How do you query solr server from php in Drupal 8?

I have installed search_api, search_api_solr and search_api_attachments. Also have Solr v.8.4.0 installed.

I installed php SolrClient for Centos 7 following this guidance: https://stackoverflow.com/questions/22959330/fatal-error-class-solrclient-not-found , but I still get "Class 'SolrClient' not found" every time I run

new SolrClient($options);

I have located documentation on querying Solr from php in Drupal 7 (apachesolr_get_solr()) but nothing in Drupal 8.

  • You can either do it through the SearchAPI services or use Solarium client directly. I recommend the first way if you are not a programmer or very familiar with Solr querying. gist.github.com/kevinquillen/cad07541347385744b161a26690ab75d Is one example. – Kevin Jan 25 at 15:02
  • Thanks. I managed to get SolrClient working and that method appears to work well. – SomebodySysop Jan 25 at 22:18

I managed to fix the problems with SolrClient install: https://stackoverflow.com/questions/41052999/php-warning-unable-to-load-dynamic-library-usr-lib64-php-modules-solr-so-und%C2%A0

This is how I can now query the solr server from php (right out of php SolrClient manual):

$options = array
    'hostname' => 'localhost',
    'port'     => '8983',
    'path'     => 'solr/sbn01'

$client = new SolrClient($options);

$query = new SolrQuery();





$query_response = $client->query($query);

$response = $query_response->getResponse();

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.