You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by ngaurav2005 <ng...@gmail.com> on 2011/05/21 23:07:57 UTC

Sorting function with condition

Hi all,

I had to do sorting on search results based on some condition inside sort
function. Let me put forward with example:
Query: q=timestamp:123454321&sort=somefunction asc 

But this "Somefunction" has to have if condition inside it, like
If age =10, sum(value,x) 
Else sum(value,y)

Actually somefunction is sum of (value,x) or (value,y) based on age
condition. 

How to handle with this situation in solr search. I was trying to do with
solr math functions using sort parameter in query, but it donot supports if
condition. Is there any way to do this programatically(java)/solr plugin. I
am new to solr, so please help me complete set of details. 

Thanks in anticipation.

Gaurav


--
View this message in context: http://lucene.472066.n3.nabble.com/Sorting-function-with-condition-tp2970036p2970036.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Sorting function with condition

Posted by Jan Høydahl <ja...@cominvent.com>.
Hi,

Could be possible if we implement https://issues.apache.org/jira/browse/SOLR-2136

Until then, perhaps you can try to pre-calculate a sort field during indexing, based on input data?

You can also emulate an if() function using map() function http://wiki.apache.org/solr/FunctionQuery#map
sort=sum(value,map(age,10,10,$x,$y))+asc&x=2&y=3

--
Jan Høydahl, search solution architect
Cominvent AS - www.cominvent.com

On 21. mai 2011, at 23.07, ngaurav2005 wrote:

> Hi all,
> 
> I had to do sorting on search results based on some condition inside sort
> function. Let me put forward with example:
> Query: q=timestamp:123454321&sort=somefunction asc 
> 
> But this "Somefunction" has to have if condition inside it, like
> If age =10, sum(value,x) 
> Else sum(value,y)
> 
> Actually somefunction is sum of (value,x) or (value,y) based on age
> condition. 
> 
> How to handle with this situation in solr search. I was trying to do with
> solr math functions using sort parameter in query, but it donot supports if
> condition. Is there any way to do this programatically(java)/solr plugin. I
> am new to solr, so please help me complete set of details. 
> 
> Thanks in anticipation.
> 
> Gaurav
> 
> 
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Sorting-function-with-condition-tp2970036p2970036.html
> Sent from the Solr - User mailing list archive at Nabble.com.