1

I have Search API DB backend where I will be retrieving thousands of results and I need some fields to get out of there as well, beside search item id, since doing additional query to MySQL with IN condition consisting of thousands of entries is nonsense.

Can't find any methods to do this in the code so far though.

I think the query option search_api_retrieved_properties is the key, but I was not able to make it work yet.


I have added the fields via hook_search_api_db_query_alter on tagged query but they are not present. Calling getField() on the result item always queries the source entity(= entity_load operation).

  • Maybe want to consider a non-SQL store for search, like Solr? – Kevin Aug 26 '17 at 20:14
  • Sure, I was planning on switching to ES soon but this feature should be standard, not dependent on backend. Since the fields are already in the index, it has access to them, why won't it make accessible is beyond me. – user21641 Aug 26 '17 at 20:20
0

Unfortunately, it looks like this is impossible.

Looking at \Drupal\search_api_db\Plugin\search_api\backend\Database::search:

  $result = $db_query->execute();

  foreach ($result as $row) {
    $item = $this->getFieldsHelper()->createItem($index, $row->item_id);
    $item->setScore($row->score / self::SCORE_MULTIPLIER);
    $results->addResultItem($item);
  }

The $item will receive only the item_id from the fetched row, so all added fields are lost :(

Your Answer

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