Need to check for range in Solr if function

1.4k views Asked by At

We are just building a Solr index for a knowledge base and I have some problems implementing boosting. First of all: We want to have multiplicative boosting and no additive.

And: The more hits a document has, the more it should be boosted, but only to a certain degree. First of all we thounght about a function like boost=sum(div(hits,10000),1), but that would push certain documents too much.

So we thought about something like this (beside some others, but those all work and only these give me an error):

 &boost=if(hits,[0+TO+100],1)
 &boost=if(hits,[101+TO+250],1.25)
 &boost=if(hits,[250+TO+100000],1.5)

Error is:

org.apache.solr.search.SyntaxError: Expected identifier at pos 8 str='if(hits,[101 TO 250],1.25)'

So the obvious reason is the range in the if function, if I remove that with a single value, all works, but that does not really help me.

So my question is: Is it not possible to combine an "if()" function with a range of values to match? I know I could try a million different ways to solve this, but actually we would be glad to have it in some way like this, as the boost param values could be configurable for the different ranges and it's easy to get that syntax working with our framework to access Solr.

However, if there is no chance to get this running, I am of course open for alternative solutions.

Thanks a lot,

Markus

2

There are 2 answers

1
mindfxxxedCoder On BEST ANSWER

So to clean this up here: It is not possible to use a range within an if function.

But we found a way with the map function which pretty much does what we wanted to achieve with that if-range attempt:

 &boost=map(hits, 0, 100, 1, map(hits,101, 250, 1.25, map(hits,250, 10000, 1.5)))
0
Mohamed Samir On

You can use bq (Boost Query) as following:

&bq=hits:[0 TO 100]^1.0