6.1.3-curl-adapter.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 curl
  9. // note that this is only shown for documentation purposes, normally you don't need
  10. // to do this as curl is the default adapter
  11. $client->setAdapter('Solarium\Core\Client\Adapter\Curl');
  12. // get a select query instance
  13. $query = $client->createSelect();
  14. // this executes the query and returns the result
  15. $resultset = $client->select($query);
  16. // display the total number of documents found by solr
  17. echo 'NumFound: '.$resultset->getNumFound();
  18. // show documents using the resultset iterator
  19. foreach ($resultset as $document) {
  20. echo '<hr/><table>';
  21. // the documents are also iterable, to get all fields
  22. foreach ($document as $field => $value) {
  23. // this converts multivalue fields to a comma-separated string
  24. if (is_array($value)) {
  25. $value = implode(', ', $value);
  26. }
  27. echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
  28. }
  29. echo '</table>';
  30. }
  31. htmlFooter();