You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2013/09/11 19:35:25 UTC

svn commit: r1521948 - in /lucene/dev/trunk/solr: CHANGES.txt core/src/java/org/apache/solr/schema/BoolField.java core/src/test/org/apache/solr/search/function/TestFunctionQuery.java

Author: hossman
Date: Wed Sep 11 17:35:24 2013
New Revision: 1521948

URL: http://svn.apache.org/r1521948
Log:
SOLR-5231: Fixed a bug with the behavior of BoolField that caused documents w/o a value for the field to act as if the value were true in functions if no other documents in the same index segment had a value of true.

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/BoolField.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1521948&r1=1521947&r2=1521948&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Wed Sep 11 17:35:24 2013
@@ -225,6 +225,11 @@ Bug Fixes
 * SOLR-5227: Correctly fail schema initalization if a dynamicField is configured to
   be required, or have a default value.  (hossman)
 
+* SOLR-5231: Fixed a bug with the behavior of BoolField that caused documents w/o
+  a value for the field to act as if the value were true in functions if no other
+  documents in the same index segment had a value of true.
+  (Robert Muir, hossman, yonik)
+
 Optimizations
 ----------------------
 

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/BoolField.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/BoolField.java?rev=1521948&r1=1521947&r2=1521948&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/BoolField.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/BoolField.java Wed Sep 11 17:35:24 2013
@@ -173,7 +173,8 @@ class BoolFieldSource extends ValueSourc
     // figure out what ord maps to true
     int nord = sindex.getValueCount();
     BytesRef br = new BytesRef();
-    int tord = -1;
+    // if no values in the segment, default trueOrd to something other then -1 (missing)
+    int tord = -2;
     for (int i=0; i<nord; i++) {
       sindex.lookupOrd(i, br);
       if (br.length==1 && br.bytes[br.offset]=='T') {

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java?rev=1521948&r1=1521947&r2=1521948&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java Wed Sep 11 17:35:24 2013
@@ -723,4 +723,32 @@ public class TestFunctionQuery extends S
         , "/response/docs/[0]=={'a':1, 'b':2.0,'c':'X','d':'A'}");
   }
 
+  public void testMissingFieldFunctionBehavior() throws Exception {
+    clearIndex();
+    // add a doc that has no values in any interesting fields
+    assertU(adoc("id", "1"));
+    assertU(commit());
+
+    // it's important that these functions not only use fields that
+    // out doc have no values for, but also that that no other doc ever added
+    // to the index might have ever had a value for, so that the segment
+    // term metadata doesn't exist
+    
+    for (String suffix : new String[] {"s", "b", "dt", "tdt",
+                                       "i", "l", "f", "d", 
+                                       "pi", "pl", "pf", "pd",
+                                       "ti", "tl", "tf", "td"    }) {
+      final String field = "no__vals____" + suffix;
+      assertQ(req("q","id:1",
+                  "fl","noval_if:if("+field+",42,-99)",
+                  "fl","noval_def:def("+field+",-99)",
+                  "fl","noval_not:not("+field+")",
+                  "fl","noval_exists:exists("+field+")"),
+              "//long[@name='noval_if']='-99'",
+              "//long[@name='noval_def']='-99'",
+              "//bool[@name='noval_not']='true'",
+              "//bool[@name='noval_exists']='false'");
+    }
+  }
+
 }