I was hoping to alter the return of a search_api based View (coming from a solr index), so I implemented hook_views_pre_render. But the $view->results array only contains the entity ID and search_api information (relevance score, fulltext snippet). All view data is supposed to be loaded by this phase.

Is there a reason that we load data during views_render? This makes it impossible to modify the output of a view without actually digging into the rendered output in views_post_render... or loading all the search result entities during pre_render, and effectively duplicating what the query/handlers are supposed to do.

Comments

nikolay borisov’s picture

Hi !
You could alter it with hook_search_api_solr_search_results_alter. You will have to foreach the elements of the results item in the results
var.

Here it is appended "hi" to every title in the result.

function hook_search_api_solr_search_results_alter(&$results, $query, $response) {

  foreach ($results['results'] as &$result) {
    $result['fields']['title'][0] = $result['fields']['title'][0] . ' hi'; 
  }
}
nikolay borisov’s picture

Issue summary: View changes

added an alternate approach on the end

legolasbo’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

This issue has not seen activity in over 2,5 years. I am therefore closing this issue to clean up the issue queue. Feel free to re-open and update this issue if you feel this issue is still relevant and of importance.