Function Query)

Source: Internet
Author: User
Tags pear solr solr query

Function query can use the numeric field value or the function of a specific value related to the field to rate the document.

1. Method of Using function Query

There are three main methods to use function query. All these three s methods use the solr http interface.

1) Use functionqparserplugin. IE: q = {! Func} log (FOO)

2) use the "_ Val _" embedded method

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.

IE: entrynm: Make & _ Val _: ord (entrynm)

3) use the BF parameter in dismax

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) ^

2. Function query syntax)

Currently, function query does not support the Form A + B. We need to write it as a method form, which is sum (A, B ).

3. Notes for using function Query

1) fields used for function query must be indexed;

2) fields cannot be multi-value)

4. Available functions (available function)

1) constant: a constant with a decimal point is supported. For example: 1.5; solrquerysyntax: _ Val _: 1.5

2) fieldvalue: this function will return the value of numeric field, which must be indexd and not multivalued. The format is simple, that is, the name of the field. If this field does not contain such a value, 0 is returned.

3) Ord: for a field, 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 field 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.

The format is 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: div (x, y) represents the value of X divided by Y. Format: div (1, x), Div (sum (x, 100), max (Y, 1 ))

8) Pow: pow indicates the power. Pow (x, y) = x ^ y. For example, POW (x, 0.5) indicates the open POW (x, log (y ))

9) ABS: ABS (x) returns the absolute value of the expression. Format: ABS (-5), ABS (X)

10) log: log (x) returns 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 x> = min and x <= max, map (x, Min, Max, target) = target. if X is not in the range [min, Max], map (x, Min, Max, target) = x.

Format: Map (x, 0, 0, 1)

13) scale: the scale (x, mintarget, maxtarget) function will limit the value of X to the range of [mintarget, maxtarget.

14) query: 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 has the same effect as the previous example. 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: inear (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)

Function Query)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.