Apache SOLR query syntax

Source: Internet
Author: User
Tags apache solr solr solr query

Query Parameters

Frequently used:

    • Q-query string, required.
    • FL-specify the content of the returned fields, which are separated by commas (,) or spaces.
    • Start-return the offset position of the first record in the complete found result. It starts from 0 and is usually used on pages.
    • Rows-specify the maximum number of records returned, and use start to implement paging.
    • Sort-sort, format:Sort = <field Name> + <DESC | ASC> [, <field Name> + <DESC | ASC>]. Example: (instock DESC, price ASC) indicates "instock" first in descending order, and then "price" in ascending order. The default value is correlation in descending order.
    • Wt-(writer type) specifies the output format, which can be XML, JSON, PHP, and PHPs.
    • FQ-(filter query) determines whether a query matches both the FQ query results. For example:Q = mm & FQ = date_time: [20081001 to 20091031], Find the keyword mm, and date_time is between 20081001 and 20091031

Not commonly used:

    • Deftype:
    • Q. Op-overwrite the defaultoperator of Schema. XML ("and" or "or" operation logic is used when spaces exist), which is usually specified by default.
    • DF-default query field, which is generally specified by default
    • Qt-(Query type) specifies the type to process query requests. Generally, this parameter is not required. The default value is standard.

Others:

    • Indent-whether the returned result is indented. It is disabled by default. It is enabled with indent = true | on. This parameter is required only for JSON, PHP, PHPs, and Ruby output debugging.
    • Version-version of the query syntax. We recommend that you do not use it. The default value is specified by the server.
Search Operator
    • ":" Query specified values for specified fields. If all values are returned:
    • "? "Indicates the wildcard of any character
    • ""Indicates the wildcard of Multiple Arbitrary characters (cannot be used in the retrieved itemOr? Symbol)
    • "~ "Indicates fuzzy search. For example, if the search spelling is similar to" Roam ", write it as roam ~ The words like foam and roams are found. roam ~ 0.8. records with a returned similarity of more than 0.8 are retrieved. Nearby search, such as search for "Apache" and "Jakarta", "Jakarta Apache "~ 10
    • "" Controlling relevance search, such as querying Jakarta Apache, and wishing to make "Jakarta" more relevant, then add the "" symbol and increment value after it, that is, jakarta4 Apache
    • Boolean operators and, |
    • Boolean operators or ,&&
    • Boolean operators not ,! ,-(The exclusion operator cannot be used together with items to form a query)
    • "+" Existence operator, requires that the item after the symbol "+" must exist in the corresponding domain of the document
    • () Is used to form a subquery.
    • [] Include range search, such as searching records in a certain period of time, including headers and tails, Date: [200707 to 200710]
    • {} Does not contain range searches. For example, records in a certain period of time do not contain headers and tails. Date: {200707 to 200710}
    • "Escape operator. special characters include +-& |! () {} [] ^ "~ *? :"
Example
    • 1. query all
http://localhost:8080/solr/primary/select?q=*:*
    • 2. Restrict returned Fields
http://localhost:8080/solr/primary/select?q=*:*&fl=productId

Query all records. Only the productid field is returned.

    • 3. Paging
http://localhost:8080/solr/primary/select?q=*:*&fl=productId&rows=6&start=0

Indicates to query the first six records. Only the productid field is returned.

    • 4. Add conditions
http://localhost:8080/solr/primary/select?q=*:*&fl=productId&rows=6&start=0&fq=category:2002&fq=namespace:d&fl=productId+category&fq=en_US_city_i:1101

Indicates to query Category = 2002,En_us_city_ I = 110Only the productid and category fields are returned for the first six records whose namespace is D.

    • 5. Add sorting
http://localhost:8080/solr/primary/select?q=*:*&fl=productId&rows=6&start=0&fq=category:2002&fq=namespace:d&sort=category_2002_sort_i+asc

Query Category = 2002 and namespace = D and pressCategory_2002_sort_ IOnly the productid field is returned for the first six records in ascending order.

    • 6. facet Query

Real-world grouping statistics

http://localhost:8080/solr/primary/select?q=*:*&fl=productId&fq=category:2002&facet=true&facet.field=en_US_county_i&facet.field=en_US_hotelType_s&facet.field=price_p&facet.field=heatRange_ihttp://localhost:8080/solr/primary/select?q=*:*&fl=productId&fq=category:2002&facet=true&facet.field=en_US_county_i&facet.field=en_US_hotelType_s&facet.field=price_p&facet.field=heatRange_i&facet.query=price_p:[300.00000+TO+*]
Highlight

HL-highlight, H1 = true, indicating highlight. You can use h1.fl = field1 and field2 to set the highlighted fields.

  • Hl. FL: List of fields separated by spaces or commas. To enable the highlight function of a field, you must ensure that the field is stored in the schema. If this parameter is not provided, the high-light default field Standard handler uses the DF parameter and the dismax field uses the QF parameter. You can use asterisks to easily highlight all fields. If you use wildcards, enable them.
  • Hl. requirefieldmatch: if it is set to true, It is highlighted unless the query result of this field is not empty. Its default value is false, which means it may match a field but highlight a different field. If hl. Fl uses a wildcard, this parameter is enabled. Even so, if your query is an all field (probably using the copy-Field Command), set it to false, so that the search results can indicate which field of the query text is not found.
  • Hl. usephrasehighlighter: If a query contains a phrase (enclosed in quotation marks), the phrase must be completely matched before being highlighted.
  • If hl. highlightmultiterm uses wildcards and fuzzy search, the matching term with the wildcard is highlighted. The default value is false, and HL. usephrasehighlighter must be true.
  • Hl. snippets: the maximum number of highlighted fragments. The default value is 1, which is almost unchanged. If the value of a specific field is set to 0 (for example, F. alltext. HL. snippets = 0), this indicates that the field is disabled and highlighted. You may use this when hl. FL =.
  • Hl. fragsize: Maximum number of characters returned by each snippet. The default value is 100. If it is 0, this field will not be fragmented and the value of the entire field will be returned. This is not the case when fields are large.
  • Hl. mergecontiguous: if it is set to true, it will be merge when snippet overlaps.
  • Hl. maxanalyzedchars: searches for the maximum highlighted characters. The default value is 51200. If you want to disable it, set it to-1.
  • Hl. alternatefield: If snippet is not generated (no terms match), another field value is used as the return value.
  • Hl. maxalternatefieldlength: If hl. alternatefield is enabled, you sometimes need to specify the maximum character length of alternatefield. The default value 0 is no limit. Therefore, the reasonable value should be hl. snippets * hl. fragsize, so that the returned results will be consistent in size.
  • Hl. formatter: an extension that provides replaceable formatting algorithms. The default value is simple, which is the only option currently. Obviously this is not enough. You can check how the highlighting element is configured in org. Apache. SOLR. Highlight. htmlformatter. Java and solrconfig. xml. Note that, no matter what value is highlighted in the original text, such as the pre-existing em tags will not be escaped, so sometimes leading to false highlighting. -Hl. fragmenter: This is an extension point for SOLR to develop the fragment algorithm. GAP is the default value. RegEx is another option, which specifies that the boundary of highlight is determined by a regular expression. This is an atypical advanced option. To know how the default setting and fragmenters (and formatters) are configured, you can look at the highlight section in solrconfig. xml.
  • Hl. RegEx. Pattern: Pattern of the Regular Expression
  • Hl. RegEx. Slop: this is a factor that HL. fragsize can change to adapt to regular expressions. The default value is 0.6, which means that if hlfragsize = 100, the fragment size ranges from 40 to 160.

Apache SOLR query syntax

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.