You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by Apache Wiki <wi...@apache.org> on 2007/05/15 07:03:26 UTC
[Solr Wiki] Update of "FunctionQuery" by MekinMaheshwari
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Solr Wiki" for change notification.
The following page has been changed by MekinMaheshwari:
http://wiki.apache.org/solr/FunctionQuery
New page:
The Javadoc - http://lucene.apache.org/solr/api/org/apache/solr/search/function/FunctionQuery.html
does not have much information.
A little more information is available at the javadoc for the parseFunction method under QueryParsing :
http://lucene.apache.org/solr/api/org/apache/solr/search/QueryParsing.html#parseFunction(java.lang.String,%20org.apache.solr.schema.IndexSchema)
The javadocs for different possible functions (described below ) can be seen as the subclasses of - http://lucene.apache.org/solr/api/org/apache/solr/search/function/ValueSource.html
When specifying these in your solrconfig. Take care to :
1. verify there is some whitespace between the functions that you are specifying
2. eliminate the space inside the recip functions - including spaces around commas - this leads to a NumberFormatException
3. verify that there is no space between a function and it's boost
eg. {{{'''recip(popularityRank,1,1000,1000)^2.5 recip(rord(creationDate),1,1000,1000)^1.3'''}}}
* '''myfield''' - Field value itself can be used as a function
Numeric fields default to correct type
(ie: IntFieldSource or FloatFieldSource)
Others use implicit ord(...) to generate numeric field value
A field like popularity might be a good example use case for this.
* '''ord(myfield)''' - OrdFieldSource. Obtains the ordinal of the field value from the default Lucene FieldCache using getStringIndex(). The native lucene index order is used to assign an ordinal value for each field value. Field values (terms) are lexicographically ordered by unicode value, and numbered starting at 1. [[BR]]Example: If there were only three field values: "apple","banana","pear" then ord("apple")=1, ord("banana")=2, ord("pear")=3 WARNING: ord() depends on the position in an index and can thus change when other documents are inserted or deleted, or if a MultiSearcher is used.
* '''rord(myfield)''' - ReverseOrdFieldSource, The reverse ordering of whar ord provides - javadoc - http://lucene.apache.org/solr/api/org/apache/solr/search/function/ReverseOrdFieldSource.html
* '''linear(myfield,1,2)''' - LinearFloatFunction on numeric field value. [[BR]]
I THINK ( this is not from documentation, please correct this) that this function implements the value - [[BR]]
f(x) = m*x + c [[BR]]
In the above case, It will implement myField*1 + 2
* '''max(linear(myfield,1,2),100)''' - MaxFloatFunction of LinearFloatFunction on numeric field value or constant. Returns the max of a ValueSource and a float (which is useful for "bottoming out" another function at 0.0, or some positive number).
* '''recip(myfield,m,a,b)''' ReciprocalFloatFunction on numeric field value. ReciprocalFloatFunction implements a reciprocal function [[BR]] f(x) = a/(mx+b), based on the float value of a field as exported by ValueSource.[[BR]] When a and b are equal, and x>=0, this function has a maximum value of 1 that drops as x increases. Increasing the value of a and b together results in a movement of the entire function to a flatter part of the curve. These properties make this an ideal function for boosting more recent documents.
(Insert graphs here to show the variation of f(x) as a & b change)
* Combinations - You can combine the above functions as suitable [[BR]]
eg. '''recip(rord(myfield),1,2,3)''' - ReciprocalFloatFunction on ReverseOrdFieldSource
'''recip(linear(rord(myfield),1,2),3,4,5)''' - ReciprocalFloatFunction on LinearFloatFunction on ReverseOrdFieldSource