Comments

vivek.puri’s picture

Many times people search for phrases and one way to improve the result of such query is to use sloppy phrase query. If you are using Drupal 7 with apache solr you can alter the apache query. Following code will handle it just change MYMODULE to whatever module you are using.

function MYMODULE_apachesolr_query_alter($query) {

  // improve search results for phrases                                                                                             
  // where words appear closer to each other                                                                                        
  $param = $query->getParam('pf');
  if ( empty($param) ) {
      $query->addParam('pf', 'label');
      $query->addParam('pf', 'content');
      $query->addParam('ps', 50);
  }
}

Both label and content field will be used for phrase sloppy query.

You can read more about it on Solr Relevancy Faq or for a use case on the blog post