Does the following do that:
BooleanQuery Query QA = new Boolean Query(); Query qa1 = QueryParser.parse("A1", "FieldA", analyzer()); Query qa2 = QueryParser.parse("A2", "FieldA", analyzer()); QA.add(qa1, false, false); // this term is not required QA.add(qa2, false, false); // this term is not required
BooleanQuery QB = new BooleanQuery(); Query qb1 = QueryParser.parse("B1", "FieldB", analyzer()); Query qb2 = QueryParser.parse("B2", "FieldB", analyzer()); QB.add(qb1, false, false); // this term is not required QB.add(qb2, false, false); // this term is not required
BooleanQuery Qfinal = new BooleanQuery(); Qfinal.add(QA, true, false); // gotta have at least one from here Qfinal.add(QB, true, false); // gotta have at least one from here
hits = mySearcher.search(Qfinal);
Your use of QueryParser is unnecessary. Simply construct TermQuery's instead. Otherwise, what you are doing looks fine.
I guess I'm assuming that if I add a queries to a BooleanQuery and none of
the items are required, there still needs to be a hit on at least one of the
items for the Document to make it out of the BooleanQuery.
Right. A OR B means that either A or B have to be present, but if neither are present then there is no match.
Is this the right way to do this? Is there an easier/faster way to do the
same thing?
You're asking a pretty general question - are you really just using two terms for each field? What you've shown based on the example (with the exception of using QueryParser) is fine.
Erik
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
