Hello and thank you for an excellent module!
Question... unless I am missing something somewhere, Search API does not provide any logging for admin/reports/search. I searched issues and couldn't find anything for 'reports' or 'phrases', apologies if this is a duplicate.
I have some custom modules that use hook_search_api_solr_query_alter to log search keys...
watchdog('search', '(which_module) '.$call_args['query']);
...but I also have a search results View using a node-entity (Solr) index, this has no custom module thus nowhere to sling a hook and nothing is springing to mind as to how to capture the keys used when searching it.
Question is not just about Solr queries either btw.
Any ideas?
Thanks in advance!
Comments
Comment #1
drunken monkeyThere's
hook_search_api_query_alter($query). With$query->getOriginalKeys()you should easily be able to retrieve and remember the keys entered by the user.$query->getKeys(), on the other hand, will (most likely) contain an array of search terms (in the numeric indexes), which you can use to identify the individual search terms encountered.Using this, you can easily come up with a module that generically tracks all used search keys and provides statistics for them. Different searches (a search page, several search views, searches provided in other ways …) can be distinguished by looking at
$query->getOption('search id'). You can also use this to let users select searches to exclude from the statistics (as an advanced feature) – e.g., periodic searches by the "Saved searches" module would otherwise contort the statistics.Comment #2
zenlan commentedThanks but I was hoping to not have to write another module just to log the search keys for this one search index.
Comment #3
drunken monkeyWell, it could log the search keys of all your indexes, so really the other, specialized solutions were unnecessary. But I just don't think this belongs into the framework module itself, so unless I'm convinced, you won't get around another module. If you are in no rush, there is at least the chance that someone else will sooner or later write it for you, if that's good enough.
Comment #4
zenlan commentedThe other specialised solutions weren't just to log search phrases though, they were complete entity modules with search_api and views integration. The search key logging was just one line of code in each query_alter.
But I will build a module for the Drupal Solr index view, I daresay I may find other uses for it besides logging.
Thanks.
Comment #5
jrbI've suggested a patch for the Search API pages module to make it log searches. So, if you're using that module, too, you can try that out:
#3023954-2: Searches not logged so "Top search phrases" report is empty