Query object in Lucene

Source: Internet
Author: User

Before searching, you need to analyze the search string, which is completed by queryparser. To ensure the correctness of the query, it is best to use the same analyzer when creating the index file. When queryparser parses a string, you can specify the query domain. In fact, you can specify one or more fields in the string. For example, "info: TV station and ID: 3329", "info: TV station", and "TV station" are queried in the default domain if the default domain is not specified.

 

After queryparser calls the static method parse, it will return the query instance and perform atomic queries. For example, "info: TV station and ID: 3329" will return booleanquery, "info: TV station" or "TV station" will return phrasequery, and "station" will return termquery.

 

Lucene built-in query object:

 

Termquery: Query of entries. By specifying an entry, you can retrieve all documents with this entry in the index.

Booleanquery: Boolean query. Lucene contains the logical relationship: complex queries with, or without are eventually expressed as booleanquery. A boolean query is a query composed of a boolean logic composed of multiple clauses and clauses.

Rangequery: range query. This range can be date, time, number, size, and so on.

Prefixquery: prefix query.

Phrasequery: phrase query. The default value is exact match, but you can specify the slope (slop, default value: 0) to change the range. For example, if slop = 1 and the search phrase is "station", a word in the middle of "station" can also be found, such as "TV station ".

Multiphrasequery: Multi-phrase query.

Fuquery: fuzzy query. The matching algorithm used for fuzzy search is levenshitein. When comparing two strings, this algorithm divides the action into three types: add an insert letter, delete a letter, and change a letter (substitute ).

Wildcardquery: wildcard query. "*" Indicates 0 to multiple characters. "?" Represents a single character.

Spanquery: Span query. This class is an abstract class.

Spantermquery: the retrieval result is exactly the same as that of termquery, but some location information is recorded internally for other spanquery APIs. It is the basis for other spanquery APIs.

Spanfirstquery: searches for the specified entry within a fixed width starting from the start position of the field content.

Spannearquery: similar to pharasequery. Spannearquery does not necessarily match a phrase. It may also be the query result of another spanquery for nested queries.

Spanorquery: combines all spanquery query results as search results.

Spannotquery: removes the second spanquery query result from the first spanquery query result as the search result.

 

Booleanclause is a class used to represent the relationship between a Boolean query clause, including booleanclause. occur. Must, booleanclause. occur. must_not, booleanclause. occur. shocould. There are 6 types of combinations:

1. Must and must: Get the intersection of multiple query clauses.

2. Must and must_not: the query results cannot contain the search results of the query clause corresponding to must_not.

3. must_not and must_not: meaningless. No results are returned.

4. When shoshould is connected to must, shoshould, and must_not: The result is the retrieval result of the must clause. The function is the same as that of must_not.

5. shocould and shocould: Indicate the "or" relationship. The final search result is the union of all search clauses.

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.