You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sa...@apache.org on 2017/10/26 19:20:49 UTC

[2/2] lucene-solr:master: SOLR-10874: Fix AIOOBE caused by FloatPayloadValueSource calling PostingsEnum.nextPosition() more than the given term's frequency in overridden FloatDocValues.floatVal().

SOLR-10874: Fix AIOOBE caused by FloatPayloadValueSource calling PostingsEnum.nextPosition() more than the given term's frequency in overridden FloatDocValues.floatVal().


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/c440361a
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/c440361a
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/c440361a

Branch: refs/heads/master
Commit: c440361a17af3c91ea0d6db3f0805da7762ea2cd
Parents: 95b7530
Author: Steve Rowe <sa...@gmail.com>
Authored: Thu Oct 26 14:44:22 2017 -0400
Committer: Steve Rowe <sa...@gmail.com>
Committed: Thu Oct 26 15:20:42 2017 -0400

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  4 +++
 .../solr/search/FloatPayloadValueSource.java    | 12 ++++++--
 .../solr/search/function/TestFunctionQuery.java | 29 ++++++++++++++++++++
 3 files changed, 42 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c440361a/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 1c7f894..f2ae5fb 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -70,6 +70,10 @@ Bug Fixes
 
 * SOLR-11326: A bootstrap of a target cluster does not need to download the tlog files from the source cluster
   (Amrit Sarkar, Varun Thacker)
+  
+* SOLR-10874: Fix AIOOBE caused by FloatPayloadValueSource calling PostingsEnum.nextPosition()
+  more than the given term's frequency in overridden FloatDocValues.floatVal().
+  (Michael Kosten, Erik Hatcher, Steve Rowe)
 
 Optimizations
 ----------------------

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c440361a/solr/core/src/java/org/apache/solr/search/FloatPayloadValueSource.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/FloatPayloadValueSource.java b/solr/core/src/java/org/apache/solr/search/FloatPayloadValueSource.java
index 23e07e2..9b2d969 100644
--- a/solr/core/src/java/org/apache/solr/search/FloatPayloadValueSource.java
+++ b/solr/core/src/java/org/apache/solr/search/FloatPayloadValueSource.java
@@ -64,6 +64,7 @@ public class FloatPayloadValueSource extends ValueSource {
       PostingsEnum docs ;
       int atDoc;
       int lastDocRequested = -1;
+      float docScore = 0.f;
 
       { reset(); }
 
@@ -141,6 +142,10 @@ public class FloatPayloadValueSource extends ValueSource {
             // out-of-order access.... reset
             reset();
           }
+          else if (doc == lastDocRequested) {
+            return docScore;
+          }
+          
           lastDocRequested = doc;
 
           if (atDoc < doc) {
@@ -150,7 +155,8 @@ public class FloatPayloadValueSource extends ValueSource {
           if (atDoc > doc) {
             // term doesn't match this document... either because we hit the
             // end, or because the next doc is after this doc.
-            return defaultValues.floatVal(doc);
+            docScore =  defaultValues.floatVal(doc);
+            return docScore;
           }
 
           // a match!
@@ -172,8 +178,8 @@ public class FloatPayloadValueSource extends ValueSource {
 
             }
           }
-
-          return (numPayloadsSeen > 0) ? payloadFunction.docScore(doc, indexedField, numPayloadsSeen, currentScore) : defaultValues.floatVal(doc);
+          docScore =  (numPayloadsSeen > 0) ? payloadFunction.docScore(doc, indexedField, numPayloadsSeen, currentScore) : defaultValues.floatVal(doc);
+          return docScore;
         } catch (IOException e) {
           throw new RuntimeException("caught exception in function "+description()+" : doc="+doc, e);
         }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c440361a/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 8383a67..dc23c4c 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
@@ -29,6 +29,7 @@ import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.search.similarities.TFIDFSimilarity;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.common.SolrException;
+import org.apache.solr.common.params.CommonParams;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -503,6 +504,34 @@ public class TestFunctionQuery extends SolrTestCaseJ4 {
     assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,x,0.0,max)"), "//float[@name='score']='37.0'");
     assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,x,0.0,average)"), "//float[@name='score']='26.0'");
     assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,x,0.0,first)"), "//float[@name='score']='22.0'");
+
+    // Test with debug
+    assertQ(req("fl","*,score","q", "{!func}payload(vals_dpf,A)", CommonParams.DEBUG, "true"), "//float[@name='score']='1.0'");
+  }
+
+  @Test
+  public void testRetrievePayloads() throws Exception {
+    clearIndex();
+    int numDocs = 100 + random().nextInt(100);
+    int numLocations = 1000 + random().nextInt(2000);
+    for (int docNum = 0 ; docNum < numDocs ; ++docNum) {
+      StringBuilder amountsBuilder = new StringBuilder();
+      for (int location = 1 ; location <= numLocations ; ++location) {
+        String amount = "" + location + '.' + random().nextInt(100);
+        amountsBuilder.append(location).append('|').append(amount).append(' ');
+      }
+      assertU(adoc("id","" + docNum,
+                   "default_amount_f", "" + (10000 + random().nextInt(10000)) + ".0",
+                   "amounts_dpf", amountsBuilder.toString()));
+    }
+    assertU(commit());
+    assertJQ(req("q","*:*",
+        "fl","id,location:$locationId,amount:$amount",
+        "sort","$amount asc",
+        "amount","payload(amounts_dpf,$locationId,default_amount_f)",
+        "locationId",""+(1+random().nextInt(numLocations)),
+        "wt","json"),
+        "/response/numFound==" + numDocs);
   }
 
   @Test