Role
The function query allows us to score the document by taking advantage of the value of the numeric field or a function of a specific value associated with the domain.
How to use
There are two main ways to use function queries, both of which are via the SOLR HTTP interface:
1, embedded in the normal SOLR query expression. That is, the function query is written in the Q parameter, when we use _val_ to distinguish the function from other queries. For details on how to use it, please note the following example.
2. Use parameters that are explicitly queried for functions, such as the BF (boost function) parameter in Dismax . Note: BF This parameter is acceptable for multiple function queries, separated by spaces, which can also be weighted. So, when we use the BF parameter, we have to make sure that there are no spaces in a single function, or that the program might think it is a two function.
Example: Q=dismax&bf=ord (popularity) ^0.5 Recip (Rord (Price), 1,1000,1000) ^0.3
function format
Currently, function query does not support a+b in this form, we have to write it in a method form, which is sum (A, B)
function explanation
1, constant: Support the constant with decimal point,
For example, 1.5, the query expression is: _val_:1.5
2, Fieldvalue, this function will return the value of numeric field, this field must be indexd, non-multivalued. The format is simple, which is the name of the field. If there is no such value in this field, then 0 will be returned.
3, Ord, for a field, all of its values will be sorted in dictionary order, and this function returns the rank of the particular value you want to query in this order. This domain, which must be non-multivalued, returns 0 when no value exists.
For example: a specific domain can only go to three values, "Apple", "banana", "pear", then ord ("Apple") =1,ord ("Banana") =2,ord ("pear") =3.
It should be noted that the Ord () function relies on the position of the value in the index, so when a document is deleted or added, the value of Ord () changes. When you use Multisearcher, this value is variable.
4, Rord, this function will return the rank of the inverted sort corresponding to Ord.
Format: Rord (Myindexedfield).
5, sum, the meaning of this function is obvious, it means "and".
Format: sum (x,1)
Sum (x, y)
SUM (sqrt (x), log (y), z,0.5)
6. Product,product (x, y,...) The product of multiple functions will be returned.
Format: Product (x,2)
Product (x, y)
7, Div,div (x, y) represents the value
Format: Div (1,x)
Div (sum (x,100), Max (y,1))
8. Pow,pow represents a power value. Pow (x, y) =x^y.
Format: Pow (x,0.5) denotes radical
Pow (X,log (y))
9, Abs,abs (x) returns the absolute value of an expression
Format: ABS (-5)
ABS (x)
10, Log,log (x) will return the logarithm of radix 10,x
Format: Log (x)
Log (sum (x,100))
11, SQRT,SQRT (x) returns the square root of a number
Format: sqrt (2)
sqrt (sum (x,100))
12, Map, if Min<=x<=max, then map (x,min,max,target) =target, if X is not in the [Min,max] this interval, then map (x,min,max,target) =x.
Format: Map (x,0,0,1)
13, Scale,scale (X,mintarget,maxtarget) This function will limit the value of x to [Mintarget,maxtarget] in the range.
14, Query,query (Subquery,default) will return the score for the given subquery, and if subquery does not match the document, the default value will be returned. Any of the query types are supported. The query string can be specified either by reference or directly.
Example: q=product (popularity, query ({!dismax v= ' Solr Rocks '}) will return the product of popularity and the scores obtained by the Dismax query.
Q=product (popularity, query ($QQ) &QQ={!DISMAX}SOLR Rocks) has the same effect as the previous example. But here's the way it's quoted.
Q=product (popularity, query ($QQ, 0.1) &QQ={!DISMAX}SOLR rocks) Adds a default value based on the previous example.
15, Linear,linear (X,m,c) represents M*x+c, where m and C are constants, X is a variable or it can be a function.
For example: Linear (x,2,4) =2*x+4.
16, Recip,recip (x,m,a,b) =a/(m*x+b), where m, A, B is a constant, x is a variable or a function. When A=b, and x>=0, the maximum value of this function is 1, the size of the value decreases with the increase of X.
Example: Recip (Rord (creationdate), 1,1000,1000)
17, Max,max (X,C) will return the maximum value between a function and a constant.
For example: Max (myfield,0)
SOLR's function query (functionquery)