1 | <?php |
---|
2 | |
---|
3 | require_once 'Zend/Loader/Autoloader.php'; |
---|
4 | $loader = Zend_Loader_Autoloader::getInstance(); |
---|
5 | |
---|
6 | require('init.php'); |
---|
7 | htmlHeader(); |
---|
8 | |
---|
9 | // create a client instance |
---|
10 | $client = new Solarium_Client($config); |
---|
11 | |
---|
12 | // set the adapter to zendhttp and get a zendhttp client instance reference |
---|
13 | $client->setAdapter('Solarium_Client_Adapter_ZendHttp'); |
---|
14 | $zendHttp = $client->getAdapter()->getZendHttp(); |
---|
15 | |
---|
16 | // you can use any of the zend_http features, like http-authentication |
---|
17 | $zendHttp->setAuth('user', 'password!', Zend_Http_Client::AUTH_BASIC); |
---|
18 | |
---|
19 | // get a select query instance |
---|
20 | $query = $client->createSelect(); |
---|
21 | |
---|
22 | // this executes the query and returns the result |
---|
23 | $resultset = $client->select($query); |
---|
24 | |
---|
25 | // display the total number of documents found by solr |
---|
26 | echo 'NumFound: '.$resultset->getNumFound(); |
---|
27 | |
---|
28 | // show documents using the resultset iterator |
---|
29 | foreach ($resultset as $document) { |
---|
30 | |
---|
31 | echo '<hr/><table>'; |
---|
32 | |
---|
33 | // the documents are also iterable, to get all fields |
---|
34 | foreach($document AS $field => $value) |
---|
35 | { |
---|
36 | // this converts multivalue fields to a comma-separated string |
---|
37 | if(is_array($value)) $value = implode(', ', $value); |
---|
38 | |
---|
39 | echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; |
---|
40 | } |
---|
41 | |
---|
42 | echo '</table>'; |
---|
43 | } |
---|
44 | |
---|
45 | htmlFooter(); |
---|