📜  Lucene-查询编程

📅  最后修改于: 2020-11-12 04:47:33             🧑  作者: Mango


我们在上一章的Lucene-搜索操作中已经看到过,Lucene使用IndexSearcher进行搜索,并且使用QueryParser创建的Query对象作为输入。在本章中,我们将讨论各种类型的Query对象以及以编程方式创建它们的不同方法。创建不同类型的Query对象可以控制要进行的搜索类型。

考虑由许多应用程序提供的高级搜索的情况,其中为用户提供了多种选择来限制搜索结果。通过查询编程,我们可以很容易地实现相同目的。

以下是我们将在适当时候讨论的查询类型的列表。

S.No. Class & Description
1 TermQuery

This class acts as a core component which creates/updates indexes during the indexing process.

2 TermRangeQuery

TermRangeQuery is used when a range of textual terms are to be searched.

3 PrefixQuery

PrefixQuery is used to match documents whose index starts with a specified string.

4 BooleanQuery

BooleanQuery is used to search documents which are result of multiple queries using AND, OR or NOT operators.

5 PhraseQuery

Phrase query is used to search documents which contain a particular sequence of terms.

6 WildCardQuery

WildcardQuery is used to search documents using wildcards like ‘*’ for any character sequence,? matching a single character.

7 FuzzyQuery

FuzzyQuery is used to search documents using fuzzy implementation that is an approximate search based on the edit distance algorithm.

8 MatchAllDocsQuery

MatchAllDocsQuery as the name suggests matches all the documents.