Score:0

Search API - Can't get result items

tm flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.