For our use case, we need to remove all queries which do not return any results. Storing the number of results in search_api_stats table, along with a view, would accomplish this.

CommentFileSizeAuthor
#2 2653370-2.diff1.75 KBJohn Cook
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

john@johncook.me.uk created an issue. See original summary.

John Cook’s picture

FileSize
1.75 KB

By using hook_search_api_results_alter(), I can get the number of results from search api. The table already has numfound field, so I used that.

I also added timing, filters and sort data storing to the function as the table was set up for them and the data was easily available from the passed in $results array.

I used drupal_json_encode() to store the filters and sort data - the array could be output to the database directly though.

Proteo’s picture

Thanks John, the patch works fine. I know that your patch is saving filter data "just in case" but you may want to know that, at least in my case, drupal_json_encode() actually strips any useful filter information, returning something like [{"tags":[]},{"tags":[]}] every single time.

Bohus Ulrych’s picture

Hi John and Proteo,
thank you both.
Because I'm interested in filters as well, I tried to find why it is not working. And it is because you have objects in the filters, that's why drupal_json_encode don't work.
For me it was sufficient to get filters information not from the search query, but from drupal_get_query_parameters():
$params = drupal_get_query_parameters();
$filters = (isset($params['f'])) ? $params['f'] : array();