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
BooleanClauses withOccur.SHOULD. In this case, at least one clause has to match for the wholeBooleanQueryto match:Answer to the updated question:
(A OR B) AND Cshould do what you want.I'm not really sure about
+(A OR B) +Csince 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
QueryParsergenerates. You'd need this kind of query structure:BooleanQueryBooleanQueryTermQuery: ATermQuery: BTermQuery: C