Function
Through function query, we can use the value of the numeric domain or the function of a specific value related to the domain to score the document.
How to Use
Here there are two main methods to use function query, both of which are through the solr http interface:
1. embedded in the normal SOLR query expression. That is, write the function query in the Q Parameter. At this time, we use _ Val _ to distinguish the function from other queries. For details about how to use it, please pay attention to the following examples.
2. Use a parameter explicitly used for function query, such as the BF (boost function) parameter in dismax. Note: BF can be queried by multiple functions. They are separated by spaces and can carry weights. Therefore, when we use the BF parameter, we must ensure that there is no space in a single function. Otherwise, the program may think it is two functions.
Example: q = dismax & BF = ord (popularity) ^ 0.5 recip (rord (price), 1000, 0.3) ^
Function Format
Currently, function query does not support the Form A + B. We need to write it as a method form, which is sum (A, B)
Function details
1. Constant: supports decimal point constants,
For example, 1.5, the query expression is: _ Val _: 1.5
2. fieldvalue. This function will return the value of numeric field, which must be indexd rather than multivalued. The format is simple, that is, the name of the domain. If this field does not have such a value, 0 is returned.
3. ord: For a domain, all its values are arranged alphabetically. This function returns the ranking of the specific value you want to query in this order. This field must be non-multivalued. If no value exists, 0 is returned.
For example, if a specific domain can have only three values, "apple", "banana", and "Pear", then ord ("apple") = 1, ord ("banana ") = 2, ord ("pear") = 3.
Note that the ord () function depends on the position of the value in the index. Therefore, when a document is deleted or added, the value of ord () changes. When you use multisearcher, this value is also variable.
4. rord. This function returns the inverted rank corresponding to Ord.
Format: rord (myindexedfield ).
5. Sum: the meaning of this function is obvious. It indicates "and ".
Format: sum (x, 1)
Sum (x, y)
Sum (SQRT (x), log (Y), Z, 0.5)
6. Product, product (X, Y,...) returns the product of multiple functions.
Format: product (x, 2)
Product (x, y)
7. Div and Div (x, y) indicate that X is divided by Y.
Format: div (1, x)
Div (sum (x, 100), max (Y, 1 ))
8. Pow indicates the power. Pow (x, y) = x ^ y.
Format: Pow (x, 0.5) indicates the start
Pow (x, log (y ))
9. ABS and ABS (x) return the absolute value of the expression.
Format: ABS (-5)
ABS (X)
10. log and log (x) will return the logarithm of base 10 and 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, map (x, Min, Max, target) = target. If X is not in the range of [min, Max, map (x, Min, Max, target) = x.
Format: Map (x, 0, 0, 1)
13. The scale, scale (x, mintarget, maxtarget) function will limit the value of X to the range of [mintarget, maxtarget.
14. Query (subquery, default) returns the score of the given subquery. If the subquery does not match the document, the default value is returned. Any query type is supported. You can specify a query string by reference or directly.
Example: q = product (popularity, query ({! Dismax v = 'solr rocks'}) returns the product of popularity and the score obtained through the dismax query.
Q = product (popularity, query ($ qq) & QQ = {! Dismax} SOLR rocks. However, the reference method is used here.
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) indicates M * x + C, where M and C are constants, and X is a variable or 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, and B are constants, X is a variable or function. When a = B and x> = 0, the maximum value of this function is 1, and the size of the value decreases with the increase of X.
Example: recip (rord (creationdate), 1000)
17. Max, Max (x, c) returns the maximum value between a function and a constant.
Example: max (myfield, 0)
SOLR function Query)