You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2011/10/31 00:14:50 UTC

svn commit: r1195275 - in /lucene/dev/trunk: lucene/contrib/ modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/ modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/

Author: simonw
Date: Sun Oct 30 23:14:50 2011
New Revision: 1195275

URL: http://svn.apache.org/viewvc?rev=1195275&view=rev
Log:
LUCENE-3542: Group expanded query terms to preserve parent boolean operator in StandardQueryParser

Modified:
    lucene/dev/trunk/lucene/contrib/CHANGES.txt
    lucene/dev/trunk/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/AnalyzerQueryNodeProcessor.java
    lucene/dev/trunk/modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java

Modified: lucene/dev/trunk/lucene/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/contrib/CHANGES.txt?rev=1195275&r1=1195274&r2=1195275&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/contrib/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/contrib/CHANGES.txt Sun Oct 30 23:14:50 2011
@@ -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
  

Modified: lucene/dev/trunk/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/AnalyzerQueryNodeProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/AnalyzerQueryNodeProcessor.java?rev=1195275&r1=1195274&r2=1195275&view=diff
==============================================================================
--- lucene/dev/trunk/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/AnalyzerQueryNodeProcessor.java (original)
+++ lucene/dev/trunk/modules/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/AnalyzerQueryNodeProcessor.java Sun Oct 30 23:14:50 2011
@@ -203,12 +203,8 @@ public class AnalyzerQueryNodeProcessor 
             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();

Modified: lucene/dev/trunk/modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java?rev=1195275&r1=1195274&r2=1195275&view=diff
==============================================================================
--- lucene/dev/trunk/modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java (original)
+++ lucene/dev/trunk/modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java Sun Oct 30 23:14:50 2011
@@ -359,8 +359,16 @@ public class TestQPHelper extends Lucene
     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 Lucene
 
     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");