3
votes

I'm trying to boost the score for documents returned from a search in solr.

The boost I want to achieve is something along the lines of:

field1:(value1)^5 OR field2:(value2)^2 

If the document does have field1 matching value1, boost by 5. If document does have field2 matching value2, boost by 2.

The documents have many fields, let's call them field1, field2... and may be missing certain fields.

The documents do not need to have field1 or field2 matching value1, value2 respectively.

I have other filter queries such as:

fq: field1:[* TO *]  <- checking for presence of

fq: field3: ("something" "somethingelse")

fq: field4: 1

I am grouping my results by a certain field not being used in any of the queries.

Raw query parameters:

group=true&group.facet=true&group.field=anIndependentField

I am using the same fq's with tried different query parsers.

There are enough documents in solr with field1:value1 and/or field2:value2 as well as other values for those fields.

So far I've tried using the query parsers:

  1. Standard Query Parser

method a) q: field1:(value1)^5 OR field2:(value2)^2 // no results

method b) q: *:* OR field1:(value1)^5 OR field2:(value2)^2 // no results

method c) q: (value1)^5 OR (value2)^2 // incorrect. looks for complete match.

method d) q: (value1)^5 (value2)^2 // incorrect. looks for complete match

  1. EDisMax Query Parser

(defType=edismax)

q: *:*

bq: field1:(value1)^5 OR field2:(value2)^2 

Problem with this one is that results are not in expected order. A document that has field1:somethingElse and field2:somethingElse2 got a higher score than a document that has field1: somethingElse and field2:value2.

Can anyone see what I'm doing wrong or has a suggestion to improve the relevancy of my search queries?

1
Have you tried splitting the bq argument? &bq=field1:value1^5&bq=field2:value2^2MatsLindh

1 Answers

1
votes

You can use the bf parameter of eDismax queryParser in the following way:

bf=if(termfreq(field1,"value1"),5,if(termfreq(field2,"value2"),2,1))

Please find below the complete query.

https://<MY_SERVER_NAME>:9443/solr/<MY_COLLECTION>/select?q=*%3A*&wt=json&indent=true&defType=edismax&bf=if(termfreq(field1%2C%22value1%22)%2C3%2Cif(termfreq(field2%2C%22value2%22)%2C2%2C0))