LUCENE-3542: Group expanded query terms to preserve parent boolean operator in StandardQueryParser

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1195275 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Simon Willnauer 2011-10-30 23:14:50 +00:00
parent 55ad4c6be1
commit a4794c135b
3 changed files with 15 additions and 8 deletions

View File

@ -139,6 +139,9 @@ Bug Fixes
* LUCENE-3508: Decompounders based on CompoundWordTokenFilterBase can now be
used with custom attributes. All those attributes are preserved and set on all
added decompounded tokens. (Spyros Kapnissis, Uwe Schindler)
* LUCENE-3542: Group expanded query terms to preserve parent boolean operator
in StandartQueryParser. (Simon Willnauer)
API Changes

View File

@ -203,12 +203,8 @@ public class AnalyzerQueryNodeProcessor extends QueryNodeProcessorImpl {
children.add(new FieldQueryNode(field, term, -1, -1));
}
if (positionCount == 1)
return new GroupQueryNode(
new StandardBooleanQueryNode(children, true));
else
return new StandardBooleanQueryNode(children, false);
return new GroupQueryNode(
new StandardBooleanQueryNode(children, positionCount==1));
} else {
// phrase query:
MultiPhraseQueryNode mpq = new MultiPhraseQueryNode();

View File

@ -359,8 +359,16 @@ public class TestQPHelper extends LuceneTestCase {
BooleanQuery expected = new BooleanQuery();
expected.add(new TermQuery(new Term("field", "")), BooleanClause.Occur.SHOULD);
expected.add(new TermQuery(new Term("field", "")), BooleanClause.Occur.SHOULD);
assertEquals(expected, getQuery("中国", analyzer));
expected = new BooleanQuery();
expected.add(new TermQuery(new Term("field", "")), BooleanClause.Occur.MUST);
BooleanQuery inner = new BooleanQuery();
inner.add(new TermQuery(new Term("field", "")), BooleanClause.Occur.SHOULD);
inner.add(new TermQuery(new Term("field", "")), BooleanClause.Occur.SHOULD);
expected.add(inner, BooleanClause.Occur.MUST);
assertEquals(expected, getQuery("中 AND 中国", new SimpleCJKAnalyzer()));
}
public void testCJKBoostedTerm() throws Exception {
@ -609,7 +617,7 @@ public class TestQPHelper extends LuceneTestCase {
assertQueryEquals("drop AND stop AND roll", qpAnalyzer, "+drop +roll");
assertQueryEquals("term phrase term", qpAnalyzer,
"term phrase1 phrase2 term");
"term (phrase1 phrase2) term");
assertQueryEquals("term AND NOT phrase term", qpAnalyzer,
"+term -(phrase1 phrase2) term");