Apache Lucene open-source search software
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.
Chris M. Hostetter86d4a61797cd
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex b3bdca90287..9c2f2e16276 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -225,6 +225,11 @@ Bug Fixes* SOLR-5227: Correctly fail schema initalization if a dynamicField is configured tobe 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----------------------diff --git a/solr/core/src/java/org/apache/solr/schema/BoolField.java b/solr/core/src/java/org/apache/solr/schema/BoolField.javaindex 3704120a152..d7be93b91fd 100644--- a/solr/core/src/java/org/apache/solr/schema/BoolField.java+++ b/solr/core/src/java/org/apache/solr/schema/BoolField.java@@ -173,7 +173,8 @@ class BoolFieldSource extends ValueSource {// figure out what ord maps to trueint 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') {diff --git a/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java b/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.javaindex 7778240910b..7068b1620c9 100644--- a/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java+++ b/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java@@ -723,4 +723,32 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {, "/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'");+ }+ }+}