我是Lucene的新手,我想知道
之间有什么区别(如果有的话)PhraseQuery.add(Term1)
PhraseQuery.add(Term2)
PhraseQuery.add(Term3)
和
term1 = new TermQuery(new Term(...));
booleanQuery.add(term1, BooleanClause.Occur.SHOULD);
term2 = new TermQuery(new Term(...));
booleanQuery.add(term2, BooleanClause.Occur.SHOULD);
term3 = new TermQuery(new Term(...));
booleanQuery.add(term3, BooleanClause.Occur.SHOULD);
答案 0 :(得分:3)
PhraseQuery
要求搜索字段中存在所有字词。BooleanQuery
并不要求所有条款都存在。这导致了PhraseQuery
和:
term1 = new TermQuery(new Term(...));
booleanQuery.add(term1, BooleanClause.Occur.MUST);
term2 = new TermQuery(new Term(...));
booleanQuery.add(term2, BooleanClause.Occur.MUST);
term3 = new TermQuery(new Term(...));
booleanQuery.add(term3, BooleanClause.Occur.MUST);
这里的区别在于PhraseQuery
要求条款的顺序正确,而BooleanQuery
则不需要任何特定的订单要求。