lucene-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcb <thestreet...@gmail.com>
Subject Using a function for sort
Date Sat, 27 Aug 2011 18:05:08 GMT
Hi there, 
Relatively new solr user with an unfortunately not-so-newb question. I'm
trying to create a function that I can use as the sort field that compares
what fields match. So basically, say I have a database of cars and I want to
simply select all of them (the sort shouldn't remove any results), I'm just
going to write:

*/cars/?select=*:**

Then I want to return a number between 0 and 1 based on 3 fields: Color,
Type, and Transmission. So the function basically says: 

*If Color=Red, add .25 to the result
If Type=SUV, add .5 to the result
if Transmission=Auto, add .25 to the result*

A match on all fields returns *1*, a match on the 1 and 3 only returns *.5*,
etc.

I think the following approach I have might be a step in the right
direction:

*/cars/?select=*:*
&sort={!function}
add(product(tf(Color,Red),.25),product(tf(Type,SUV),.5),product(tf(Transmission,.Auto),.25))*

but not sure if tf is really the best too to use for this, thanks for the
help!

--
View this message in context: http://lucene.472066.n3.nabble.com/Using-a-function-for-sort-tp3289411p3289411.html
Sent from the Lucene - General mailing list archive at Nabble.com.

Mime
View raw message