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.