I installed Search API, created Search Index, and it's using the Solr server.
When I execute the query and debug the code afterward, I get 3 result counts.
And for result items, I get an empty array. When I try the same query in Solr Admin, I get 3 result counts as well as result items.
public function searchResults() {
$parse_mode = \Drupal::service('plugin.manager.search_api.parse_mode')
->createInstance('terms');
$parse_mode->setConjunction('OR');
/** @var Query $query */
$query = Index::load('default_solr_index')->query();
$query->addCondition('status', 'true');
$query->setOption('bq', 'base_site_url:"' . 'http://test.local' . '"^4');
$query->keys('editor');
$query->setLanguages(['en']);
$query->setFulltextFields(['field_summary']);
$query->range(50, 10);
$query->setParseMode($parse_mode);
$query->addTag('custom_search');
$data = $query->execute();
$results = $data->getResultItems(); // I get empty array
$resultCount = $data->getResultCount(); // I get int 3
}
I tried to change this line of code:
$query->range(50, 10);
to:
$query->range(0, 10);
But I get this error:
Argument 4 passed to Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::getHighlighting() must be of the type array, null given, called in /var/www/html/my-project/modules/contrib/search_api_solr/src/Plugin/search_api/backend/SearchApiSolrBackend.php on line 2748
What am I doing wrong?
This is my code and I use the Drupal 8 version.