0

I'm using search_api_solr and search_api_location. I have a view with exposed filters to perform geolocation searches.

I'm trying to reorder search result from a solr query based a referenced node's field. My question is witch hook to use, where i can access node fields and reorder the results.

I already tried:

  • hook_views_pre_render()
  • hook_views_post_execute()
  • hook_views_post_render()
  • hook_views_pre_view()

but reordering is effectless or i don't have access to node fields. I'm doing something like this:

$results = &$view->result; $to_search_top = array(); foreach ( $results as $i => $capacity){ if ((int) $capacity->{_entity_properties}['field_free_capacity_company_ref:field_last_review'] > 1) { unset($results[$i]); $to_search_top[] = $capacity; } } foreach ($to_search_top as $capa) { array_unshift($results, $capa); } 

Thank

1 Answer 1

0

Finaly i was only able to solve this with hook_preprocess_views_view_table().

$to_search_top = array(); foreach ($vars['rows'] as $index => $row) { if ((int) $row['field_company_review_number_1'] > 0) { $to_search_top[] = $row; unset($vars['rows'][$index]); } } // Sort reviewed by distance. usort($to_search_top, function ($item1, $item2) { if ($item1['field_free_capacity_coordinates_latlon'] == $item2['field_free_capacity_coordinates_latlon']) { return 0; } return $item1['field_free_capacity_coordinates_latlon'] > $item2['field_free_capacity_coordinates_latlon'] ? -1 : 1; }); // Move to results top. foreach ($to_search_top as $row) { array_unshift($vars['rows'], $row); } 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.