[7576] | 1 | <?php |
---|
| 2 | |
---|
| 3 | require('init.php'); |
---|
| 4 | htmlHeader(); |
---|
| 5 | |
---|
| 6 | // This example shows how to manually execute the query flow. |
---|
| 7 | // By doing this manually you can customize data in between any step (although a plugin might be better for this) |
---|
| 8 | // And you can use only a part of the flow. You could for instance use the query object and request builder, |
---|
| 9 | // but execute the request in your own code. |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | // create a client instance |
---|
| 13 | $client = new Solarium_Client($config); |
---|
| 14 | |
---|
| 15 | // create a select query instance |
---|
| 16 | $query = $client->createSelect(); |
---|
| 17 | |
---|
| 18 | // manually create a request for the query |
---|
| 19 | $request = $client->createRequest($query); |
---|
| 20 | |
---|
| 21 | // you can now use the request object for getting an uri (ie. to use in you own code) |
---|
| 22 | // or you could modify the request object |
---|
| 23 | echo 'Request URI: ' . $request->getUri() . '<br/>'; |
---|
| 24 | |
---|
| 25 | // you can still execute the request using the client and get a 'raw' response object |
---|
| 26 | $response = $client->executeRequest($request); |
---|
| 27 | |
---|
| 28 | // and finally you can convert the response into a result |
---|
| 29 | $result = $client->createResult($query, $response); |
---|
| 30 | |
---|
| 31 | // display the total number of documents found by solr |
---|
| 32 | echo 'NumFound: '.$result->getNumFound(); |
---|
| 33 | |
---|
| 34 | // show documents using the resultset iterator |
---|
| 35 | foreach ($result as $document) { |
---|
| 36 | |
---|
| 37 | echo '<hr/><table>'; |
---|
| 38 | |
---|
| 39 | // the documents are also iterable, to get all fields |
---|
| 40 | foreach($document AS $field => $value) |
---|
| 41 | { |
---|
| 42 | // this converts multivalue fields to a comma-separated string |
---|
| 43 | if(is_array($value)) $value = implode(', ', $value); |
---|
| 44 | |
---|
| 45 | echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | echo '</table>'; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | htmlFooter(); |
---|