Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr: How to specify field relevancy/weight

Tags:

search

solr

I'm currently indexing data using Solr that consists of about 10 fields. When I perform a search I would like certain fields to be weighted higher. Could anyone help point me in the right direction?

For example, searching across all fields for a term such as "superman" should return hits in the "Title" field before the "Description" field.

I've found documentation on how to make one field score higher from the query, but I would prefer to set this in a configuration file or similar. The following would require all searches to specify the weight. Is it possible to specify this in the solr config file?

q=title:superman^2 description:superman
like image 333
Nathan Hall Avatar asked Sep 16 '25 04:09

Nathan Hall


2 Answers

Try using qf with ExtendedDisMax your query then would look like that:

q=superman

While your config will look like:

<str name="qf">title^2 description</str>

You can get some working examples here

like image 128
Fuxi Avatar answered Sep 19 '25 16:09

Fuxi


The qf parameter introduces a list of fields, each of which is assigned a boost factor to increase or decrease that particular field's importance in the query. For example, the query below:

qf="fieldOne^2.3 fieldTwo fieldThree^0.4"

Assigns fieldOne a boost of 2.3, leaves fieldTwo with the default boost (because no boost factor is specified), and fieldThree a boost of 0.4. These boost factors make matches in fieldOne much more significant than matches in fieldTwo, which in turn are much more significant than matches in fieldThree."

Source: Apache Lucene

In your case: qf="title^100 description" may do the trick - if you're using Solr in a library I'd love to chat.

like image 25
Eric Nord Avatar answered Sep 19 '25 14:09

Eric Nord