SOLR query syntax

Source: Internet
Author: User
Tags solr solr query

http://blog.javachen.com/2014/03/03/solr-query-syntax/

Query parameters

Common:

    • q-query string, required.
    • fl-Specifies that the contents of those fields be returned, separated by commas or spaces.
    • start-Returns the offset position of the first record in the full found result, starting at 0, for general paging.
    • rows-Specify the maximum number of records to be returned, with start to achieve paging.
    • sort-Sort, format: sort=<field name>+<desc|asc>[,<field name>+<desc|asc>] . Example: (Instock desc, price asc) means "instock" descending, then "price" ascending, and the default is correlation descending.
    • wt-(writer type) specifies the output format, which can have XML, JSON, PHP, Phps.
    • fq-(filter query) FQ query, function: In the Q query matches the result is also the same as the query, for example: q=mm&fq=date_time:[20081001 TO 20091031] , find the keyword mm, and date_time is between 20081001 to 20091031

Not used:

    • defType
    • q.op-Schema.xml Defaultoperator (with "and" or "or" in the case of a space), typically specified by default
    • df-Default query fields, typically specified by default
    • qt-(query type) specifies that type to handle query requests, which are generally not specified and are standard by default.

Other:

    • indent-If the returned result is indented, it is closed by default, and indent=true|on it is necessary to use this parameter for general debug Json,php,phps,ruby output.
    • version-the version of the query syntax, it is recommended not to use it, by the server to specify the default value.
Retrieving operators
  • :Specifies that the field checks for the specified value, such as returning all values :
  • ?A wildcard that represents a single arbitrary character
  • *A wildcard that represents multiple arbitrary characters (cannot start with the retrieved item * or? symbol)
  • ~Represents a fuzzy search, such as retrieving an entry with a spelling similar to "roam": roam~ will find words like foam and roams, and roam~0.8, retrieving records that return a similarity of more than 0.8. Proximity search, such as retrieving 10 words of "Apache" and "Jakarta", "Jakarta Apache"
  • ^Control relevance search, such as retrieving Jakarta Apache, and hoping to make "Jakarta" more relevant, then add "" Symbol and increment value, that is, JAKARTA4 Apache
  • Boolean operatorAND、||
  • Boolean operatorOR、&&
  • Boolean operator NOT、!、- (the exclusion operator cannot be a singleton query with the item usage)
  • +An operator exists that requires that the item after the symbol "+" must exist in the corresponding field of the document
  • ()Used to form subqueries
  • []Include range retrieval, such as retrieving a time period record, including the tail, date:[200707 to 200710]
  • {}Does not include range retrieval, such as retrieving a time period record, not including Kinsoku, date:{200707 to 200710}
  • "Escape operators, special characters include +-&& | | ! ( ) { } [ ] ^ " ~ * ? : "
Example
    • 1. Check All
http://localhost:8080/solr/primary/select?q=*:*
    • 2. Limit the return field
http://localhost:8080/solr/primary/select?q=*:*&fl=productId

means: Query all records, return only the ProductID field

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

Means: Query the first six records, return only the ProductID field

    • 4. Additional Qualifications
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

means: Query category=2002, en_US_city_i=110 and the first six records of Namespace=d, return only ProductID and category fields

    • 5. Add sort
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

Represents: Query category=2002 and Namespace=d and category_2002_sort_i the first six records sorted in ascending order, returning only the ProductID field

    • 6. Facet Query

Realistic Grouping Statistics results

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 which indicates the highlight is used. You can use it h1.fl=field1,field2 to set the highlighted field.

  • hl.fl: A list of fields separated by a space or comma. To enable the highlight function of a field, you have to ensure that the field is stored in the schema. If the parameter is not given, then the default field, standard handler, is used with the DF parameter, and the Dismax field is used with the QF parameter. You can use asterisks to highlight all the fields conveniently. If you are using wildcard characters, consider enabling.
  • hl.requireFieldMatch: If set to true, the field will be highlighted unless the query result is not empty. Its default value is False, which means it may match a field but highlight a different field. If a wildcard character is used by HL.FL, then this parameter must be enabled. However, if your query is the all field (possibly using the Copy-field Directive), set it to false so that the search results indicate which field the query text is not found
  • H l.usePhraseHighlighter : If a query contains a phrase (the quotation marks are framed) then it is guaranteed that the exact phrase must be matched to be highlighted.
  • hl.highlightMultiTermIf you use wildcards and fuzzy searches, you will ensure that the term that matches the wildcard character is highlighted. The default is False, which hl.usePhraseHighlighter is also true.
  • hl.snippets: This is the maximum number of highlighted fragments. The default value is 1 and is almost never modified. If the value of a particular field is set to 0 (for example f.allText.hl.snippets=0 ), this indicates that the field is disabled highlighting. You might use it when you're hl.fl=*.
  • hl.fragsize: The maximum number of characters returned per snippet. The default is 100. If 0, then the field will not be fragmented and the value of the entire field will be returned. This is not done in large print.
  • hl.mergeContiguous: If set to True, the snippet will merge when overlapping.
  • hl.maxAnalyzedChars: Will search for the highlighted maximum character, the default value is 51200, if you want to disable, set to 1
  • hl.alternateField: If no snippet is generated (no terms match), another field value is used as the return.
  • hl.maxAlternateFieldLength: If hl.alternateField enabled, it is sometimes necessary to set the maximum character length for Alternatefield, with the default of 0 being no limit. So a reasonable value is that the hl.snippets * hl.fragsize size of the returned result should be consistent.
  • hl.formatter: An extension point that provides a replaceable formatting algorithm. The default value is simple, which is the only option available at this time. Obviously this is not enough, you can see org.apache.solr.highlight.HtmlFormatter.java how the highlighting element is configured in 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 in some cases will cause false highlighting. - hl.fragmenter : This is the extension point for SOLR to develop the fragment algorithm. Gap is the default value. The Regex is another option that indicates that the bounds of the highlight are determined by a regular expression. This is an atypical advanced option. To know how the default settings and Fragmenters (and formatters) are configured, you can look at the highlight segment in Solrconfig.xml.
  • hl.regex.pattern: Pattern of regular expressions
  • hl.regex.slop: This is a factor that hl.fragsize can change to fit the regular expression. The default value is 0.6, meaning if hlfragsize=100 the size of the fragment will be from 40-160.

Http://www.111cn.net/jsp/Java/65040.htm

After you have configured SOLR, you can manage and query through the Web management interface. The Web interface basically lists most of the query parameters, which can be learned through the query syntax of Lucene.
SOLR query parsing is configured by Queryparser (Solrconfig.xml), generally we use the default. The meanings and usages of each parameter are briefly explained as follows:
Q: Query input, must. You can use operators
FQ: Filter Query. You can use operators
Sort: Sorted field, format field score, multiple fields separated by commas, such as SUM (X_f, Y_f) desc, price ASC, default is score desc
Start: from which line
Rows: How many rows are fetched
FL: Queries the fields to be output, separated by commas, such as Title,price,seller, the asterisk is all, and the asterisk is the default.
DF: The default query field when defining a query.
WT: the type of data returned, which can be in JSON, XML, Python, Ruby, PHP, CSV, and other formats.
Indent:true/false, whether the returned XML format needs to be indented (formatted display), false by default
Debugquery: Debugging a query will output some parameters of the query process.

Highlight correlation:
Highlighting is configured through Searchcomponent, Solrconfig.xml is configured with a searchcomponent named Highlight, and the default implementation is solr.highlightcomponent.
Hl:true/false, whether highlighting
HL.FL: Highlighted fields
Hl.example.pre: Highlighted prefixes
Hl.exapmle.post: Highlighted suffix
Hl.requirefieldmatch: Whether the query specifies only the field (only when Hl.usephrasehighlighter is true) highlighting, which is highlighted by default in all field
Hl.usephrasehighlighter:true/false, use Spanscorer to highlight query phrases
Hl.highlightmultiterm:true/false, if Spanscorer is enabled, this parameter turns on highlighting for prefix/blur/range/wildcard characters, etc.

Facet:true/false
Facets are one of SOLR's advanced search features that give users a more user-friendly search experience (similar to the functionality of breadcrumb navigation). While searching for keywords, you can group statistics by the fields specified by the facet. such as the classification of goods, product specifications. Facet fields must be indexed, no participle (participle is insignificant), and no need to be stored. Refer to SOLR's facet query for details
Facet Query results return fields facet_counts to Responseheader, response peers.
Facet.query: Filter-like syntax, filtering on any field
Facet.field: Fields that need to be faceted
Facet.prefix: Prefix filtering for facet fields
Facet.sort:true/false, in which order the facets are returned, true to sort by count value from large to small, by default true

SpellCheck: Spell Check
SpellCheck is achieved through the component way, You can configure searchcomponent in the Solrconfig.xml file to complete the spell check function, the default implementation is solr.spellcheckcomponent, the specific configuration parameters and implementation principles can be seen here, " Spellcheckcomponent "

Spatial: Spatial Search
Spatial is a search for spatial data, the index and storage of space FieldType is Latlontype or spatialrecursiveprefixtreefieldtype, by using spatial search, you can point, Polygon, such as data indexing, round, square or other shapes to search the range, and search results by distance, etc., the specific configuration parameters and implementation principles can be seen here, "SpatialSearch"


Search operators:
Colon ":": Field:value structure Query, which represents the field value of a query.
Wildcard characters:? (Any character) * (any character)
Boolean operation: and (and, with &&) or (or, same as | |) + (contains)-(not included) not (same as!), note and, or, not all uppercase
Range: [A to B] (from A to B, with A and B, note to uppercase), {A to B} (from A to B, without A and B, note to uppercase)
Sub-operation: () parentheses are similar to mathematical expressions, such as: (Melon OR silly) and men
Fuzzy search: ~ means fuzzy search, for example: roam~ will find the shape such as foam and roams words; roam~0.8, retrieve records that return a similarity of more than 0.8
Control correlation: ^ indicates correlation, such as retrieving Jakarta Apache, and hoping to make "Jakarta" more relevant, then add "^" symbol and increment value, i.e. jakarta^4 Apache

SOLR query syntax

Related Article

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.