Lucene 简明教程
Lucene - Query Programming
我们在前一章 Lucene - Search Operation 中看到,Lucene 使用 IndexSearcher 进行搜索,并且它使用 QueryParser 创建的 Query 对象作为输入。在本章中,我们将讨论各种类型的 Query 对象以及以编程方式创建它们的不同方法。创建不同类型的 Query 对象可以控制要进行的搜索类型。
We have seen in previous chapter Lucene - Search Operation, Lucene uses IndexSearcher to make searches and it uses the Query object created by QueryParser as the input. In this chapter, we are going to discuss various types of Query objects and the different ways to create them programmatically. Creating different types of Query object gives control on the kind of search to be made.
考虑许多应用程序提供的高级搜索案例,在这些应用程序中用户有多个选项来限定搜索结果。通过查询编程,我们可以非常轻松地实现相同目标。
Consider a case of Advanced Search, provided by many applications where users are given multiple options to confine the search results. By Query programming, we can achieve the same very easily.
以下是我们稍后将讨论的查询类型列表。
Following is the list of Query types that we’ll discuss in due course.
S.No. |
Class & Description |
1 |
TermQueryThis class acts as a core component which creates/updates indexes during the indexing process. |
2 |
TermRangeQueryTermRangeQuery is used when a range of textual terms are to be searched. |
3 |
PrefixQueryPrefixQuery is used to match documents whose index starts with a specified string. |
4 |
BooleanQueryBooleanQuery is used to search documents which are result of multiple queries using AND, OR or NOT operators. |
5 |
PhraseQueryPhrase query is used to search documents which contain a particular sequence of terms. |
6 |
WildCardQueryWildcardQuery is used to search documents using wildcards like '*' for any character sequence,? matching a single character. |
7 |
FuzzyQueryFuzzyQuery is used to search documents using fuzzy implementation that is an approximate search based on the edit distance algorithm. |
8 |
MatchAllDocsQueryMatchAllDocsQuery as the name suggests matches all the documents. |