這是lucene文檔中Term的定義。
`A Term represents a word from text. This is the unit of search. It is composed of two elements, the text of the word, as a string, and the name of the field that the text occurred in.`
因此,在您的情況下,將創建查詢以在字段「title」中搜索單詞「Lucene」。
要解釋兩者之間的差異讓我來區別例如,
考慮以下
`Query query2=new TermQuery(new Term("title", "Apache Lucene"));`
在這種情況下,查詢將在現場爲確切的詞「阿帕奇Lucene的」搜索標題。
在另一種情況下 作爲一個例子,我們假設一個Lucene索引包含兩個字段「title」和「body」。
`QueryParser parser = new QueryParser("title", "StandardAnalyzer");
Query query1 = parser.parse("title:Apache body:Lucene");
Query query2 = parser.parse("title:Apache Lucene");
Query query2 = parser.parse("title:\"Apache Lucene\"");
`
幾件事。
- 「title」是QueryParser將搜索的字段,如果不用字段作爲前綴(如構造函數中給出的那樣)。
- parser.parse(「title:Apache body:Lucene」); - >在這種情況下,最終查詢將如下所示。 query2 = title:Apache正文:Lucene。
parser.parse(「title:Apache Lucene」); - >在這種情況下,最終查詢也將如下所示。 query2 = title:Apache正文:Lucene。但出於不同的原因。
因此,解析器將在標題字段中搜索「Apache」並在正文字段中搜索「Lucene」。 由於現場只適用於它直接先(http://lucene.apache.org/core/2_9_4/queryparsersyntax.html)一詞,
所以,因爲我們不指定任何Lucene的領域,「身體」將用於這是默認的領域。
query2 = parser.parse(「title:\」Apache Lucene \「」);在這種情況下,我們明確告訴我們要在字段「標題」中搜索「Apache Lucene」。這是詞組查詢,如果分析正確,則與詞語查詢類似。
因此,總結一下,術語查詢不會分析術語並按原樣進行搜索。而查詢解析器基於上述某些條件解析輸入。