lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hoss...@apache.org
Subject svn commit: r1306059 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/core/src/ lucene/core/src/test/org/apache/lucene/analysis/ solr/ solr/core/src/java/org/apache/solr/search/ solr/core/src/test/org/apache/solr/search/
Date Tue, 27 Mar 2012 23:40:54 GMT
Author: hossman
Date: Tue Mar 27 23:40:54 2012
New Revision: 1306059

URL: http://svn.apache.org/viewvc?rev=1306059&view=rev
Log:
SOLR-3261: Fix edismax to respect query operators when literal colons are used in query string
(merge r1306054)

Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/core/src/   (props changed)
    lucene/dev/branches/branch_3x/lucene/core/src/test/org/apache/lucene/analysis/   (props
changed)
    lucene/dev/branches/branch_3x/solr/   (props changed)
    lucene/dev/branches/branch_3x/solr/CHANGES.txt
    lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java
    lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java

Modified: lucene/dev/branches/branch_3x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/CHANGES.txt?rev=1306059&r1=1306058&r2=1306059&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/solr/CHANGES.txt Tue Mar 27 23:40:54 2012
@@ -297,6 +297,9 @@ Bug Fixes
 
 * SOLR-3046: Fix whitespace typo in DIH response "Time taken" (hossman)
 
+* SOLR-3261: Fix edismax to respect query operators when literal colons 
+  are used in query string.  (Juan Grande via hossman)
+
 Other Changes
 ----------------------
 * SOLR-2922: Upgrade commons-io and commons-lang to 2.1 and 2.6, respectively. (koji)

Modified: lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java?rev=1306059&r1=1306058&r2=1306059&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java
(original)
+++ lucene/dev/branches/branch_3x/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java
Tue Mar 27 23:40:54 2012
@@ -629,14 +629,17 @@ class ExtendedDismaxQParser extends QPar
   
   public List<Clause> splitIntoClauses(String s, boolean ignoreQuote) {
     ArrayList<Clause> lst = new ArrayList<Clause>(4);
-    Clause clause = new Clause();
+    Clause clause;
 
     int pos=0;
     int end=s.length();
     char ch=0;
     int start;
-    boolean disallowUserField = false;
+    boolean disallowUserField;
     outer: while (pos < end) {
+      clause = new Clause();
+      disallowUserField = true;
+      
       ch = s.charAt(pos);
 
       while (Character.isWhitespace(ch)) {
@@ -653,10 +656,10 @@ class ExtendedDismaxQParser extends QPar
 
       clause.field = getFieldName(s, pos, end);
       if(clause.field != null && !userFields.isAllowed(clause.field)) {
-        disallowUserField = true;
         clause.field = null;
       }
       if (clause.field != null) {
+        disallowUserField = false;
         pos += clause.field.length(); // skip the field name
         pos++;  // skip the ':'
       }
@@ -752,7 +755,11 @@ class ExtendedDismaxQParser extends QPar
 
       if (clause != null) {
         if(disallowUserField) {
-          clause.raw = clause.val;
+          clause.raw = s.substring(start, pos);
+          // escape colons, except for "match all" query
+          if(!"*:*".equals(clause.raw)) {
+            clause.raw = clause.raw.replaceAll(":", "\\\\:");
+          }
         } else {
           clause.raw = s.substring(start, pos);
           // Add default userField boost if no explicit boost exists
@@ -764,8 +771,6 @@ class ExtendedDismaxQParser extends QPar
         }
         lst.add(clause);
       }
-      clause = new Clause();
-      disallowUserField = false;
     }
 
     return lst;

Modified: lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java?rev=1306059&r1=1306058&r2=1306059&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
(original)
+++ lucene/dev/branches/branch_3x/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java
Tue Mar 27 23:40:54 2012
@@ -435,5 +435,70 @@ public class TestExtendedDismaxParser ex
       assertTrue(e.getCause().getMessage().contains("Field aliases lead to a cycle"));
     }
   }
-  
+
+  public void testOperatorsWithLiteralColons() {
+    assertU(adoc("id", "142", "a_s", "bogus:xxx", "text_s", "yak"));
+    assertU(adoc("id", "143", "a_s", "bogus:xxx"));
+    assertU(adoc("id", "144", "text_s", "yak"));
+    assertU(adoc("id", "145", "a_s", "a_s:xxx", "text_s", "yak"));
+    assertU(adoc("id", "146", "a_s", "a_s:xxx"));
+    assertU(adoc("id", "147", "a_s", "AND", "a_s", "NOT"));
+    assertU(commit());
+
+    assertQ(req("q", "bogus:xxx AND text_s:yak",
+                "fl", "id",
+                "qf", "a_s b_s",
+                "defType", "edismax",
+                "mm", "0"),
+            "//*[@numFound='1']",
+            "//str[@name='id'][.='142']");
+    
+    assertQ(req("q", "a_s:xxx AND text_s:yak",
+                "fl", "id",
+                "qf", "a_s b_s",
+                "defType", "edismax",
+                "mm", "0",
+                "uf", "text_s"),
+            "//*[@numFound='1']",
+            "//str[@name='id'][.='145']");
+
+    assertQ(req("q", "NOT bogus:xxx +text_s:yak",
+                "fl", "id",
+                "qf", "a_s b_s",
+                "defType", "edismax",
+                "mm", "0",
+                "debugQuery", "true"),
+            "//*[@numFound='2']",
+            "//str[@name='id'][.='144']",
+            "//str[@name='id'][.='145']");
+    
+    assertQ(req("q", "NOT a_s:xxx +text_s:yak",
+                "fl", "id",
+                "qf", "a_s b_s",
+                "defType", "edismax",
+                "mm", "0",
+                "uf", "text_s"),
+            "//*[@numFound='2']",
+            "//str[@name='id'][.='142']",
+            "//str[@name='id'][.='144']");
+    
+    assertQ(req("q", "+bogus:xxx yak",
+                "fl", "id",
+                "qf", "a_s b_s text_s",
+                "defType", "edismax",
+                "mm", "0"),
+            "//*[@numFound='2']",
+            "//str[@name='id'][.='142']",
+            "//str[@name='id'][.='143']");
+
+    assertQ(req("q", "+a_s:xxx yak",
+                "fl", "id",
+                "qf", "a_s b_s text_s",
+                "defType", "edismax",
+                "mm", "0",
+                "uf", "b_s"),
+            "//*[@numFound='2']",
+            "//str[@name='id'][.='145']",
+            "//str[@name='id'][.='146']");
+  }
 }



Mime
View raw message