Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#2 | 2653370-2.diff | 1.75 KB | John Cook |
Comments
Comment #2
John Cook CreditAttribution: John Cook at Curve Agency commentedBy using
hook_search_api_results_alter()
, I can get the number of results from search api. The table already hasnumfound
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.Comment #3
Proteo CreditAttribution: Proteo commentedThanks 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.Comment #4
Bohus UlrychHi 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();