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.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1521948 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2013-09-11 17:35:24 +00:00
parent 49a7ccee8c
commit 86d4a61797
3 changed files with 35 additions and 1 deletions

View File

@ -225,6 +225,11 @@ Bug Fixes
* SOLR-5227: Correctly fail schema initalization if a dynamicField is configured to * SOLR-5227: Correctly fail schema initalization if a dynamicField is configured to
be required, or have a default value. (hossman) 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 Optimizations
---------------------- ----------------------

View File

@ -173,7 +173,8 @@ class BoolFieldSource extends ValueSource {
// figure out what ord maps to true // figure out what ord maps to true
int nord = sindex.getValueCount(); int nord = sindex.getValueCount();
BytesRef br = new BytesRef(); 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++) { for (int i=0; i<nord; i++) {
sindex.lookupOrd(i, br); sindex.lookupOrd(i, br);
if (br.length==1 && br.bytes[br.offset]=='T') { if (br.length==1 && br.bytes[br.offset]=='T') {

View File

@ -723,4 +723,32 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
, "/response/docs/[0]=={'a':1, 'b':2.0,'c':'X','d':'A'}"); , "/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'");
}
}
} }