Score:0

Unable to filter fields in Search API Solr index Query

cc flag

I'm trying to run a Search API search programmatically on my solr index. The issue is that the query is quite expensive so I'm trying to reduce the cost by filtering for specific fields. In Solr I would do this through the Field List Parameter as e.g. "fl=name,surname" but I'm unsure how to do this through a Search API Search. I've tried setting the parse mode to direct as well but I just get an error that says "An error occurred while trying to search with Solr: Parse mode direct requires fields." I also tried using setFulltextFields but it doesn't seem to work either. I've included my code below. Any help with this one would be greatly appreciated.

$index = \Drupal\search_api\Entity\Index::load('my_index');
$query = $index->query();

$parse_mode = \Drupal::service('plugin.manager.search_api.parse_mode')
->createInstance('direct');
$parse_mode->setConjunction('AND');
$query->setParseMode($parse_mode);

$query->keys('name AND surname');

$query->range(0, 2000);
$query->addTag('custom_search');
$results = $query->execute();
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.