I'm new to Lucene and I would like to know what's the difference (if there is any) between
PhraseQuery.add(Term1)
PhraseQuery.add(Term2)
PhraseQuery.add(Term3)
and
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);
PhraseQuery requires that all the terms exist in the field being searched.BooleanQuery does not require that all the terms exist.This leads to the question of what is the difference between your PhraseQuery and:
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);
The difference here is that the PhraseQuery would require the terms be in the correct order, as opposed to the BooleanQuery which would not have any particular order requirement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With