SOLR lookup Syntax (SOLR query)

Source: Internet
Author: User
Tags abs constant ord pear solr solr query sort square root
1. Parameters of the Corequeryparam query
1) Q: query string, required.
2) Q.op: Overrides the Schema.xml defaultoperator (with "and" or "or" in the case of a space), which is usually specified by default.
3) DF: The default query field, typically specified by default.
4) Qt:query type, which specifies the query Handler to use for queries, default to "standard".
5) Wt:writer type. Specifies the query output structure format, which defaults to "XML". The query output format is defined in Solrconfig.xml: XML, JSON, Python, Ruby, PHP, Phps, Custom.
6) Echohandler: Whether to display the query handler name that is used in the search results.
7) Echoparams: Whether to display query parameters. None: Not displayed; Explicit: displays only query parameters; all: all, including the query handler parameter defined in Solrconfig.xml.
8) Indent-whether the returned result is indented, is closed by default, Indent=true|on is turned on, general debugging Json,php,phps,ruby output is necessary to use this parameter.
9) Version-query syntax versions, it is recommended not to use it, by the server to specify the default value.

2. Commonqueryparameters
1) Sort: sorted, Format: Sort=<field Name>+<desc|asc>[,<field name>+<desc|asc>] ".
Example: (Instock desc, price ASC) indicates first "Instock" descending, then "price" ascending, the default is correlation descending ...
2) Start: Used for paging to define the number of result start records, default is 0.
3) Rows: For page definition Results The number of records is returned per page, and the default is 10.
4) Fq:filter query. Use the filter query to take advantage of the filter query Cache to improve retrieval performance. function: In the Q query conforms to the result is also FQ query conforms to,
For example: q=mm&fq=date_time:[20081001 to 20091031], find the keyword mm, and date_time is between 20081001 and 20091031.
5) Fl:field list. Specifies that the result field is returned. Separated by a space "" or a comma ",".
6) Debugquery: Sets whether the returned result displays debug information.
7) Explainother: When Debugquery=true is set, additional query instructions are displayed.
8) Deftype: Sets the query resolver name.
9) timeallowed: Sets the query time-out.
Omitheader: Sets whether to ignore the query result return header information, the default is "false".

two. query Syntax
1. Match All documents: *:*

2. Force, block, and optional queries:
1) Mandatory: Must be included in the query results (for example, only entry name containing the word make) Solr/lucene statement:+make, +make +up, +ma Ke +up +kiss
2) Prohibited: (for example, all documents except those with Word believe) Solr/lucene statement:+make +up-kiss 3) optiona L:solr/lucene Statement:+make +up Kiss

3. Boolean operations: And, OR and not Boolean operations (must capitalize) are similar to mandatory, optional, and prohibited.
1) make and up = +make +up:and The left and right sides of the operation are mandatory
2) Make | | up = Make OR up=make up:or the left and right sides of the operation are optional
3) +make +up not kiss = +make +up–kiss
4) Make and up OR French and kiss do not achieve the desired result, because the operations on and both sides are mandatory.

4. Sub-expression query (subquery): You can construct a subquery using the ().
For ex: (Do and up) OR (French and Kiss)

5. Limitations of blocking queries in subexpression queries:
For Ex:make (-up): Only the query results of make can be obtained; use make (-up *:*) to query made or do not include the results of up.

6. Multi-field Fields query: Query by field name plus semicolon (fieldname:query)
For Ex:entryNm:make and entryid:3cdc86e8e0fb4da8ab17caed42f6760c

7. Wildcard queries (wildCard query):
1) wildcard characters. and *: "*" means matching any character; ". "Indicates where the match appears.
For ex:ma?* (one position at the back of Ma), MA?? * (two positions in the back of the MA are matched)
2) The query character must be lowercase: +ma +be** can search for results; +ma +be** No search results
3) The query is slow, especially the wildcard in the first place: the main reason is to iterate over each term in the query field, to determine whether the match, and the second is to match the term is added to the internal query, when the number of terms reached 1024, the query will fail.
4) The default wildcard in SOLR does not appear in the first place (you can modify Queryparser, set Setallowleadingwildcard to True)
5) Set Setallowleadingwildcard to True.

8. Fuzzy query, similar query: not an exact query, by re-inserting, deleting and converting the fields of the query to get a higher score query resolution (supported by the Levenstein Distance algorithm algorithm).
1) General fuzzy query: for ex:make-believ~
2) Threshold Fuzzy query: On the fuzzy query can set the query threshold, the threshold is the value between 0~1, threshold
The higher the surface similarity becomes. For ex:make-believ~0.5, make-believ~0.8, make-believ~0.9

9. Range Query: Lucene supports range queries for numbers, dates, and even text. The end range can use the "*" wildcard character.
For ex:
1) Date range (ISO-8601 time GMT): Sa_type:2 and a_begin_date:[1990-01-01t00:00:00.000z to 1999-12-31t24:59:99.999z]
2) Number: salary:[2000 to *] 3) Text: Entrynm:[a to a]

10. Date matching: Year, MONTH, day, date (synonymous with days) HOUR, MINUTE, SECOND, millisecond, and MILLI (synonymous with Millis Econd) can be marked as a date.
For ex:
1) r_event_date:[* to now-2year]:2 years ago now this time
2) r_event_date:[* to Now/day-2year]:2 year ago this time

three. function Query
A function query can use the value of a numeric field or a function of a specific value associated with a domain to score a document.
1. Methods for using function queries
There are three main ways to use function queries, and these three s methods are all via the SOLR HTTP interface.
1) Use Functionqparserplugin. Ie:q={!func}log (foo)
2) embedded in the normal SOLR query expression using the "_val_" inline method. That is, the function query is written in the Q parameter, when we use "_val_" to distinguish the function from other queries. Ie:entryNm:make && _val_:ord (ENTRYNM)
3) Use the BF parameter in Dismax to 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.
For ex:
Q=dismax&bf= "Ord" (popularity) ^0.5 Recip (Rord (Price), 1,1000,1000) ^0.3 2. function Query Syntax at present, functions query does not support the form of a+b, we have to write it in a method form, which is sum (A, B).

3. Use function Query considerations
1) The field used for the function query must be indexed;
2) The field cannot be multi-valued (multi-value)

4. Functions that can be used (available function)
1) Constant: Supports constants with decimal points; for example: 1.5; solrquerysyntax:_val_:1.5
2) Fieldvalue: This function will return the value of the numeric field, which 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, which 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 is important to note that the function of Ord () Depends 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 "sum". Formatting: 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) indicates the value of dividing by y, format: div (1,x), Div (sum (x,100), Max (y,1))
8) Pow:pow represents a power value. Pow (x, y) =x^y. For example: Pow (x,0.5) denotes a pow (x,log (y))
9) abs:abs (x) returns the absolute value of an expression. Format: ABS (-5), ABS (x)
Log:log (x) will return the logarithm of radix 10,x. Format: Log (x), log (sum (x,100))
One) sqrt:sqrt (x) returns the square root of a number. Format: sqrt (2), sqrt (sum (x,100))
Map: If x>=min, and X<=max, then map (x,min,max,target) =target. If x is not in the [Min,max] zone, then map (x,min,max,target) =x. Format: Map (x,0,0,1)
Scale:scale (X,mintarget,maxtarget) This function will limit the value of x to [Mintarget,maxtarget] in the range. 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) &AMP;QQ={!DISMAX}SOLR rocks the same effect as the previous example. But here's the way it's quoted.
Q=product (popularity, query ($QQ, 0.1) &AMP;QQ={!DISMAX}SOLR rocks adds a default value based on the previous example.
Linear:inear (X,m,c) represents M*x+c, where both M and C are constants, and X is a variable and can be a function. For example: Linear (x,2,4) =2*x+4.
Recip:recip (x,m,a,b) =a/(m*x+b) where m, a, B are constants, and 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)
Max:max (X,C) will return the maximum value between a function and a constant. For example: Max (myfield,0)

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.