Hello,
I have some trouble understanding the semantics of the BooleanQuery with
regards to prohibited clause.
the method I am using is this:
public final void add(Query query, boolean required, boolean prohibited)
in the class BooleanQuery.
I am not using the QueryParser, but instead I build my own queries from a
Tree of search-strings with boolean operators NOT, AND and OR
so a tree might look like this
AND
/ \
"A" NOT
|
"B"
and that would mean "documents containing A, but not B". (If the AND was an
OR, the NOT branch would be culled)
Now my problem is this, when I make a BooleanQuery containing only a
prohibited TermQuery and I add that to another BooleanQuery as a required
query, I always get 0 results.
here's an example of my code:
---------------------------
Term term1 = new Term("name", "jensen");
Term term2 = new Term("name", "barfod");
BooleanQuery minusQuery = new BooleanQuery();
minusQuery.add(new TermQuery(term2), false, true);
BooleanQuery q1 = new BooleanQuery();
q1.add(new TermQuery(term1), true, false);
q1.add(minusQuery, false, false); // not required that the
minusQuery is "matched"
BooleanQuery q2 = new BooleanQuery();
q2.add(new TermQuery(term1), true, false);
q2.add(minusQuery, true, false); // required that the minusQuery
is "matched"
BooleanQuery q3 = new BooleanQuery();
q3.add(new TermQuery(term1), true, false);
q3.add(new TermQuery(term2), false, true); // add the term directly
as a prohibited query
System.out.println("non-required: " + _index.search(q1,
null).length());
System.out.println("required : " + _index.search(q2,
null).length());
System.out.println("directly : " + _index.search(q3, null).length());
---------------------------
this outputs:
non-required: 55
required : 0
directly : 48
Regards,
Anders Nielsen
--
To unsubscribe, e-mail: <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>
I have some trouble understanding the semantics of the BooleanQuery with
regards to prohibited clause.
the method I am using is this:
public final void add(Query query, boolean required, boolean prohibited)
in the class BooleanQuery.
I am not using the QueryParser, but instead I build my own queries from a
Tree of search-strings with boolean operators NOT, AND and OR
so a tree might look like this
AND
/ \
"A" NOT
|
"B"
and that would mean "documents containing A, but not B". (If the AND was an
OR, the NOT branch would be culled)
Now my problem is this, when I make a BooleanQuery containing only a
prohibited TermQuery and I add that to another BooleanQuery as a required
query, I always get 0 results.
here's an example of my code:
---------------------------
Term term1 = new Term("name", "jensen");
Term term2 = new Term("name", "barfod");
BooleanQuery minusQuery = new BooleanQuery();
minusQuery.add(new TermQuery(term2), false, true);
BooleanQuery q1 = new BooleanQuery();
q1.add(new TermQuery(term1), true, false);
q1.add(minusQuery, false, false); // not required that the
minusQuery is "matched"
BooleanQuery q2 = new BooleanQuery();
q2.add(new TermQuery(term1), true, false);
q2.add(minusQuery, true, false); // required that the minusQuery
is "matched"
BooleanQuery q3 = new BooleanQuery();
q3.add(new TermQuery(term1), true, false);
q3.add(new TermQuery(term2), false, true); // add the term directly
as a prohibited query
System.out.println("non-required: " + _index.search(q1,
null).length());
System.out.println("required : " + _index.search(q2,
null).length());
System.out.println("directly : " + _index.search(q3, null).length());
---------------------------
this outputs:
non-required: 55
required : 0
directly : 48
Regards,
Anders Nielsen
--
To unsubscribe, e-mail: <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>