From 99f011a06edaaa91ee545d0a451b6c5cd3b5cbb0 Mon Sep 17 00:00:00 2001 From: David Smiley Date: Sun, 14 Feb 2021 00:53:32 -0500 Subject: [PATCH] Revert "LUCENE-9762: FunctionScoreQuery must guard score() called twice (#2358)" This reverts commit 6c140b6d --- .../queries/function/FunctionScoreQuery.java | 6 +--- .../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 a2750ccf629..aed12ff4d3f 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 737ab7053f0..3450280b1d6 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); - } - } - } }