Increase Boolean fields in Solr

Is it possible to increase the Boolean fields in Solr to get a higher score?

We have an index that looks something like this:

  • document_id
  • title
  • Description
  • keywords
  • is_reviewed

When searching, documents that were viewed (i.e. is_reviewed = true) should be weighed more heavily than those that do not, but do not completely exclude them.

Using is_review:true^100 does not seem to work and eliminates unviewed items instead of just giving them lower weight. If this can be achieved in another way? Thanks!

+8
sorting solr
source share
2 answers

Some query analyzers have a function designed for this use. For example, the smax request analyzer has a boost query bq , which allows you to increase the documents matching the request by adding its sentences to the original request. There is also a boost bf function that allows you to multiply points by the result of the function. For example, using is_review as this bf parameter,

  • the score of each document whose is_review undefined field will be multiplied by 0.
  • score for each document, so is_review = false will be multiplied by one.
  • the score of each document that is_review = true will be multiplied by two.

is_review:true^100 unexplored items should not be excluded unless you use AND as the default query operator. In this case, you can try replacing is_review:true^100 with (is_review:true^100 OR is_review:false^0) .

If you are interested in the smax query parser verbosity function, but you want to use the default query parser, you can use the query parser , which allows you to multiply the number of queries with any function.

+9
source share

Drupal

Here is a solution for those using Drupal CMS.

First find your field name in Schema Browser in /solr/admin/schema.jsp

Then, depending on the module used, try the following examples:

Apacheolr Module

Code example:

 /** * Implements hook_apachesolr_query_alter(). */ function hook_apachesolr_query_alter(DrupalSolrQueryInterface $query) { $query->addParam('bq', array('is_review' => '(is_review:true^100 OR is_review:false^0)' )); } 

Search for the Solr API module

Code example:

 /** * Implements hook_search_api_solr_query_alter(). */ function hook_search_api_solr_query_alter(&$call_args, SearchApiQueryInterface $query) { $call_args['params']['bq'][] = '(is_review:true^100 OR is_review:false^0)'; } 
+4
source share

All Articles