6.1.1-zend-http-adapter.php 1.3 KB

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