I want to alter the results of a Drupal 8.x search_api_solr search using hook_search_api_solr_search_results():
function sbn_search_api_solr_search_results_alter(Drupalsearch_apiQueryResultSetInterface $result_set, Drupalsearch_apiQueryQueryInterface $query, SolariumQueryTypeSelectResultResult $result) { $resultset_data = $result->getData(); // Get docs in response results $results = $resultset_data['response']['docs']; foreach ($results as $id => &$item) { // get the doc and array id } }
I know that the docs I seek are in the search results:
dsm($result);
returns
stdClass Object ( [__CLASS__] => SolariumQueryTypeSelectResultResult [numfound:protected] => 5 [maxscore:protected] => 1.8644972 [nextcursormark:protected] => [documents:protected] => Array ( [0] => stdClass Object ( [__CLASS__] => SolariumQueryTypeSelectResultDocument [fields:protected] => Array ( [ss_search_api_id] => entity:node/47:en [ss_search_api_language] => en [score] => 1.8644972 ) ... [data:protected] => Array ( [response] => Array ( [numFound] => 5 [start] => 0 [maxScore] => 1.8644972 [docs] => Array ( [0] => Array ( [ss_search_api_id] => entity:node/47:en [ss_search_api_language] => en [score] => 1.8644972 ) [1] => Array ( [ss_search_api_id] => entity:file/85:en [ss_search_api_language] => en [score] => 1.784599 )
Let’s say that the doc in question that I want to remove from $result
object is:
$resultset_data['response']['docs'][$id]
How do I alter the $result
object to remove this doc from results? Every attempt I have made to access the $result
object as an array has resulted in these types of errors:
Error: Cannot use object of type SolariumQueryTypeSelectResultResult as array
Error: Cannot access protected property SolariumQueryTypeSelectResultResult::$response
Any suggestions or documentation on this would be highly appreciated.