Constant boost multivalued fields in Solr

511 views Asked by At

I have a multivalued field storing strings which I need to perform queries on. It stores IDs as strings. So, this is the field:

   <field name="id" type="string" indexed="true" stored="true" multiValued="true" termVectors="true"/>

And the the query would look like

q: (id:'23' OR id:'24')^2

This filters out documents where the field is 23 or 24. The documents which have both of those IDs are at the top, the documents which have either of those IDs are below.

What I want is a constant boost of 2. If at least one ID matches, give it a boost of 2. How do I achieve something like that?

1

There are 1 answers

0
Mysterion On BEST ANSWER

One possible option is to convert this query to the ConstantScoreQuery, by replacing ^ with ^=

q: (id:'23' OR id:'24')^=2

In this case, if your document will have both terms 23 and 24 or just having either of them you will still have the same score of 2.0