Community Documentation

Tips and suggestions for module customization

Comments

Improving search results for phrases

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

About this page

Drupal version
Drupal 6.x

Site Building Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here