I have two fields, call them FieldA and FieldB. I have a set of words I'm
looking for in FieldA, call them A1 and A2. I have a different set of words
for FieldB, call them B1 and B2. Now I want a hit list which contains items
that have at least one A item in FieldA and one B item in FieldB. In
essence, I think I'm saying I want "(A1 OR A2) AND (B1 OR B2)"
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);
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.
Is this the right way to do this? Is there an easier/faster way to do the
same thing?
Scott
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]