Drupal 6: Getting Apache Solr to show all results and facets without searching
I’ve encountered this issue a few times recently when working with Apache Solr (in Drupal 6): clients want to to show all search results and allow the users to browse facets, instead of requiring a search phrase or filter to begin the search. The current version of the Apache Solr module appears to require at least one of these items.
- Querying Solr directly allows you to return all search results using the query/select URL. Example: http://example.com:8080/solr/select
- Entering a keyword works. Example: http://example.com/search/apachesolr_search/blah
- Entering a keyword AND taxonomy filter works. Example: http://example.com/search/apachesolr_search/blah?filters=tid%3A22
- Entering a taxonomy filter WITHOUT a keyword works. Example: http://example.com/search/apachesolr_search/?filters=tid%3A22
- No keyword AND no filter returns nothing (dang). Example: http://example.com/search/apachesolr_search
A quick look at apachesolr_search.module, in the function: apachesolr_search_view() shows this is not going to happen:
So what if there was a way to modify the $_GET values prior to the apache solr search page callback? hook_boot maybe? NOTE: hook_boot functions are only processed if the bootstrap column in the system table for your module is set to 1! Example SQL to update..
I then created this hook_boot function in my module. It is run prior to the the apache solr search page callback, and allows me to tamper with $_GET variables. In this case, I just add a fake filter to allow the search to pass the above conditional statements.
Now going to the solr search page defaults to show all results and facets:
It appears to work, but anyone know of a better way to accomplish this?! :)