You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@lucene.apache.org by Chris Hostetter <ho...@fucit.org> on 2011/09/02 23:30:32 UTC

Re: Using a function for sort

: Then I want to return a number between 0 and 1 based on 3 fields: Color,
: Type, and Transmission. So the function basically says: 
	...
: 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!

...that should work, but if you want the value of the 
function to be included in the response you'll either need to change your 
"q" to be the function query (and use "fq" to constrain only the docs you 
want to match, -- if you really want *:* then you can ignore this) or try 
out the new "fl" "psuedo fields" syntax to include the results of a 
function in the response for each doc returned.

If you don't want the true "tf" value (ie: 0..infinity) and you just want 
o or 1 if it contains the term, you can either omitTf on those fields when 
indexing, or use the "map" function to map all values larger then 1 to 1.


FYI: in the future, questions like this are better suited for the 
solr-user@lucene mailing list, which exists explicitly for asking 
questions about using solr, and has a much larger subscriber base.  This 
list is for general discussion about hte broader lucene project.




-Hoss