You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2021/02/14 06:31:07 UTC

[lucene-solr] branch master updated: Revert "LUCENE-9762: FunctionScoreQuery must guard score() called twice (#2358)"

This is an automated email from the ASF dual-hosted git repository.

dsmiley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new 99f011a  Revert "LUCENE-9762: FunctionScoreQuery must guard score() called twice (#2358)"
99f011a is described below

commit 99f011a06edaaa91ee545d0a451b6c5cd3b5cbb0
Author: David Smiley <ds...@apache.org>
AuthorDate: Sun Feb 14 00:53:32 2021 -0500

    Revert "LUCENE-9762: FunctionScoreQuery must guard score() called twice (#2358)"
    
    This reverts commit 6c140b6d
---
 .../queries/function/FunctionScoreQuery.java       |  6 +----
 .../queries/function/TestFunctionScoreQuery.java   | 29 ----------------------
 2 files changed, 1 insertion(+), 34 deletions(-)

diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionScoreQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionScoreQuery.java
index a2750cc..aed12ff 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionScoreQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionScoreQuery.java
@@ -234,13 +234,9 @@ public final class FunctionScoreQuery extends Query {
       }
       DoubleValues scores = valueSource.getValues(context, DoubleValuesSource.fromScorer(in));
       return new FilterScorer(in) {
-        int scoresDocId = -1; // remember the last docId we called score() on
-
         @Override
         public float score() throws IOException {
-          int docId = docID();
-          if (scoresDocId == docId || scores.advanceExact(docId)) {
-            scoresDocId = docId;
+          if (scores.advanceExact(docID())) {
             double factor = scores.doubleValue();
             if (factor >= 0) {
               return (float) (factor * boost);
diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java b/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java
index 737ab70..3450280 100644
--- a/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java
+++ b/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java
@@ -20,16 +20,13 @@ package org.apache.lucene.queries.function;
 import java.io.IOException;
 import java.util.concurrent.atomic.AtomicReference;
 import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
 import org.apache.lucene.document.NumericDocValuesField;
-import org.apache.lucene.document.TextField;
 import org.apache.lucene.expressions.Expression;
 import org.apache.lucene.expressions.SimpleBindings;
 import org.apache.lucene.expressions.js.JavascriptCompiler;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
@@ -38,7 +35,6 @@ import org.apache.lucene.search.DoubleValuesSource;
 import org.apache.lucene.search.Explanation;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.MatchAllDocsQuery;
-import org.apache.lucene.search.PhraseQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.QueryUtils;
 import org.apache.lucene.search.ScoreMode;
@@ -336,29 +332,4 @@ public class TestFunctionScoreQuery extends FunctionTestSetup {
     fq.createWeight(searcher, inputScoreMode, 1f);
     assertEquals(expectedScoreMode, scoreModeInWeight.get());
   }
-
-  /** The FunctionScoreQuery's Scorer score() is going to be called twice for the same doc. */
-  public void testScoreCalledTwice() throws Exception {
-    try (Directory dir = newDirectory()) {
-      IndexWriterConfig conf = newIndexWriterConfig();
-      IndexWriter indexWriter = new IndexWriter(dir, conf);
-      Document doc = new Document();
-      doc.add(new TextField("ExampleText", "periodic function", Field.Store.NO));
-      doc.add(new TextField("ExampleText", "plot of the original function", Field.Store.NO));
-      indexWriter.addDocument(doc);
-      indexWriter.commit();
-      indexWriter.close();
-
-      try (DirectoryReader reader = DirectoryReader.open(dir)) {
-        Query q = new TermQuery(new Term("ExampleText", "function"));
-
-        q =
-            FunctionScoreQuery.boostByQuery(
-                q, new PhraseQuery(1, "ExampleText", "function", "plot"), 2);
-        q = FunctionScoreQuery.boostByValue(q, DoubleValuesSource.SCORES);
-
-        assertEquals(1, new IndexSearcher(reader).search(q, 10).totalHits.value);
-      }
-    }
-  }
 }