LUCENE-6314: BooleanQuery toString() is wrong for FILTER clauses

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1663102 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2015-03-01 13:52:28 +00:00
parent f64e74c0c7
commit b985737d1f
2 changed files with 10 additions and 5 deletions

View File

@ -261,11 +261,7 @@ public class BooleanQuery extends Query implements Iterable<BooleanClause> {
for (int i = 0 ; i < clauses.size(); i++) {
BooleanClause c = clauses.get(i);
if (c.isProhibited()) {
buffer.append("-");
} else if (c.isRequired()) {
buffer.append("+");
}
buffer.append(c.getOccur().toString());
Query subQuery = c.getQuery();
if (subQuery != null) {

View File

@ -741,4 +741,13 @@ public class TestBooleanQuery extends LuceneTestCase {
w.close();
dir.close();
}
public void testToString() {
BooleanQuery bq = new BooleanQuery();
bq.add(new TermQuery(new Term("field", "a")), Occur.SHOULD);
bq.add(new TermQuery(new Term("field", "b")), Occur.MUST);
bq.add(new TermQuery(new Term("field", "c")), Occur.MUST_NOT);
bq.add(new TermQuery(new Term("field", "d")), Occur.FILTER);
assertEquals("a +b -c #d", bq.toString("field"));
}
}