Apache Solr open-source search software
LUCENE-3542: Group expanded query terms to preserve parent boolean operator in StandardQueryParser
Simon Willnauera4794c135b68
diff --git a/lucene/contrib/CHANGES.txt b/lucene/contrib/CHANGES.txtindex 598c6e6b2ad..31ca0f3f164 100644--- a/lucene/contrib/CHANGES.txt+++ b/lucene/contrib/CHANGES.txt@@ -139,6 +139,9 @@ Bug Fixes* LUCENE-3508: Decompounders based on CompoundWordTokenFilterBase can now beused with custom attributes. All those attributes are preserved and set on alladded decompounded tokens. (Spyros Kapnissis, Uwe Schindler)++ * LUCENE-3542: Group expanded query terms to preserve parent boolean operator+ in StandartQueryParser. (Simon Willnauer)API Changesdiff --git a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/AnalyzerQueryNodeProcessor.java b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/AnalyzerQueryNodeProcessor.javaindex 384adf63719..dad54691c9f 100644--- a/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/AnalyzerQueryNodeProcessor.java+++ b/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/AnalyzerQueryNodeProcessor.java@@ -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();diff --git a/modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java b/modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.javaindex a132341c280..55d155b8f40 100644--- a/modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java+++ b/modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java@@ -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");