How can QueryParser from Apache Lucene be used to have a query that either contains term A or term B (or both, but at least one of them). EDIT: Also, it contains other MUST clauses, e.g., it must contain C and it must contain either A or B.
Is this then correct?
+(A OR B) +C
It is simply:
A OR B
(or justA B
)This will generate two
BooleanClause
s withOccur.SHOULD
. In this case, at least one clause has to match for the wholeBooleanQuery
to match:Answer to the updated question:
(A OR B) AND C
should do what you want.I'm not really sure about
+(A OR B) +C
since it looks like it should work but you stated that+(A OR B)
doesn't work like you expect it to in your original question.To make sure, you can take a look at what
QueryParser
generates. You'd need this kind of query structure:BooleanQuery
BooleanQuery
TermQuery
: ATermQuery
: BTermQuery
: C