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 2018/01/06 20:05:38 UTC
[1/2] lucene-solr:master: SOLR-11758: Fixed FloatDocValues.boolVal to
correctly return true for all values != 0.0F
Repository: lucene-solr
Updated Branches:
refs/heads/branch_7x 169850f90 -> a6cd4ac41
refs/heads/master 0d5581177 -> d03cb44de
SOLR-11758: Fixed FloatDocValues.boolVal to correctly return true for all values != 0.0F
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/d03cb44d
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/d03cb44d
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/d03cb44d
Branch: refs/heads/master
Commit: d03cb44de73bb29e16a3ab927ee57d6eb916789a
Parents: 0d55811
Author: Chris Hostetter <ho...@apache.org>
Authored: Sat Jan 6 12:54:05 2018 -0700
Committer: Chris Hostetter <ho...@apache.org>
Committed: Sat Jan 6 12:54:05 2018 -0700
----------------------------------------------------------------------
lucene/CHANGES.txt | 3 +
.../function/docvalues/FloatDocValues.java | 5 ++
.../docvalues/TestBoolValOfNumericDVs.java | 76 ++++++++++++++++++++
.../solr/search/function/TestFunctionQuery.java | 16 ++++-
4 files changed, 97 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d03cb44d/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 89afdfd..2b02b87 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -124,6 +124,9 @@ Bug Fixes
* LUCENE-8077: Fixed bug in how CheckIndex verifies doc-value iterators.
(Xiaoshan Sun via Adrien Grand)
+* SOLR-11758: Fixed FloatDocValues.boolVal to correctly return true for all values != 0.0F
+ (Munendra S N via hossman)
+
Other
* LUCENE-8111: IndexOrDocValuesQuery Javadoc references outdated method name.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d03cb44d/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/FloatDocValues.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/FloatDocValues.java b/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/FloatDocValues.java
index 8b9e942..72798d6 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/FloatDocValues.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/FloatDocValues.java
@@ -58,6 +58,11 @@ public abstract class FloatDocValues extends FunctionValues {
}
@Override
+ public boolean boolVal(int doc) throws IOException {
+ return floatVal(doc) != 0.0f;
+ }
+
+ @Override
public double doubleVal(int doc) throws IOException {
return (double)floatVal(doc);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d03cb44d/lucene/queries/src/test/org/apache/lucene/queries/function/docvalues/TestBoolValOfNumericDVs.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/docvalues/TestBoolValOfNumericDVs.java b/lucene/queries/src/test/org/apache/lucene/queries/function/docvalues/TestBoolValOfNumericDVs.java
new file mode 100644
index 0000000..a604674
--- /dev/null
+++ b/lucene/queries/src/test/org/apache/lucene/queries/function/docvalues/TestBoolValOfNumericDVs.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.queries.function.docvalues;
+
+import java.io.IOException;
+
+import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.util.LuceneTestCase;
+
+/**
+ * <p>
+ * Sanity check that {@link FunctionValues#boolVal} behaves as expected for trivial subclasses of the various
+ * (Numeric) DocValue implementations.
+ * </p>
+ * <p>
+ * Any "non-zero" value should result in "true"
+ * </p>
+ */
+public class TestBoolValOfNumericDVs extends LuceneTestCase {
+
+ public void test() throws IOException {
+ check(true);
+ check(false);
+ }
+
+ public void check(final boolean expected) throws IOException {
+
+ // create "constant" based instances of each superclass that should returned the expected value based on
+ // the constant used
+ final FunctionValues[] values = new FunctionValues[] {
+ new FloatDocValues(null) {
+ @Override
+ public float floatVal(int doc) throws IOException {
+ return expected ? Float.MIN_VALUE : 0.0F;
+ }
+ },
+ new DoubleDocValues(null) {
+ @Override
+ public double doubleVal(int doc) throws IOException {
+ return expected ? Double.MIN_VALUE : 0.0D;
+ }
+ },
+ new IntDocValues(null) {
+ @Override
+ public int intVal(int doc) throws IOException {
+ return expected ? 1 : 0;
+ }
+ },
+ new LongDocValues(null) {
+ @Override
+ public long longVal(int doc) throws IOException {
+ return expected ? 1L : 0L;
+ }
+ },
+ };
+
+ for (FunctionValues fv : values) {
+ // docId is irrelevant since all of our FunctionValues return a constant value.
+ assertEquals(fv.getClass().getSuperclass().toString(), expected, fv.boolVal(123));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d03cb44d/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java
----------------------------------------------------------------------
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.java
index 53e1ea7..32f603a 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
@@ -800,7 +800,7 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
public void testBooleanFunctions() throws Exception {
clearIndex();
- assertU(adoc("id", "1", "text", "hello", "foo_s","A", "foo_ti", "0", "foo_tl","0"));
+ assertU(adoc("id", "1", "text", "hello", "foo_s","A", "foo_ti", "0", "foo_tl","0", "foo_tf", "0.00001"));
assertU(adoc("id", "2" , "foo_ti","10", "foo_tl","11"));
assertU(commit());
@@ -819,6 +819,10 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
// test if()
assertJQ(req("q", "id:1", "fl", "a1:if(true,'A','B')", "fl","b1:if(false,'A',testfunc('B'))")
, "/response/docs/[0]=={'a1':'A', 'b1':'B'}");
+ // queries with positive scores < 1 should still evaluate to 'true' in boolean context
+ assertJQ(req("q", "id:1", "nested", "*:*^=0.00001",
+ "fl", "a1:if(query($nested),'A','B')", "fl","b1:if(not(query($nested)),'A','B')")
+ , "/response/docs/[0]=={'a1':'A', 'b1':'B'}");
// test boolean operators
assertJQ(req("q", "id:1", "fl", "t1:and(testfunc(true),true)", "fl","f1:and(true,false)", "fl","f2:and(false,true)", "fl","f3:and(false,false)")
@@ -830,6 +834,12 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
assertJQ(req("q", "id:1", "fl", "t:not(testfunc(false)),f:not(true)")
, "/response/docs/[0]=={'t':true, 'f':false}");
+ // test fields evaluated as booleans in wrapping functions
+ assertJQ(req("q", "id:1", "fl", "a:not(foo_ti), b:if(foo_tf,'TT','FF'), c:and(true,foo_tf)")
+ , "/response/docs/[0]=={'a':true, 'b':'TT', 'c':true}");
+ assertJQ(req("q", "id:2", "fl", "a:not(foo_ti), b:if(foo_tf,'TT','FF'), c:and(true,foo_tf)")
+ , "/response/docs/[0]=={'a':false, 'b':'FF', 'c':false}");
+
// def(), the default function that returns the first value that exists
assertJQ(req("q", "id:1", "fl", "x:def(id,testfunc(123)), y:def(foo_f,234.0)")
@@ -838,8 +848,8 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
, "/response/docs/[0]=={'x':'A', 'y':'W'}");
// test constant conversion to boolean
- assertJQ(req("q", "id:1", "fl", "a:not(0), b:not(1), c:not(0.0), d:not(1.1), e:not('A')")
- , "/response/docs/[0]=={'a':true, 'b':false, 'c':true, 'd':false, 'e':false}");
+ assertJQ(req("q", "id:1", "fl", "a:not(0), b:not(1), c:not(0.0), d:not(1.1), e:not('A'), f:not(0.001)")
+ , "/response/docs/[0]=={'a':true, 'b':false, 'c':true, 'd':false, 'e':false, 'f':false}");
}
[2/2] lucene-solr:branch_7x: SOLR-11758: Fixed FloatDocValues.boolVal
to correctly return true for all values != 0.0F
Posted by ho...@apache.org.
SOLR-11758: Fixed FloatDocValues.boolVal to correctly return true for all values != 0.0F
(cherry picked from commit d03cb44de73bb29e16a3ab927ee57d6eb916789a)
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/a6cd4ac4
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/a6cd4ac4
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/a6cd4ac4
Branch: refs/heads/branch_7x
Commit: a6cd4ac41941f1d8bfc5b2e5267c8bdec1b62b56
Parents: 169850f
Author: Chris Hostetter <ho...@apache.org>
Authored: Sat Jan 6 12:54:05 2018 -0700
Committer: Chris Hostetter <ho...@apache.org>
Committed: Sat Jan 6 12:54:18 2018 -0700
----------------------------------------------------------------------
lucene/CHANGES.txt | 3 +
.../function/docvalues/FloatDocValues.java | 5 ++
.../docvalues/TestBoolValOfNumericDVs.java | 76 ++++++++++++++++++++
.../solr/search/function/TestFunctionQuery.java | 16 ++++-
4 files changed, 97 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a6cd4ac4/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index dc3c992..e737ba4 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -46,6 +46,9 @@ Bug Fixes
* LUCENE-8077: Fixed bug in how CheckIndex verifies doc-value iterators.
(Xiaoshan Sun via Adrien Grand)
+* SOLR-11758: Fixed FloatDocValues.boolVal to correctly return true for all values != 0.0F
+ (Munendra S N via hossman)
+
Other
* LUCENE-8111: IndexOrDocValuesQuery Javadoc references outdated method name.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a6cd4ac4/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/FloatDocValues.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/FloatDocValues.java b/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/FloatDocValues.java
index 8b9e942..72798d6 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/FloatDocValues.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/FloatDocValues.java
@@ -58,6 +58,11 @@ public abstract class FloatDocValues extends FunctionValues {
}
@Override
+ public boolean boolVal(int doc) throws IOException {
+ return floatVal(doc) != 0.0f;
+ }
+
+ @Override
public double doubleVal(int doc) throws IOException {
return (double)floatVal(doc);
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a6cd4ac4/lucene/queries/src/test/org/apache/lucene/queries/function/docvalues/TestBoolValOfNumericDVs.java
----------------------------------------------------------------------
diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/docvalues/TestBoolValOfNumericDVs.java b/lucene/queries/src/test/org/apache/lucene/queries/function/docvalues/TestBoolValOfNumericDVs.java
new file mode 100644
index 0000000..a604674
--- /dev/null
+++ b/lucene/queries/src/test/org/apache/lucene/queries/function/docvalues/TestBoolValOfNumericDVs.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.queries.function.docvalues;
+
+import java.io.IOException;
+
+import org.apache.lucene.queries.function.FunctionValues;
+import org.apache.lucene.util.LuceneTestCase;
+
+/**
+ * <p>
+ * Sanity check that {@link FunctionValues#boolVal} behaves as expected for trivial subclasses of the various
+ * (Numeric) DocValue implementations.
+ * </p>
+ * <p>
+ * Any "non-zero" value should result in "true"
+ * </p>
+ */
+public class TestBoolValOfNumericDVs extends LuceneTestCase {
+
+ public void test() throws IOException {
+ check(true);
+ check(false);
+ }
+
+ public void check(final boolean expected) throws IOException {
+
+ // create "constant" based instances of each superclass that should returned the expected value based on
+ // the constant used
+ final FunctionValues[] values = new FunctionValues[] {
+ new FloatDocValues(null) {
+ @Override
+ public float floatVal(int doc) throws IOException {
+ return expected ? Float.MIN_VALUE : 0.0F;
+ }
+ },
+ new DoubleDocValues(null) {
+ @Override
+ public double doubleVal(int doc) throws IOException {
+ return expected ? Double.MIN_VALUE : 0.0D;
+ }
+ },
+ new IntDocValues(null) {
+ @Override
+ public int intVal(int doc) throws IOException {
+ return expected ? 1 : 0;
+ }
+ },
+ new LongDocValues(null) {
+ @Override
+ public long longVal(int doc) throws IOException {
+ return expected ? 1L : 0L;
+ }
+ },
+ };
+
+ for (FunctionValues fv : values) {
+ // docId is irrelevant since all of our FunctionValues return a constant value.
+ assertEquals(fv.getClass().getSuperclass().toString(), expected, fv.boolVal(123));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a6cd4ac4/solr/core/src/test/org/apache/solr/search/function/TestFunctionQuery.java
----------------------------------------------------------------------
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.java
index 81ba9df..0d1ae70 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
@@ -800,7 +800,7 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
public void testBooleanFunctions() throws Exception {
clearIndex();
- assertU(adoc("id", "1", "text", "hello", "foo_s","A", "foo_ti", "0", "foo_tl","0"));
+ assertU(adoc("id", "1", "text", "hello", "foo_s","A", "foo_ti", "0", "foo_tl","0", "foo_tf", "0.00001"));
assertU(adoc("id", "2" , "foo_ti","10", "foo_tl","11"));
assertU(commit());
@@ -819,6 +819,10 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
// test if()
assertJQ(req("q", "id:1", "fl", "a1:if(true,'A','B')", "fl","b1:if(false,'A',testfunc('B'))")
, "/response/docs/[0]=={'a1':'A', 'b1':'B'}");
+ // queries with positive scores < 1 should still evaluate to 'true' in boolean context
+ assertJQ(req("q", "id:1", "nested", "*:*^=0.00001",
+ "fl", "a1:if(query($nested),'A','B')", "fl","b1:if(not(query($nested)),'A','B')")
+ , "/response/docs/[0]=={'a1':'A', 'b1':'B'}");
// test boolean operators
assertJQ(req("q", "id:1", "fl", "t1:and(testfunc(true),true)", "fl","f1:and(true,false)", "fl","f2:and(false,true)", "fl","f3:and(false,false)")
@@ -830,6 +834,12 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
assertJQ(req("q", "id:1", "fl", "t:not(testfunc(false)),f:not(true)")
, "/response/docs/[0]=={'t':true, 'f':false}");
+ // test fields evaluated as booleans in wrapping functions
+ assertJQ(req("q", "id:1", "fl", "a:not(foo_ti), b:if(foo_tf,'TT','FF'), c:and(true,foo_tf)")
+ , "/response/docs/[0]=={'a':true, 'b':'TT', 'c':true}");
+ assertJQ(req("q", "id:2", "fl", "a:not(foo_ti), b:if(foo_tf,'TT','FF'), c:and(true,foo_tf)")
+ , "/response/docs/[0]=={'a':false, 'b':'FF', 'c':false}");
+
// def(), the default function that returns the first value that exists
assertJQ(req("q", "id:1", "fl", "x:def(id,testfunc(123)), y:def(foo_f,234.0)")
@@ -838,8 +848,8 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
, "/response/docs/[0]=={'x':'A', 'y':'W'}");
// test constant conversion to boolean
- assertJQ(req("q", "id:1", "fl", "a:not(0), b:not(1), c:not(0.0), d:not(1.1), e:not('A')")
- , "/response/docs/[0]=={'a':true, 'b':false, 'c':true, 'd':false, 'e':false}");
+ assertJQ(req("q", "id:1", "fl", "a:not(0), b:not(1), c:not(0.0), d:not(1.1), e:not('A'), f:not(0.001)")
+ , "/response/docs/[0]=={'a':true, 'b':false, 'c':true, 'd':false, 'e':false, 'f':false}");
}