Search code examples
javasolrsolr-query-syntaxfunction-query

Solr : How to add conditions in Boost function query


I'm trying to see if it's possible to use conditions within a Solr boost function query. Right now,I'm using the following function to boost on Likes data.

bf=recip(ms(NOW/DAY,PublishDate),3.16e-11,1,1)^2.0 sum(Likes,2) 

What I would like to do is to apply the boost on "Likes" based on some conditions. For e.g.

if Source="A" or "B" or "C", then sum(Likes,4)

else-if Source="D" then sum(Likes,3)

else sum(Likes,2).

"if" function works for a single condition, but not sure how to address if-else condition.

if(termfreq(Source2,'A'),sum(Likes,3),0)

I'm trying to avoid nested queries due to performance overhead.

Any pointer will be appreciated.

-Thanks,

Shamik


Solution

  • Ok, after some research, I found the right syntax.

    if(termfreq(Source2,'A'),sum(Likes,3),if(termfreq(Source2,'B'),sum(Likes,3),0))
    

    Hope this help others.