drupalsolrdrupal-7solr-boost

How to use Solr Handlers when sending requests from Drupal


I'm using Solr 4.10.2 and Drupal 7.X, I have the Apache Solr Module Framework operating and sending the requests to Solr From Drupal. Currently when we perform a search, Drupal builds the query and sends it to Solr. Solr just executes the query and returns the results without using it's internal handlers which can be configured through SolrConfig.xml.

I would like to know if there is a way to just send the searched terms (without building a query) from Drupal and let Solr use the internal handlers declared in SolrConfig.xml to handle the request, build the query and then return the data?

The reason for this is we have been working on trying to boost some results when we perform a search (we want exact match first & fuzzy search results after) by changing the "weight" of some fields.

We know that from Back Office we can use the "Bias" function to boost some fields but this is too limited for what we are trying to achieve.

We also know we can change the query sent from Drupal directly from code side by using hook_apachesolr_modify_query() but we prefer changing as little code as possible and using the SolrConfig.xml /handlers which we already have configured to return the results as we want.


Solution

  • Ok, we figured out how to do this:

    In order to choose the handler that is being used by Solr while sending a request from Drupal, we have to edit the "hook_apachesolr_query_alter" function and add the following code:

    $query->addParam(‘qt’, ‘MyHandlerName’);
    

    We did some extra coding to allow us to change the Handler directly from back office in order to be able to switch handlers without touching the code.