From de40a94e96498fe4459e68d61550449bd75e2526 Mon Sep 17 00:00:00 2001 From: iamsanjay Date: Thu, 30 May 2024 19:36:36 +0530 Subject: [PATCH 1/5] Removed Scorer#getWeight --- lucene/CHANGES.txt | 5 +- lucene/MIGRATE.md | 6 + .../java/org/apache/lucene/search/Scorer.java | 9 - .../TestBooleanQueryVisitSubscorers.java | 16 +- .../lucene/search/TestConjunctions.java | 23 +- .../search/TestConstantScoreScorer.java | 5 +- .../lucene/search/TestSubScorerFreqs.java | 270 ------------------ .../queries/payloads/PayloadScoreQuery.java | 2 +- .../sandbox/search/QueryProfilerScorer.java | 9 - .../lucene/tests/search/AssertingScorer.java | 17 +- .../lucene/tests/search/AssertingWeight.java | 1 + .../search/RandomApproximationQuery.java | 6 +- .../tests/search/ScorerIndexSearcher.java | 1 + 13 files changed, 50 insertions(+), 320 deletions(-) delete mode 100644 lucene/core/src/test/org/apache/lucene/search/TestSubScorerFreqs.java diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 4ad67f9c6b5a..2f14110c28e7 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -110,6 +110,8 @@ API Changes I/O for top-level disjunctions. Weight#bulkScorer() still exists for compatibility, but delegates to ScorerSupplier#bulkScorer(). (Adrien Grand) +* GITHUB#13410: Removed Scorer#getWeight (Sanjay Dutt, Adrien Grand) + New Features --------------------- @@ -458,7 +460,8 @@ API Changes IndexSearcher#search(Query, CollectorManager) for TopFieldCollectorManager and TopScoreDocCollectorManager. (Zach Chen, Adrien Grand, Michael McCandless, Greg Miller, Luca Cavanna) -* GITHUB#12854: Mark DrillSideways#createDrillDownFacetsCollector as @Deprecated. (Greg Miller) +* GITHUB#12854: Mark DrillSideways#createDrillDownFacetsCollector as @ +Deprecated. (Greg Miller) New Features --------------------- diff --git a/lucene/MIGRATE.md b/lucene/MIGRATE.md index 1a2f622b7281..91d0a6e21fea 100644 --- a/lucene/MIGRATE.md +++ b/lucene/MIGRATE.md @@ -779,3 +779,9 @@ to manage the indexed data on their own and create new `Facet` implementations t The `Weight#scorerSupplier` method is now declared abstract, compelling child classes to implement the ScorerSupplier interface. Additionally, `Weight#scorer` is now declared final, with its implementation being delegated to `Weight#scorerSupplier` for the scorer. + +### `Scorer#getWeight` is removed (GITHUB#13410) + +The `Scorer#getWeight` method has been removed. Callers must now keep track of the Weight instance +that created the Scorer if they need it instead of relying on `Scorer`. + diff --git a/lucene/core/src/java/org/apache/lucene/search/Scorer.java b/lucene/core/src/java/org/apache/lucene/search/Scorer.java index 7f613afe9e4c..bf25649ace0c 100644 --- a/lucene/core/src/java/org/apache/lucene/search/Scorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/Scorer.java @@ -39,15 +39,6 @@ protected Scorer(Weight weight) { this.weight = Objects.requireNonNull(weight); } - /** - * returns parent Weight - * - * @lucene.experimental - */ - public Weight getWeight() { - return weight; - } - /** Returns the doc ID that is currently being scored. */ public abstract int docID(); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanQueryVisitSubscorers.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanQueryVisitSubscorers.java index cfdc92574381..68c4c6f8f190 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanQueryVisitSubscorers.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanQueryVisitSubscorers.java @@ -256,9 +256,9 @@ public void testGetChildrenMinShouldMatchSumScorer() throws IOException { "ConjunctionScorer\n" + " MUST ConstantScoreScorer\n" + " MUST WANDScorer\n" - + " SHOULD TermScorer body:crawler\n" - + " SHOULD TermScorer body:web\n" - + " SHOULD TermScorer body:nutch", + + " SHOULD TermScorer\n" + + " SHOULD TermScorer\n" + + " SHOULD TermScorer", summary); } } @@ -272,7 +272,7 @@ public void testGetChildrenBoosterScorer() throws IOException { assertEquals(1, scoreSummary.numHits.get()); assertFalse(scoreSummary.summaries.isEmpty()); for (String summary : scoreSummary.summaries) { - assertEquals("TermScorer body:nutch", summary); + assertEquals("TermScorer", summary); } } @@ -329,14 +329,6 @@ public void collect(int doc) { private static void summarizeScorer( final StringBuilder builder, final Scorable scorer, final int indent) throws IOException { builder.append(scorer.getClass().getSimpleName()); - if (scorer instanceof TermScorer) { - TermQuery termQuery = (TermQuery) ((Scorer) scorer).getWeight().getQuery(); - builder - .append(" ") - .append(termQuery.getTerm().field()) - .append(":") - .append(termQuery.getTerm().text()); - } for (final Scorable.ChildScorable childScorer : scorer.getChildren()) { indent(builder, indent + 1).append(childScorer.relationship).append(" "); summarizeScorer(builder, childScorer.child, indent + 2); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestConjunctions.java b/lucene/core/src/test/org/apache/lucene/search/TestConjunctions.java index c491fe6c47fd..675aa959b665 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestConjunctions.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestConjunctions.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.lucene.analysis.Analyzer; @@ -147,15 +148,14 @@ private static class TestCollector extends SimpleCollector { private final AtomicBoolean setScorerCalled = new AtomicBoolean(false); @Override - public void setScorer(Scorable s) throws IOException { - Collection childScorers = s.getChildren(); - setScorerCalled.set(true); - assertEquals(2, childScorers.size()); + public void setWeight(Weight weight) { + BooleanQuery query = (BooleanQuery) weight.getQuery(); + List clauseList = query.clauses(); + assertEquals(2, clauseList.size()); Set terms = new HashSet<>(); - for (Scorer.ChildScorable childScorer : childScorers) { - Query query = ((Scorer) childScorer.child).getWeight().getQuery(); - assertTrue(query instanceof TermQuery); - Term term = ((TermQuery) query).getTerm(); + for (BooleanClause clause : clauseList) { + assert (clause.query() instanceof TermQuery); + Term term = ((TermQuery) clause.query()).getTerm(); assertEquals("field", term.field()); terms.add(term.text()); } @@ -164,6 +164,13 @@ public void setScorer(Scorable s) throws IOException { assertTrue(terms.contains("b")); } + @Override + public void setScorer(Scorable s) throws IOException { + Collection childScorers = s.getChildren(); + setScorerCalled.set(true); + assertEquals(2, childScorers.size()); + } + @Override public void collect(int doc) {} diff --git a/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreScorer.java index 2f1125cb11af..f9ea6f74b8fe 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreScorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreScorer.java @@ -205,10 +205,9 @@ ConstantScoreScorer constantScoreScorer(Query query, float score, ScoreMode scor Scorer scorer = weight.scorer(context); if (scorer.twoPhaseIterator() == null) { - return new ConstantScoreScorer(scorer.getWeight(), score, scoreMode, scorer.iterator()); + return new ConstantScoreScorer(weight, score, scoreMode, scorer.iterator()); } else { - return new ConstantScoreScorer( - scorer.getWeight(), score, scoreMode, scorer.twoPhaseIterator()); + return new ConstantScoreScorer(weight, score, scoreMode, scorer.twoPhaseIterator()); } } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSubScorerFreqs.java b/lucene/core/src/test/org/apache/lucene/search/TestSubScorerFreqs.java deleted file mode 100644 index cc2cf69bba89..000000000000 --- a/lucene/core/src/test/org/apache/lucene/search/TestSubScorerFreqs.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * 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.search; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; -import org.apache.lucene.index.FieldInvertState; -import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.Term; -import org.apache.lucene.search.BooleanClause.Occur; -import org.apache.lucene.search.similarities.Similarity; -import org.apache.lucene.store.ByteBuffersDirectory; -import org.apache.lucene.store.Directory; -import org.apache.lucene.tests.analysis.MockAnalyzer; -import org.apache.lucene.tests.index.RandomIndexWriter; -import org.apache.lucene.tests.search.AssertingScorable; -import org.apache.lucene.tests.search.DisablingBulkScorerQuery; -import org.apache.lucene.tests.util.LuceneTestCase; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -public class TestSubScorerFreqs extends LuceneTestCase { - - private static Directory dir; - private static IndexSearcher s; - - @BeforeClass - public static void makeIndex() throws Exception { - dir = new ByteBuffersDirectory(); - RandomIndexWriter w = - new RandomIndexWriter( - random(), - dir, - newIndexWriterConfig(new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy())); - // make sure we have more than one segment occationally - int num = atLeast(31); - for (int i = 0; i < num; i++) { - Document doc = new Document(); - doc.add(newTextField("f", "a b c d b c d c d d", Field.Store.NO)); - w.addDocument(doc); - - doc = new Document(); - doc.add(newTextField("f", "a b c d", Field.Store.NO)); - w.addDocument(doc); - } - - s = newSearcher(w.getReader()); - s.setSimilarity(new CountingSimilarity()); - w.close(); - } - - @AfterClass - public static void finish() throws Exception { - s.getIndexReader().close(); - s = null; - dir.close(); - dir = null; - } - - private static class CountingCollectorManager - implements CollectorManager>> { - - private final Set relationships; - - CountingCollectorManager(Set relationships) { - this.relationships = relationships; - } - - @Override - public CountingCollector newCollector() { - TopScoreDocCollector topScoreDocCollector = - TopScoreDocCollector.create(10, Integer.MAX_VALUE); - return relationships == null - ? new CountingCollector(topScoreDocCollector) - : new CountingCollector(topScoreDocCollector, relationships); - } - - @Override - public Map> reduce(Collection collectors) { - Map> docCounts = new HashMap<>(); - for (CountingCollector collector : collectors) { - docCounts.putAll(collector.docCounts); - } - return docCounts; - } - } - - private static class CountingCollector extends FilterCollector { - public final Map> docCounts = new HashMap<>(); - - private final Map subScorers = new HashMap<>(); - private final Set relationships; - - public CountingCollector(Collector other) { - this(other, new HashSet<>(Arrays.asList("MUST", "SHOULD", "MUST_NOT"))); - } - - public CountingCollector(Collector other, Set relationships) { - super(other); - this.relationships = relationships; - } - - public void setSubScorers(Scorable scorer) throws IOException { - scorer = AssertingScorable.unwrap(scorer); - for (Scorable.ChildScorable child : scorer.getChildren()) { - if (relationships.contains(child.relationship)) { - setSubScorers(child.child); - } - } - subScorers.put(((Scorer) scorer).getWeight().getQuery(), (Scorer) scorer); - } - - @Override - public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException { - final int docBase = context.docBase; - return new FilterLeafCollector(super.getLeafCollector(context)) { - - @Override - public void collect(int doc) throws IOException { - final Map freqs = new HashMap(); - for (Map.Entry ent : subScorers.entrySet()) { - Scorer value = ent.getValue(); - int matchId = value.docID(); - freqs.put(ent.getKey(), matchId == doc ? value.score() : 0.0f); - } - docCounts.put(doc + docBase, freqs); - super.collect(doc); - } - - @Override - public void setScorer(Scorable scorer) throws IOException { - super.setScorer(scorer); - subScorers.clear(); - setSubScorers(scorer); - } - }; - } - } - - private static final float FLOAT_TOLERANCE = 0.00001F; - - @Test - public void testTermQuery() throws Exception { - TermQuery q = new TermQuery(new Term("f", "d")); - Map> docCounts = s.search(q, new CountingCollectorManager(null)); - final int maxDocs = s.getIndexReader().maxDoc(); - assertEquals(maxDocs, docCounts.size()); - for (int i = 0; i < maxDocs; i++) { - Map doc0 = docCounts.get(i); - assertEquals(1, doc0.size()); - assertEquals(4.0F, doc0.get(q), FLOAT_TOLERANCE); - - Map doc1 = docCounts.get(++i); - assertEquals(1, doc1.size()); - assertEquals(1.0F, doc1.get(q), FLOAT_TOLERANCE); - } - } - - @Test - public void testBooleanQuery() throws Exception { - TermQuery aQuery = new TermQuery(new Term("f", "a")); - TermQuery dQuery = new TermQuery(new Term("f", "d")); - TermQuery cQuery = new TermQuery(new Term("f", "c")); - TermQuery yQuery = new TermQuery(new Term("f", "y")); - - BooleanQuery.Builder query = new BooleanQuery.Builder(); - BooleanQuery.Builder inner = new BooleanQuery.Builder(); - - inner.add(cQuery, Occur.SHOULD); - inner.add(yQuery, Occur.MUST_NOT); - query.add(inner.build(), Occur.MUST); - query.add(aQuery, Occur.MUST); - query.add(dQuery, Occur.MUST); - - // Only needed in Java6; Java7+ has a @SafeVarargs annotated Arrays#asList()! - // see http://docs.oracle.com/javase/7/docs/api/java/lang/SafeVarargs.html - @SuppressWarnings("unchecked") - final Iterable> occurList = - Arrays.asList( - Collections.singleton("MUST"), new HashSet<>(Arrays.asList("MUST", "SHOULD"))); - - for (final Set occur : occurList) { - Map> docCounts = - s.search( - new DisablingBulkScorerQuery(query.build()), new CountingCollectorManager(occur)); - final int maxDocs = s.getIndexReader().maxDoc(); - assertEquals(maxDocs, docCounts.size()); - boolean includeOptional = occur.contains("SHOULD"); - for (int i = 0; i < maxDocs; i++) { - Map doc0 = docCounts.get(i); - // Y doesnt exist in the index, so it's not in the scorer tree - assertEquals(4, doc0.size()); - assertEquals(1.0F, doc0.get(aQuery), FLOAT_TOLERANCE); - assertEquals(4.0F, doc0.get(dQuery), FLOAT_TOLERANCE); - if (includeOptional) { - assertEquals(3.0F, doc0.get(cQuery), FLOAT_TOLERANCE); - } - - Map doc1 = docCounts.get(++i); - // Y doesnt exist in the index, so it's not in the scorer tree - assertEquals(4, doc1.size()); - assertEquals(1.0F, doc1.get(aQuery), FLOAT_TOLERANCE); - assertEquals(1.0F, doc1.get(dQuery), FLOAT_TOLERANCE); - if (includeOptional) { - assertEquals(1.0F, doc1.get(cQuery), FLOAT_TOLERANCE); - } - } - } - } - - @Test - public void testPhraseQuery() throws Exception { - PhraseQuery q = new PhraseQuery("f", "b", "c"); - Map> docCounts = s.search(q, new CountingCollectorManager(null)); - final int maxDocs = s.getIndexReader().maxDoc(); - assertEquals(maxDocs, docCounts.size()); - for (int i = 0; i < maxDocs; i++) { - Map doc0 = docCounts.get(i); - assertEquals(1, doc0.size()); - assertEquals(2.0F, doc0.get(q), FLOAT_TOLERANCE); - - Map doc1 = docCounts.get(++i); - assertEquals(1, doc1.size()); - assertEquals(1.0F, doc1.get(q), FLOAT_TOLERANCE); - } - } - - // Similarity that just returns the frequency as the score - private static class CountingSimilarity extends Similarity { - - @Override - public long computeNorm(FieldInvertState state) { - return 1; - } - - @Override - public SimScorer scorer( - float boost, CollectionStatistics collectionStats, TermStatistics... termStats) { - return new SimScorer() { - @Override - public float score(float freq, long norm) { - return freq; - } - }; - } - } -} diff --git a/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java index f2d9d1aef4c1..21e8866331e1 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java @@ -171,7 +171,7 @@ public Explanation explain(LeafReaderContext context, int doc) throws IOExceptio Explanation payloadExpl = scorer.getPayloadExplanation(); if (includeSpanScore) { - SpanWeight innerWeight = ((PayloadSpanWeight) scorer.getWeight()).innerWeight; + SpanWeight innerWeight = this.innerWeight; Explanation innerExpl = innerWeight.explain(context, doc); return Explanation.match( scorer.scoreCurrentDoc(), "PayloadSpanQuery, product of:", innerExpl, payloadExpl); diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerScorer.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerScorer.java index d99b5716827c..1abb4968a216 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerScorer.java +++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerScorer.java @@ -22,7 +22,6 @@ import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.TwoPhaseIterator; -import org.apache.lucene.search.Weight; /** * {@link Scorer} wrapper that will compute how much time is spent on moving the iterator, @@ -31,8 +30,6 @@ class QueryProfilerScorer extends Scorer { private final Scorer scorer; - private final QueryProfilerWeight profileWeight; - private final QueryProfilerTimer scoreTimer, nextDocTimer, advanceTimer, @@ -44,7 +41,6 @@ class QueryProfilerScorer extends Scorer { QueryProfilerScorer(QueryProfilerWeight w, Scorer scorer, QueryProfilerBreakdown profile) { super(w); this.scorer = scorer; - this.profileWeight = w; scoreTimer = profile.getTimer(QueryProfilerTimingType.SCORE); nextDocTimer = profile.getTimer(QueryProfilerTimingType.NEXT_DOC); advanceTimer = profile.getTimer(QueryProfilerTimingType.ADVANCE); @@ -70,11 +66,6 @@ public float score() throws IOException { } } - @Override - public Weight getWeight() { - return profileWeight; - } - @Override public Collection getChildren() throws IOException { return scorer.getChildren(); diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingScorer.java b/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingScorer.java index a68ca05400ab..fce7de3e02cb 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingScorer.java +++ b/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingScorer.java @@ -24,6 +24,7 @@ import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.TwoPhaseIterator; +import org.apache.lucene.search.Weight; /** Wraps a Scorer with additional checks */ public class AssertingScorer extends Scorer { @@ -36,11 +37,15 @@ enum IteratorState { }; public static Scorer wrap( - Random random, Scorer other, ScoreMode scoreMode, boolean canCallMinCompetitiveScore) { + Weight weight, + Random random, + Scorer other, + ScoreMode scoreMode, + boolean canCallMinCompetitiveScore) { if (other == null) { return null; } - return new AssertingScorer(random, other, scoreMode, canCallMinCompetitiveScore); + return new AssertingScorer(weight, random, other, scoreMode, canCallMinCompetitiveScore); } final Random random; @@ -54,8 +59,12 @@ public static Scorer wrap( int lastShallowTarget = -1; private AssertingScorer( - Random random, Scorer in, ScoreMode scoreMode, boolean canCallMinCompetitiveScore) { - super(in.getWeight()); + Weight weight, + Random random, + Scorer in, + ScoreMode scoreMode, + boolean canCallMinCompetitiveScore) { + super(weight); this.random = random; this.in = in; this.scoreMode = scoreMode; diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingWeight.java b/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingWeight.java index c25296b9a53f..68ec5fa3c27c 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingWeight.java +++ b/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingWeight.java @@ -72,6 +72,7 @@ public Scorer get(long leadCost) throws IOException { getCalled = true; assert leadCost >= 0 : leadCost; return AssertingScorer.wrap( + in, new Random(random.nextLong()), inScorerSupplier.get(leadCost), scoreMode, diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/search/RandomApproximationQuery.java b/lucene/test-framework/src/java/org/apache/lucene/tests/search/RandomApproximationQuery.java index 73adcb5e95e2..0ffe4c6f985f 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/tests/search/RandomApproximationQuery.java +++ b/lucene/test-framework/src/java/org/apache/lucene/tests/search/RandomApproximationQuery.java @@ -95,7 +95,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti return null; } else { final var subScorer = scorerSupplier.get(Long.MAX_VALUE); - scorer = new RandomApproximationScorer(subScorer, new Random(random.nextLong())); + scorer = new RandomApproximationScorer(in, subScorer, new Random(random.nextLong())); } return new DefaultScorerSupplier(scorer); } @@ -106,8 +106,8 @@ private static class RandomApproximationScorer extends Scorer { private final Scorer scorer; private final RandomTwoPhaseView twoPhaseView; - RandomApproximationScorer(Scorer scorer, Random random) { - super(scorer.getWeight()); + RandomApproximationScorer(Weight weight, Scorer scorer, Random random) { + super(weight); this.scorer = scorer; this.twoPhaseView = new RandomTwoPhaseView(random, scorer.iterator()); } diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/search/ScorerIndexSearcher.java b/lucene/test-framework/src/java/org/apache/lucene/tests/search/ScorerIndexSearcher.java index d3a414bc9883..139c7a421c9b 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/tests/search/ScorerIndexSearcher.java +++ b/lucene/test-framework/src/java/org/apache/lucene/tests/search/ScorerIndexSearcher.java @@ -55,6 +55,7 @@ public ScorerIndexSearcher(IndexReader r) { @Override protected void search(List leaves, Weight weight, Collector collector) throws IOException { + collector.setWeight(weight); for (LeafReaderContext ctx : leaves) { // search each subreader // we force the use of Scorer (not BulkScorer) to make sure // that the scorer passed to LeafCollector.setScorer supports From 47d71278b6915899c9ba73c9cf50b39c4dc7e20a Mon Sep 17 00:00:00 2001 From: iamsanjay Date: Fri, 31 May 2024 12:27:06 +0530 Subject: [PATCH 2/5] Removed weight from Scorer and all the subclasses of it --- .../document/BaseShapeDocValuesQuery.java | 2 +- .../document/BinaryRangeFieldRangeQuery.java | 2 +- .../document/LatLonDocValuesBoxQuery.java | 2 +- .../lucene/document/LatLonDocValuesQuery.java | 2 +- .../LatLonPointDistanceFeatureQuery.java | 6 +- .../document/LatLonPointDistanceQuery.java | 5 +- .../document/LongDistanceFeatureQuery.java | 6 +- .../lucene/document/RangeFieldQuery.java | 5 +- .../SortedNumericDocValuesRangeQuery.java | 2 +- .../SortedNumericDocValuesSetQuery.java | 2 +- .../SortedSetDocValuesRangeQuery.java | 5 +- .../apache/lucene/document/SpatialQuery.java | 13 ++-- .../XYDocValuesPointInGeometryQuery.java | 2 +- .../document/XYPointInGeometryQuery.java | 3 +- .../lucene/search/AbstractKnnVectorQuery.java | 2 +- ...actMultiTermQueryConstantScoreWrapper.java | 12 ++-- .../search/AbstractVectorSimilarityQuery.java | 7 +-- .../search/BlockMaxConjunctionScorer.java | 3 +- .../lucene/search/BooleanScorerSupplier.java | 24 ++++---- .../lucene/search/ConjunctionScorer.java | 3 +- .../lucene/search/ConstantScoreQuery.java | 5 +- .../lucene/search/ConstantScoreScorer.java | 10 +--- .../lucene/search/DisjunctionMaxQuery.java | 3 +- .../lucene/search/DisjunctionMaxScorer.java | 6 +- .../lucene/search/DisjunctionScorer.java | 4 +- .../lucene/search/DisjunctionSumScorer.java | 6 +- .../lucene/search/DocValuesRewriteMethod.java | 9 +-- .../lucene/search/FieldExistsQuery.java | 2 +- .../apache/lucene/search/FilterScorer.java | 14 +---- ...xSortSortedNumericDocValuesRangeQuery.java | 3 +- .../apache/lucene/search/IndriAndScorer.java | 4 +- .../apache/lucene/search/IndriAndWeight.java | 2 +- .../lucene/search/IndriDisjunctionScorer.java | 5 +- .../org/apache/lucene/search/IndriScorer.java | 3 +- .../apache/lucene/search/LRUQueryCache.java | 6 +- .../lucene/search/MatchAllDocsQuery.java | 3 +- ...iTermQueryConstantScoreBlendedWrapper.java | 2 +- .../apache/lucene/search/PhraseScorer.java | 8 +-- .../apache/lucene/search/PhraseWeight.java | 2 +- .../apache/lucene/search/PointInSetQuery.java | 5 +- .../apache/lucene/search/PointRangeQuery.java | 7 +-- .../apache/lucene/search/ReqExclScorer.java | 1 - .../apache/lucene/search/ReqOptSumScorer.java | 1 - .../java/org/apache/lucene/search/Scorer.java | 14 +---- .../apache/lucene/search/SynonymQuery.java | 10 ++-- .../org/apache/lucene/search/TermQuery.java | 1 - .../org/apache/lucene/search/TermScorer.java | 10 +--- .../org/apache/lucene/search/WANDScorer.java | 3 +- .../search/BaseKnnVectorQueryTestCase.java | 2 +- .../lucene/search/JustCompileSearch.java | 4 +- .../search/TestBoolean2ScorerSupplier.java | 1 - .../lucene/search/TestConjunctionDISI.java | 60 ++++--------------- .../search/TestConstantScoreScorer.java | 4 +- .../lucene/search/TestDisiPriorityQueue.java | 2 +- ...sjunctionScoreBlockBoundaryPropagator.java | 25 -------- .../lucene/search/TestLRUQueryCache.java | 6 +- .../lucene/search/TestMaxScoreBulkScorer.java | 33 ---------- .../lucene/search/TestMinShouldMatch2.java | 3 +- .../TestPositiveScoresOnlyCollector.java | 10 +--- .../lucene/search/TestQueryRescorer.java | 2 +- .../TestScoreCachingWrappingScorer.java | 10 +--- .../apache/lucene/search/TestScorerPerf.java | 5 +- .../apache/lucene/search/TestSortRandom.java | 5 +- .../TestUsageTrackingFilterCachingPolicy.java | 3 +- .../apache/lucene/search/TestWANDScorer.java | 3 +- .../lucene/facet/DrillSidewaysQuery.java | 3 +- .../lucene/facet/range/DoubleRange.java | 4 +- .../apache/lucene/facet/range/LongRange.java | 4 +- .../lucene/facet/TestDrillSideways.java | 1 - .../search/join/BaseGlobalOrdinalScorer.java | 4 +- .../search/join/GlobalOrdinalsQuery.java | 10 +--- .../join/GlobalOrdinalsWithScoreQuery.java | 11 +--- .../join/ParentChildrenBlockJoinQuery.java | 2 +- .../join/PointInSetIncludingScoreQuery.java | 2 +- .../search/join/TermsIncludingScoreQuery.java | 15 ++--- .../search/join/ToChildBlockJoinQuery.java | 6 +- .../search/join/ToParentBlockJoinQuery.java | 7 +-- .../lucene/search/join/TestJoinUtil.java | 2 +- .../TestDiversifiedTopDocsCollector.java | 2 +- .../queries/function/FunctionMatchQuery.java | 2 +- .../queries/function/FunctionQuery.java | 1 - .../queries/function/FunctionRangeQuery.java | 5 +- .../queries/function/FunctionValues.java | 14 ++--- .../queries/function/ValueSourceScorer.java | 5 +- .../docvalues/DocTermsIndexDocValues.java | 4 +- .../function/docvalues/DoubleDocValues.java | 10 ++-- .../function/docvalues/IntDocValues.java | 4 +- .../function/docvalues/LongDocValues.java | 4 +- .../function/valuesource/EnumFieldSource.java | 4 +- .../queries/intervals/IntervalQuery.java | 2 +- .../queries/intervals/IntervalScorer.java | 8 +-- .../queries/payloads/PayloadScoreQuery.java | 7 +-- .../payloads/SpanPayloadCheckQuery.java | 2 +- .../queries/spans/SpanContainingQuery.java | 3 +- .../lucene/queries/spans/SpanNearQuery.java | 3 +- .../lucene/queries/spans/SpanScorer.java | 3 +- .../lucene/queries/spans/SpanWeight.java | 2 +- .../function/TestSortedSetFieldSource.java | 11 +--- .../sandbox/search/CombinedFieldQuery.java | 11 +--- .../lucene/sandbox/search/CoveringQuery.java | 5 +- .../lucene/sandbox/search/CoveringScorer.java | 5 +- .../sandbox/search/MultiRangeQuery.java | 5 +- .../sandbox/search/QueryProfilerScorer.java | 3 +- .../sandbox/search/QueryProfilerWeight.java | 4 +- .../sandbox/search/TermAutomatonScorer.java | 6 -- .../search/TestQueryProfilerScorer.java | 28 ++------- .../search/TestQueryProfilerWeight.java | 3 +- .../search/TestTermAutomatonQuery.java | 5 +- .../composite/CompositeVerifyQuery.java | 2 +- .../composite/IntersectsRPTVerifyQuery.java | 4 +- .../prefix/AbstractPrefixTreeQuery.java | 2 +- .../serialized/SerializedDVStrategy.java | 2 +- .../spatial/vector/PointVectorStrategy.java | 2 +- .../spatial3d/PointInGeo3DShapeQuery.java | 3 +- .../lucene/tests/search/AssertingScorer.java | 16 +---- .../lucene/tests/search/AssertingWeight.java | 1 - .../tests/search/BlockScoreQueryWrapper.java | 2 +- .../tests/search/BulkScorerWrapperScorer.java | 4 +- .../search/RandomApproximationQuery.java | 5 +- 119 files changed, 193 insertions(+), 527 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/document/BaseShapeDocValuesQuery.java b/lucene/core/src/java/org/apache/lucene/document/BaseShapeDocValuesQuery.java index 7f1c4c1c1a2d..03cbb3b2007e 100644 --- a/lucene/core/src/java/org/apache/lucene/document/BaseShapeDocValuesQuery.java +++ b/lucene/core/src/java/org/apache/lucene/document/BaseShapeDocValuesQuery.java @@ -89,7 +89,7 @@ public float matchCost() { @Override public Scorer get(long leadCost) { - return new ConstantScoreScorer(weight, boost, scoreMode, iterator); + return new ConstantScoreScorer(boost, scoreMode, iterator); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/document/BinaryRangeFieldRangeQuery.java b/lucene/core/src/java/org/apache/lucene/document/BinaryRangeFieldRangeQuery.java index c66281498be8..140227746f0d 100644 --- a/lucene/core/src/java/org/apache/lucene/document/BinaryRangeFieldRangeQuery.java +++ b/lucene/core/src/java/org/apache/lucene/document/BinaryRangeFieldRangeQuery.java @@ -135,7 +135,7 @@ public float matchCost() { } }; - final var scorer = new ConstantScoreScorer(this, score(), scoreMode, iterator); + final var scorer = new ConstantScoreScorer(score(), scoreMode, iterator); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/core/src/java/org/apache/lucene/document/LatLonDocValuesBoxQuery.java b/lucene/core/src/java/org/apache/lucene/document/LatLonDocValuesBoxQuery.java index feed4a85f571..ac01e4c74f33 100644 --- a/lucene/core/src/java/org/apache/lucene/document/LatLonDocValuesBoxQuery.java +++ b/lucene/core/src/java/org/apache/lucene/document/LatLonDocValuesBoxQuery.java @@ -153,7 +153,7 @@ public float matchCost() { return 5; // 5 comparisons } }; - final var scorer = new ConstantScoreScorer(this, boost, scoreMode, iterator); + final var scorer = new ConstantScoreScorer(boost, scoreMode, iterator); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/core/src/java/org/apache/lucene/document/LatLonDocValuesQuery.java b/lucene/core/src/java/org/apache/lucene/document/LatLonDocValuesQuery.java index 86dc574191f6..45a7bc0eb521 100644 --- a/lucene/core/src/java/org/apache/lucene/document/LatLonDocValuesQuery.java +++ b/lucene/core/src/java/org/apache/lucene/document/LatLonDocValuesQuery.java @@ -158,7 +158,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti throw new IllegalArgumentException( "Invalid query relationship:[" + queryRelation + "]"); } - final var scorer = new ConstantScoreScorer(this, boost, scoreMode, iterator); + final var scorer = new ConstantScoreScorer(boost, scoreMode, iterator); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceFeatureQuery.java b/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceFeatureQuery.java index b10eab2cda10..df296c15ab51 100644 --- a/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceFeatureQuery.java +++ b/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceFeatureQuery.java @@ -215,14 +215,12 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti final SortedNumericDocValues multiDocValues = DocValues.getSortedNumeric(context.reader(), field); final NumericDocValues docValues = selectValues(multiDocValues); - - final Weight weight = this; return new ScorerSupplier() { @Override public Scorer get(long leadCost) throws IOException { return new DistanceScorer( - weight, context.reader().maxDoc(), leadCost, boost, pointValues, docValues); + context.reader().maxDoc(), leadCost, boost, pointValues, docValues); } @Override @@ -258,13 +256,11 @@ private class DistanceScorer extends Scorer { private double maxDistance = GeoUtils.EARTH_MEAN_RADIUS_METERS * Math.PI; protected DistanceScorer( - Weight weight, int maxDoc, long leadCost, float boost, PointValues pointValues, NumericDocValues docValues) { - super(weight); this.maxDoc = maxDoc; this.leadCost = leadCost; this.boost = boost; diff --git a/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java b/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java index 34f3d16750e1..7f5f8cf6290c 100644 --- a/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java +++ b/lucene/core/src/java/org/apache/lucene/document/LatLonPointDistanceQuery.java @@ -137,7 +137,6 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti DocIdSetBuilder result = new DocIdSetBuilder(reader.maxDoc(), values, field); final IntersectVisitor visitor = getIntersectVisitor(result); - final Weight weight = this; return new ScorerSupplier() { long cost = -1; @@ -155,10 +154,10 @@ && cost() > reader.maxDoc() / 2) { long[] cost = new long[] {reader.maxDoc()}; values.intersect(getInverseIntersectVisitor(result, cost)); final DocIdSetIterator iterator = new BitSetIterator(result, cost[0]); - return new ConstantScoreScorer(weight, score(), scoreMode, iterator); + return new ConstantScoreScorer(score(), scoreMode, iterator); } values.intersect(visitor); - return new ConstantScoreScorer(weight, score(), scoreMode, result.build().iterator()); + return new ConstantScoreScorer(score(), scoreMode, result.build().iterator()); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/document/LongDistanceFeatureQuery.java b/lucene/core/src/java/org/apache/lucene/document/LongDistanceFeatureQuery.java index 58cb747bf7f5..c675136ca80d 100644 --- a/lucene/core/src/java/org/apache/lucene/document/LongDistanceFeatureQuery.java +++ b/lucene/core/src/java/org/apache/lucene/document/LongDistanceFeatureQuery.java @@ -205,14 +205,12 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti final SortedNumericDocValues multiDocValues = DocValues.getSortedNumeric(context.reader(), field); final NumericDocValues docValues = selectValues(multiDocValues); - - final Weight weight = this; return new ScorerSupplier() { @Override public Scorer get(long leadCost) throws IOException { return new DistanceScorer( - weight, context.reader().maxDoc(), leadCost, boost, pointValues, docValues); + context.reader().maxDoc(), leadCost, boost, pointValues, docValues); } @Override @@ -236,13 +234,11 @@ private class DistanceScorer extends Scorer { private long maxDistance = Long.MAX_VALUE; protected DistanceScorer( - Weight weight, int maxDoc, long leadCost, float boost, PointValues pointValues, NumericDocValues docValues) { - super(weight); this.maxDoc = maxDoc; this.leadCost = leadCost; this.boost = boost; diff --git a/lucene/core/src/java/org/apache/lucene/document/RangeFieldQuery.java b/lucene/core/src/java/org/apache/lucene/document/RangeFieldQuery.java index 00b96b960d29..f5747c0f8bde 100644 --- a/lucene/core/src/java/org/apache/lucene/document/RangeFieldQuery.java +++ b/lucene/core/src/java/org/apache/lucene/document/RangeFieldQuery.java @@ -459,13 +459,12 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti allDocsMatch = true; } - final Weight weight = this; if (allDocsMatch) { return new ScorerSupplier() { @Override public Scorer get(long leadCost) { return new ConstantScoreScorer( - weight, score(), scoreMode, DocIdSetIterator.all(reader.maxDoc())); + score(), scoreMode, DocIdSetIterator.all(reader.maxDoc())); } @Override @@ -484,7 +483,7 @@ public long cost() { public Scorer get(long leadCost) throws IOException { values.intersect(visitor); DocIdSetIterator iterator = result.build().iterator(); - return new ConstantScoreScorer(weight, score(), scoreMode, iterator); + return new ConstantScoreScorer(score(), scoreMode, iterator); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/document/SortedNumericDocValuesRangeQuery.java b/lucene/core/src/java/org/apache/lucene/document/SortedNumericDocValuesRangeQuery.java index 932327716982..32a5672186e5 100644 --- a/lucene/core/src/java/org/apache/lucene/document/SortedNumericDocValuesRangeQuery.java +++ b/lucene/core/src/java/org/apache/lucene/document/SortedNumericDocValuesRangeQuery.java @@ -145,7 +145,7 @@ public float matchCost() { } }; } - final var scorer = new ConstantScoreScorer(this, score(), scoreMode, iterator); + final var scorer = new ConstantScoreScorer(score(), scoreMode, iterator); return new DefaultScorerSupplier(scorer); } }; diff --git a/lucene/core/src/java/org/apache/lucene/document/SortedNumericDocValuesSetQuery.java b/lucene/core/src/java/org/apache/lucene/document/SortedNumericDocValuesSetQuery.java index b5596a672211..192a751b43e4 100644 --- a/lucene/core/src/java/org/apache/lucene/document/SortedNumericDocValuesSetQuery.java +++ b/lucene/core/src/java/org/apache/lucene/document/SortedNumericDocValuesSetQuery.java @@ -150,7 +150,7 @@ public float matchCost() { } }; } - final var scorer = new ConstantScoreScorer(this, score(), scoreMode, iterator); + final var scorer = new ConstantScoreScorer(score(), scoreMode, iterator); return new DefaultScorerSupplier(scorer); } }; diff --git a/lucene/core/src/java/org/apache/lucene/document/SortedSetDocValuesRangeQuery.java b/lucene/core/src/java/org/apache/lucene/document/SortedSetDocValuesRangeQuery.java index 03cea17b3b9e..0c9959b87566 100644 --- a/lucene/core/src/java/org/apache/lucene/document/SortedSetDocValuesRangeQuery.java +++ b/lucene/core/src/java/org/apache/lucene/document/SortedSetDocValuesRangeQuery.java @@ -110,7 +110,6 @@ public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float bo return new ConstantScoreWeight(this, boost) { @Override public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { - final Weight weight = this; if (context.reader().getFieldInfos().fieldInfo(field) == null) { return null; } @@ -151,7 +150,7 @@ public Scorer get(long leadCost) throws IOException { // no terms matched in this segment if (minOrd > maxOrd) { - return new ConstantScoreScorer(weight, score(), scoreMode, DocIdSetIterator.empty()); + return new ConstantScoreScorer(score(), scoreMode, DocIdSetIterator.empty()); } final SortedDocValues singleton = DocValues.unwrapSingleton(values); @@ -193,7 +192,7 @@ public float matchCost() { } }; } - return new ConstantScoreScorer(weight, score(), scoreMode, iterator); + return new ConstantScoreScorer(score(), scoreMode, iterator); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java b/lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java index 836ca974bc5c..57e93a62e6f5 100644 --- a/lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java +++ b/lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java @@ -178,8 +178,7 @@ protected ScorerSupplier getScorerSupplier( return new ScorerSupplier() { @Override public Scorer get(long leadCost) { - return new ConstantScoreScorer( - weight, score, scoreMode, DocIdSetIterator.all(reader.maxDoc())); + return new ConstantScoreScorer(score, scoreMode, DocIdSetIterator.all(reader.maxDoc())); } @Override @@ -324,7 +323,7 @@ && cost() > reader.maxDoc() / 2) { final long[] cost = new long[] {reader.maxDoc()}; values.intersect(getInverseDenseVisitor(spatialVisitor, queryRelation, result, cost)); final DocIdSetIterator iterator = new BitSetIterator(result, cost[0]); - return new ConstantScoreScorer(weight, boost, scoreMode, iterator); + return new ConstantScoreScorer(boost, scoreMode, iterator); } else if (values.getDocCount() < (values.size() >>> 2)) { // we use a dense structure so we can skip already visited documents final FixedBitSet result = new FixedBitSet(reader.maxDoc()); @@ -333,12 +332,12 @@ && cost() > reader.maxDoc() / 2) { assert cost[0] > 0 || result.cardinality() == 0; final DocIdSetIterator iterator = cost[0] == 0 ? DocIdSetIterator.empty() : new BitSetIterator(result, cost[0]); - return new ConstantScoreScorer(weight, boost, scoreMode, iterator); + return new ConstantScoreScorer(boost, scoreMode, iterator); } else { final DocIdSetBuilder docIdSetBuilder = new DocIdSetBuilder(reader.maxDoc(), values, field); values.intersect(getSparseVisitor(spatialVisitor, queryRelation, docIdSetBuilder)); final DocIdSetIterator iterator = docIdSetBuilder.build().iterator(); - return new ConstantScoreScorer(weight, boost, scoreMode, iterator); + return new ConstantScoreScorer(boost, scoreMode, iterator); } } @@ -369,7 +368,7 @@ private Scorer getDenseScorer( assert cost[0] > 0 || result.cardinality() == 0; final DocIdSetIterator iterator = cost[0] == 0 ? DocIdSetIterator.empty() : new BitSetIterator(result, cost[0]); - return new ConstantScoreScorer(weight, boost, scoreMode, iterator); + return new ConstantScoreScorer(boost, scoreMode, iterator); } private Scorer getContainsDenseScorer( @@ -385,7 +384,7 @@ private Scorer getContainsDenseScorer( assert cost[0] > 0 || result.cardinality() == 0; final DocIdSetIterator iterator = cost[0] == 0 ? DocIdSetIterator.empty() : new BitSetIterator(result, cost[0]); - return new ConstantScoreScorer(weight, boost, scoreMode, iterator); + return new ConstantScoreScorer(boost, scoreMode, iterator); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/document/XYDocValuesPointInGeometryQuery.java b/lucene/core/src/java/org/apache/lucene/document/XYDocValuesPointInGeometryQuery.java index be297a142d6b..132a3a36308d 100644 --- a/lucene/core/src/java/org/apache/lucene/document/XYDocValuesPointInGeometryQuery.java +++ b/lucene/core/src/java/org/apache/lucene/document/XYDocValuesPointInGeometryQuery.java @@ -130,7 +130,7 @@ public float matchCost() { return 1000f; // TODO: what should it be? } }; - final var scorer = new ConstantScoreScorer(this, boost, scoreMode, iterator); + final var scorer = new ConstantScoreScorer(boost, scoreMode, iterator); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/core/src/java/org/apache/lucene/document/XYPointInGeometryQuery.java b/lucene/core/src/java/org/apache/lucene/document/XYPointInGeometryQuery.java index 107ecd0ffd98..47b6abb46c22 100644 --- a/lucene/core/src/java/org/apache/lucene/document/XYPointInGeometryQuery.java +++ b/lucene/core/src/java/org/apache/lucene/document/XYPointInGeometryQuery.java @@ -141,7 +141,6 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti return null; } XYPointField.checkCompatible(fieldInfo); - final Weight weight = this; return new ScorerSupplier() { @@ -152,7 +151,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti @Override public Scorer get(long leadCost) throws IOException { values.intersect(visitor); - return new ConstantScoreScorer(weight, score(), scoreMode, result.build().iterator()); + return new ConstantScoreScorer(score(), scoreMode, result.build().iterator()); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/AbstractKnnVectorQuery.java b/lucene/core/src/java/org/apache/lucene/search/AbstractKnnVectorQuery.java index 32dc09c3a9f6..8fceb0cfec57 100644 --- a/lucene/core/src/java/org/apache/lucene/search/AbstractKnnVectorQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/AbstractKnnVectorQuery.java @@ -388,7 +388,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti return null; } final var scorer = - new Scorer(this) { + new Scorer() { final int lower = segmentStarts[context.ord]; final int upper = segmentStarts[context.ord + 1]; int upTo = -1; diff --git a/lucene/core/src/java/org/apache/lucene/search/AbstractMultiTermQueryConstantScoreWrapper.java b/lucene/core/src/java/org/apache/lucene/search/AbstractMultiTermQueryConstantScoreWrapper.java index 1a9b18f0f39e..cfd0f48147ca 100644 --- a/lucene/core/src/java/org/apache/lucene/search/AbstractMultiTermQueryConstantScoreWrapper.java +++ b/lucene/core/src/java/org/apache/lucene/search/AbstractMultiTermQueryConstantScoreWrapper.java @@ -208,7 +208,7 @@ private Scorer scorerForIterator(DocIdSetIterator iterator) { if (iterator == null) { return null; } - return new ConstantScoreScorer(this, score(), scoreMode, iterator); + return new ConstantScoreScorer(score(), scoreMode, iterator); } @Override @@ -232,8 +232,6 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti } final long cost = estimateCost(terms, q.getTermsCount()); - - final Weight weight = this; return new ScorerSupplier() { @Override public Scorer get(long leadCost) throws IOException { @@ -252,8 +250,7 @@ public Scorer get(long leadCost) throws IOException { // find that there are actually no hits, we need to return an empty Scorer as opposed // to null: return Objects.requireNonNullElseGet( - scorer, - () -> new ConstantScoreScorer(weight, score(), scoreMode, DocIdSetIterator.empty())); + scorer, () -> new ConstantScoreScorer(score(), scoreMode, DocIdSetIterator.empty())); } @Override @@ -267,7 +264,7 @@ public BulkScorer bulkScorer() throws IOException { } else { bulkScorer = new DefaultBulkScorer( - new ConstantScoreScorer(weight, score(), scoreMode, weightOrIterator.iterator)); + new ConstantScoreScorer(score(), scoreMode, weightOrIterator.iterator)); } // It's against the API contract to return a null scorer from a non-null ScoreSupplier. @@ -278,8 +275,7 @@ public BulkScorer bulkScorer() throws IOException { bulkScorer, () -> new DefaultBulkScorer( - new ConstantScoreScorer( - weight, score(), scoreMode, DocIdSetIterator.empty()))); + new ConstantScoreScorer(score(), scoreMode, DocIdSetIterator.empty()))); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/AbstractVectorSimilarityQuery.java b/lucene/core/src/java/org/apache/lucene/search/AbstractVectorSimilarityQuery.java index c55ea308e76e..77a5ff6f24f0 100644 --- a/lucene/core/src/java/org/apache/lucene/search/AbstractVectorSimilarityQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/AbstractVectorSimilarityQuery.java @@ -201,8 +201,7 @@ private static class VectorSimilarityScorer extends Scorer { final DocIdSetIterator iterator; final float[] cachedScore; - VectorSimilarityScorer(Weight weight, DocIdSetIterator iterator, float[] cachedScore) { - super(weight); + VectorSimilarityScorer(DocIdSetIterator iterator, float[] cachedScore) { this.iterator = iterator; this.cachedScore = cachedScore; } @@ -253,7 +252,7 @@ public long cost() { } }; - return new VectorSimilarityScorer(weight, iterator, cachedScore); + return new VectorSimilarityScorer(iterator, cachedScore); } static VectorSimilarityScorer fromAcceptDocs( @@ -282,7 +281,7 @@ protected boolean match(int doc) throws IOException { } }; - return new VectorSimilarityScorer(weight, iterator, cachedScore); + return new VectorSimilarityScorer(iterator, cachedScore); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionScorer.java b/lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionScorer.java index 47ef5e07f19b..76788185faa1 100644 --- a/lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/BlockMaxConjunctionScorer.java @@ -34,8 +34,7 @@ final class BlockMaxConjunctionScorer extends Scorer { float minScore; /** Create a new {@link BlockMaxConjunctionScorer} from scoring clauses. */ - BlockMaxConjunctionScorer(Weight weight, Collection scorersList) throws IOException { - super(weight); + BlockMaxConjunctionScorer(Collection scorersList) throws IOException { this.scorers = scorersList.toArray(new Scorer[scorersList.size()]); // Sort scorer by cost Arrays.sort(this.scorers, Comparator.comparingLong(s -> s.iterator().cost())); diff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanScorerSupplier.java b/lucene/core/src/java/org/apache/lucene/search/BooleanScorerSupplier.java index 4f957aad4be7..b07d8ebb88e1 100644 --- a/lucene/core/src/java/org/apache/lucene/search/BooleanScorerSupplier.java +++ b/lucene/core/src/java/org/apache/lucene/search/BooleanScorerSupplier.java @@ -31,8 +31,6 @@ import org.apache.lucene.util.Bits; final class BooleanScorerSupplier extends ScorerSupplier { - - private final Weight weight; private final Map> subs; private final ScoreMode scoreMode; private final int minShouldMatch; @@ -65,7 +63,6 @@ final class BooleanScorerSupplier extends ScorerSupplier { == 0) { throw new IllegalArgumentException("There should be at least one positive clause"); } - this.weight = weight; this.subs = subs; this.scoreMode = scoreMode; this.minShouldMatch = minShouldMatch; @@ -121,8 +118,8 @@ public Scorer get(long leadCost) throws IOException { // no scoring clauses but scores are needed so we wrap the scorer in // a constant score in order to allow early termination return scorer.twoPhaseIterator() != null - ? new ConstantScoreScorer(weight, 0f, scoreMode, scorer.twoPhaseIterator()) - : new ConstantScoreScorer(weight, 0f, scoreMode, scorer.iterator()); + ? new ConstantScoreScorer(0f, scoreMode, scorer.twoPhaseIterator()) + : new ConstantScoreScorer(0f, scoreMode, scorer.iterator()); } return scorer; } @@ -159,7 +156,7 @@ private Scorer getInternal(long leadCost) throws IOException { subs.get(Occur.MUST_NOT), leadCost); Scorer opt = opt(subs.get(Occur.SHOULD), minShouldMatch, scoreMode, leadCost, false); - return new ConjunctionScorer(weight, Arrays.asList(req, opt), Arrays.asList(req, opt)); + return new ConjunctionScorer(Arrays.asList(req, opt), Arrays.asList(req, opt)); } else { assert scoreMode.needsScores(); return new ReqOptSumScorer( @@ -237,7 +234,7 @@ BulkScorer booleanScorer() throws IOException { Scorer prohibitedScorer = prohibited.size() == 1 ? prohibited.get(0) - : new DisjunctionSumScorer(weight, prohibited, ScoreMode.COMPLETE_NO_SCORES); + : new DisjunctionSumScorer(prohibited, ScoreMode.COMPLETE_NO_SCORES); return new ReqExclBulkScorer(positiveScorer, prohibitedScorer); } } @@ -349,8 +346,7 @@ private BulkScorer requiredBulkScorer() throws IOException { return new ConjunctionBulkScorer(requiredScoring, requiredNoScoring); } if (scoreMode == ScoreMode.TOP_SCORES && requiredScoring.size() > 1) { - requiredScoring = - Collections.singletonList(new BlockMaxConjunctionScorer(weight, requiredScoring)); + requiredScoring = Collections.singletonList(new BlockMaxConjunctionScorer(requiredScoring)); } Scorer conjunctionScorer; if (requiredNoScoring.size() + requiredScoring.size() == 1) { @@ -378,7 +374,7 @@ public float getMaxScore(int upTo) throws IOException { List required = new ArrayList<>(); required.addAll(requiredScoring); required.addAll(requiredNoScoring); - conjunctionScorer = new ConjunctionScorer(weight, required, requiredScoring); + conjunctionScorer = new ConjunctionScorer(required, requiredScoring); } return new DefaultBulkScorer(conjunctionScorer); } @@ -433,14 +429,14 @@ public float getMaxScore(int upTo) throws IOException { scoringScorers.add(scorer); } if (scoreMode == ScoreMode.TOP_SCORES && scoringScorers.size() > 1 && topLevelScoringClause) { - Scorer blockMaxScorer = new BlockMaxConjunctionScorer(weight, scoringScorers); + Scorer blockMaxScorer = new BlockMaxConjunctionScorer(scoringScorers); if (requiredScorers.isEmpty()) { return blockMaxScorer; } scoringScorers = Collections.singletonList(blockMaxScorer); } requiredScorers.addAll(scoringScorers); - return new ConjunctionScorer(weight, requiredScorers, scoringScorers); + return new ConjunctionScorer(requiredScorers, scoringScorers); } } @@ -477,9 +473,9 @@ private Scorer opt( // However, as WANDScorer uses more complex algorithm and data structure, we would like to // still use DisjunctionSumScorer to handle exhaustive pure disjunctions, which may be faster if ((scoreMode == ScoreMode.TOP_SCORES && topLevelScoringClause) || minShouldMatch > 1) { - return new WANDScorer(weight, optionalScorers, minShouldMatch, scoreMode); + return new WANDScorer(optionalScorers, minShouldMatch, scoreMode); } else { - return new DisjunctionSumScorer(weight, optionalScorers, scoreMode); + return new DisjunctionSumScorer(optionalScorers, scoreMode); } } } diff --git a/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java b/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java index 05634e5dcccd..e651c95d3b39 100644 --- a/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java @@ -31,8 +31,7 @@ class ConjunctionScorer extends Scorer { * Create a new {@link ConjunctionScorer}, note that {@code scorers} must be a subset of {@code * required}. */ - ConjunctionScorer(Weight weight, Collection required, Collection scorers) { - super(weight); + ConjunctionScorer(Collection required, Collection scorers) { assert required.containsAll(scorers); this.disi = ConjunctionUtils.intersectScorers(required); this.scorers = scorers.toArray(new Scorer[scorers.size()]); diff --git a/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java b/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java index 80c94a30079d..cb406389f373 100644 --- a/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java @@ -149,10 +149,9 @@ public Scorer get(long leadCost) throws IOException { final Scorer innerScorer = innerScorerSupplier.get(leadCost); final TwoPhaseIterator twoPhaseIterator = innerScorer.twoPhaseIterator(); if (twoPhaseIterator == null) { - return new ConstantScoreScorer( - innerWeight, score(), scoreMode, innerScorer.iterator()); + return new ConstantScoreScorer(score(), scoreMode, innerScorer.iterator()); } else { - return new ConstantScoreScorer(innerWeight, score(), scoreMode, twoPhaseIterator); + return new ConstantScoreScorer(score(), scoreMode, twoPhaseIterator); } } diff --git a/lucene/core/src/java/org/apache/lucene/search/ConstantScoreScorer.java b/lucene/core/src/java/org/apache/lucene/search/ConstantScoreScorer.java index d7a3a812a519..7407edaaf548 100644 --- a/lucene/core/src/java/org/apache/lucene/search/ConstantScoreScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/ConstantScoreScorer.java @@ -64,14 +64,11 @@ public long cost() { * Constructor based on a {@link DocIdSetIterator} which will be used to drive iteration. Two * phase iteration will not be supported. * - * @param weight the parent weight * @param score the score to return on each document * @param scoreMode the score mode * @param disi the iterator that defines matching documents */ - public ConstantScoreScorer( - Weight weight, float score, ScoreMode scoreMode, DocIdSetIterator disi) { - super(weight); + public ConstantScoreScorer(float score, ScoreMode scoreMode, DocIdSetIterator disi) { this.score = score; this.scoreMode = scoreMode; // TODO: Only wrap when it is the top-level scoring clause? See @@ -86,14 +83,11 @@ public ConstantScoreScorer( * Constructor based on a {@link TwoPhaseIterator}. In that case the {@link Scorer} will support * two-phase iteration. * - * @param weight the parent weight * @param score the score to return on each document * @param scoreMode the score mode * @param twoPhaseIterator the iterator that defines matching documents */ - public ConstantScoreScorer( - Weight weight, float score, ScoreMode scoreMode, TwoPhaseIterator twoPhaseIterator) { - super(weight); + public ConstantScoreScorer(float score, ScoreMode scoreMode, TwoPhaseIterator twoPhaseIterator) { this.score = score; this.scoreMode = scoreMode; if (scoreMode == ScoreMode.TOP_SCORES) { diff --git a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java index 903931459fdd..5a53749b6675 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java @@ -142,7 +142,6 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti } else if (scorerSuppliers.size() == 1) { return scorerSuppliers.get(0); } else { - final Weight thisWeight = this; return new ScorerSupplier() { private long cost = -1; @@ -153,7 +152,7 @@ public Scorer get(long leadCost) throws IOException { for (ScorerSupplier ss : scorerSuppliers) { scorers.add(ss.get(leadCost)); } - return new DisjunctionMaxScorer(thisWeight, tieBreakerMultiplier, scorers, scoreMode); + return new DisjunctionMaxScorer(tieBreakerMultiplier, scorers, scoreMode); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java index a43077a725e6..c12a131fc5ef 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java @@ -36,15 +36,13 @@ final class DisjunctionMaxScorer extends DisjunctionScorer { /** * Creates a new instance of DisjunctionMaxScorer * - * @param weight The Weight to be used. * @param tieBreakerMultiplier Multiplier applied to non-maximum-scoring subqueries for a document * as they are summed into the result. * @param subScorers The sub scorers this Scorer should iterate on */ - DisjunctionMaxScorer( - Weight weight, float tieBreakerMultiplier, List subScorers, ScoreMode scoreMode) + DisjunctionMaxScorer(float tieBreakerMultiplier, List subScorers, ScoreMode scoreMode) throws IOException { - super(weight, subScorers, scoreMode); + super(subScorers, scoreMode); this.subScorers = subScorers; this.tieBreakerMultiplier = tieBreakerMultiplier; if (tieBreakerMultiplier < 0 || tieBreakerMultiplier > 1) { diff --git a/lucene/core/src/java/org/apache/lucene/search/DisjunctionScorer.java b/lucene/core/src/java/org/apache/lucene/search/DisjunctionScorer.java index 74fb42f01b34..8b4da6ffed76 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionScorer.java @@ -31,9 +31,7 @@ abstract class DisjunctionScorer extends Scorer { private final DocIdSetIterator approximation; private final TwoPhase twoPhase; - protected DisjunctionScorer(Weight weight, List subScorers, ScoreMode scoreMode) - throws IOException { - super(weight); + protected DisjunctionScorer(List subScorers, ScoreMode scoreMode) throws IOException { if (subScorers.size() <= 1) { throw new IllegalArgumentException("There must be at least 2 subScorers"); } diff --git a/lucene/core/src/java/org/apache/lucene/search/DisjunctionSumScorer.java b/lucene/core/src/java/org/apache/lucene/search/DisjunctionSumScorer.java index 26fbd19bcd6a..3b5b98378c80 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionSumScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionSumScorer.java @@ -28,12 +28,10 @@ final class DisjunctionSumScorer extends DisjunctionScorer { /** * Construct a DisjunctionScorer. * - * @param weight The weight to be used. * @param subScorers Array of at least two subscorers. */ - DisjunctionSumScorer(Weight weight, List subScorers, ScoreMode scoreMode) - throws IOException { - super(weight, subScorers, scoreMode); + DisjunctionSumScorer(List subScorers, ScoreMode scoreMode) throws IOException { + super(subScorers, scoreMode); this.scorers = subScorers; } diff --git a/lucene/core/src/java/org/apache/lucene/search/DocValuesRewriteMethod.java b/lucene/core/src/java/org/apache/lucene/search/DocValuesRewriteMethod.java index 93e59435a9a3..ce179cf85d2e 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DocValuesRewriteMethod.java +++ b/lucene/core/src/java/org/apache/lucene/search/DocValuesRewriteMethod.java @@ -153,7 +153,6 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti return null; // no values/docs so nothing can match } - final Weight weight = this; return new ScorerSupplier() { @Override public Scorer get(long leadCost) throws IOException { @@ -164,8 +163,7 @@ public Scorer get(long leadCost) throws IOException { if (termsEnum.next() == null) { // no matching terms - return new ConstantScoreScorer( - weight, score(), scoreMode, DocIdSetIterator.empty()); + return new ConstantScoreScorer(score(), scoreMode, DocIdSetIterator.empty()); } // Create a bit set for the "term set" ordinals (these are the terms provided by the @@ -184,8 +182,7 @@ public Scorer get(long leadCost) throws IOException { // no terms matched in this segment if (maxOrd < 0) { - return new ConstantScoreScorer( - weight, score(), scoreMode, DocIdSetIterator.empty()); + return new ConstantScoreScorer(score(), scoreMode, DocIdSetIterator.empty()); } final SortedDocValues singleton = DocValues.unwrapSingleton(values); @@ -227,7 +224,7 @@ public float matchCost() { }; } - return new ConstantScoreScorer(weight, score(), scoreMode, iterator); + return new ConstantScoreScorer(score(), scoreMode, iterator); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/FieldExistsQuery.java b/lucene/core/src/java/org/apache/lucene/search/FieldExistsQuery.java index 74a44c00caa0..893caca4015d 100644 --- a/lucene/core/src/java/org/apache/lucene/search/FieldExistsQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/FieldExistsQuery.java @@ -217,7 +217,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti if (iterator == null) { return null; } - final var scorer = new ConstantScoreScorer(this, score(), scoreMode, iterator); + final var scorer = new ConstantScoreScorer(score(), scoreMode, iterator); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/core/src/java/org/apache/lucene/search/FilterScorer.java b/lucene/core/src/java/org/apache/lucene/search/FilterScorer.java index 337531dbb321..9ea6fad407e8 100644 --- a/lucene/core/src/java/org/apache/lucene/search/FilterScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/FilterScorer.java @@ -29,24 +29,12 @@ public abstract class FilterScorer extends Scorer implements Unwrappable { protected final Scorer in; - /** - * Create a new FilterScorer - * - * @param in the {@link Scorer} to wrap - */ - public FilterScorer(Scorer in) { - super(in.weight); - this.in = in; - } - /** * Create a new FilterScorer with a specific weight * * @param in the {@link Scorer} to wrap - * @param weight a {@link Weight} */ - public FilterScorer(Scorer in, Weight weight) { - super(weight); + public FilterScorer(Scorer in) { if (in == null) { throw new NullPointerException("wrapped Scorer must not be null"); } diff --git a/lucene/core/src/java/org/apache/lucene/search/IndexSortSortedNumericDocValuesRangeQuery.java b/lucene/core/src/java/org/apache/lucene/search/IndexSortSortedNumericDocValuesRangeQuery.java index aead6d9f9b8c..0c27e4de83ff 100644 --- a/lucene/core/src/java/org/apache/lucene/search/IndexSortSortedNumericDocValuesRangeQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/IndexSortSortedNumericDocValuesRangeQuery.java @@ -158,14 +158,13 @@ public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float bo @Override public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { - final Weight weight = this; IteratorAndCount itAndCount = getDocIdSetIteratorOrNull(context); if (itAndCount != null) { DocIdSetIterator disi = itAndCount.it; return new ScorerSupplier() { @Override public Scorer get(long leadCost) throws IOException { - return new ConstantScoreScorer(weight, score(), scoreMode, disi); + return new ConstantScoreScorer(score(), scoreMode, disi); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/IndriAndScorer.java b/lucene/core/src/java/org/apache/lucene/search/IndriAndScorer.java index 28c33db94a57..72cc2ff530a2 100644 --- a/lucene/core/src/java/org/apache/lucene/search/IndriAndScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/IndriAndScorer.java @@ -25,9 +25,9 @@ */ public class IndriAndScorer extends IndriDisjunctionScorer { - protected IndriAndScorer(Weight weight, List subScorers, ScoreMode scoreMode, float boost) + protected IndriAndScorer(List subScorers, ScoreMode scoreMode, float boost) throws IOException { - super(weight, subScorers, scoreMode, boost); + super(subScorers, scoreMode, boost); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/IndriAndWeight.java b/lucene/core/src/java/org/apache/lucene/search/IndriAndWeight.java index 58938be4333a..1aa9db7c1591 100644 --- a/lucene/core/src/java/org/apache/lucene/search/IndriAndWeight.java +++ b/lucene/core/src/java/org/apache/lucene/search/IndriAndWeight.java @@ -59,7 +59,7 @@ private Scorer getScorer(LeafReaderContext context) throws IOException { } Scorer scorer = subScorers.get(0); if (subScorers.size() > 1) { - scorer = new IndriAndScorer(this, subScorers, scoreMode, boost); + scorer = new IndriAndScorer(subScorers, scoreMode, boost); } return scorer; } diff --git a/lucene/core/src/java/org/apache/lucene/search/IndriDisjunctionScorer.java b/lucene/core/src/java/org/apache/lucene/search/IndriDisjunctionScorer.java index 1cfab609b1fb..e501013f4abb 100644 --- a/lucene/core/src/java/org/apache/lucene/search/IndriDisjunctionScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/IndriDisjunctionScorer.java @@ -30,9 +30,8 @@ public abstract class IndriDisjunctionScorer extends IndriScorer { private final DisiPriorityQueue subScorers; private final DocIdSetIterator approximation; - protected IndriDisjunctionScorer( - Weight weight, List subScorersList, ScoreMode scoreMode, float boost) { - super(weight, boost); + protected IndriDisjunctionScorer(List subScorersList, ScoreMode scoreMode, float boost) { + super(boost); this.subScorersList = subScorersList; this.subScorers = new DisiPriorityQueue(subScorersList.size()); for (Scorer scorer : subScorersList) { diff --git a/lucene/core/src/java/org/apache/lucene/search/IndriScorer.java b/lucene/core/src/java/org/apache/lucene/search/IndriScorer.java index 7d7902d1604f..1dd97dbf7a0c 100644 --- a/lucene/core/src/java/org/apache/lucene/search/IndriScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/IndriScorer.java @@ -26,8 +26,7 @@ public abstract class IndriScorer extends Scorer { private float boost; - protected IndriScorer(Weight weight, float boost) { - super(weight); + protected IndriScorer(float boost) { this.boost = boost; } diff --git a/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java b/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java index 1bbafc1908de..7f82e78e056f 100644 --- a/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java +++ b/lucene/core/src/java/org/apache/lucene/search/LRUQueryCache.java @@ -779,8 +779,7 @@ public Scorer get(long leadCost) throws IOException { disi = DocIdSetIterator.empty(); } - return new ConstantScoreScorer( - CachingWrapperWeight.this, 0f, ScoreMode.COMPLETE_NO_SCORES, disi); + return new ConstantScoreScorer(0f, ScoreMode.COMPLETE_NO_SCORES, disi); } @Override @@ -805,8 +804,7 @@ public long cost() { return new ScorerSupplier() { @Override public Scorer get(long LeadCost) throws IOException { - return new ConstantScoreScorer( - CachingWrapperWeight.this, 0f, ScoreMode.COMPLETE_NO_SCORES, disi); + return new ConstantScoreScorer(0f, ScoreMode.COMPLETE_NO_SCORES, disi); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java b/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java index 426fc7c2ff52..8bed66a7f495 100644 --- a/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java @@ -33,13 +33,12 @@ public String toString() { @Override public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { - final Weight weight = this; return new ScorerSupplier() { @Override public Scorer get(long leadCost) throws IOException { return new ConstantScoreScorer( - weight, score(), scoreMode, DocIdSetIterator.all(context.reader().maxDoc())); + score(), scoreMode, DocIdSetIterator.all(context.reader().maxDoc())); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreBlendedWrapper.java b/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreBlendedWrapper.java index a598f644d0ca..c108f6d9c1c4 100644 --- a/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreBlendedWrapper.java +++ b/lucene/core/src/java/org/apache/lucene/search/MultiTermQueryConstantScoreBlendedWrapper.java @@ -132,6 +132,6 @@ protected boolean lessThan(PostingsEnum a, PostingsEnum b) { private static Scorer wrapWithDummyScorer(Weight weight, DocIdSetIterator disi) { // The score and score mode do not actually matter here, except that using TOP_SCORES results // in another wrapper object getting created around the disi, so we try to avoid that: - return new ConstantScoreScorer(weight, 1f, ScoreMode.COMPLETE_NO_SCORES, disi); + return new ConstantScoreScorer(1f, ScoreMode.COMPLETE_NO_SCORES, disi); } } diff --git a/lucene/core/src/java/org/apache/lucene/search/PhraseScorer.java b/lucene/core/src/java/org/apache/lucene/search/PhraseScorer.java index 4925de479f82..26a1387acda5 100644 --- a/lucene/core/src/java/org/apache/lucene/search/PhraseScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/PhraseScorer.java @@ -32,8 +32,7 @@ class PhraseScorer extends Scorer { private float minCompetitiveScore = 0; private float freq = 0; - PhraseScorer(Weight weight, PhraseMatcher matcher, ScoreMode scoreMode, LeafSimScorer simScorer) { - super(weight); + PhraseScorer(PhraseMatcher matcher, ScoreMode scoreMode, LeafSimScorer simScorer) { this.matcher = matcher; this.scoreMode = scoreMode; this.simScorer = simScorer; @@ -103,9 +102,4 @@ public int advanceShallow(int target) throws IOException { public float getMaxScore(int upTo) throws IOException { return maxScoreCache.getMaxScore(upTo); } - - @Override - public String toString() { - return "PhraseScorer(" + weight + ")"; - } } diff --git a/lucene/core/src/java/org/apache/lucene/search/PhraseWeight.java b/lucene/core/src/java/org/apache/lucene/search/PhraseWeight.java index b88ee7635439..6aa1d6849682 100644 --- a/lucene/core/src/java/org/apache/lucene/search/PhraseWeight.java +++ b/lucene/core/src/java/org/apache/lucene/search/PhraseWeight.java @@ -65,7 +65,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti if (matcher == null) return null; LeafSimScorer simScorer = new LeafSimScorer(stats, context.reader(), field, scoreMode.needsScores()); - final var scorer = new PhraseScorer(this, matcher, scoreMode, simScorer); + final var scorer = new PhraseScorer(matcher, scoreMode, simScorer); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java b/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java index cc6047916fbf..c2efa68a45ba 100644 --- a/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/PointInSetQuery.java @@ -145,7 +145,6 @@ public final Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, fl return new ConstantScoreWeight(this, boost) { @Override public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { - final Weight weight = this; LeafReader reader = context.reader(); PointValues values = reader.getPointValues(field); @@ -184,7 +183,7 @@ public Scorer get(long leadCost) throws IOException { DocIdSetBuilder result = new DocIdSetBuilder(reader.maxDoc(), values, field); values.intersect(new MergePointVisitor(sortedPackedPoints, result)); DocIdSetIterator iterator = result.build().iterator(); - return new ConstantScoreScorer(weight, score(), scoreMode, iterator); + return new ConstantScoreScorer(score(), scoreMode, iterator); } @Override @@ -221,7 +220,7 @@ public Scorer get(long leadCost) throws IOException { visitor.setPoint(point); values.intersect(visitor); } - return new ConstantScoreScorer(weight, score(), scoreMode, result.build().iterator()); + return new ConstantScoreScorer(score(), scoreMode, result.build().iterator()); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java b/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java index 5d2a00f05125..bfcef92f6f60 100644 --- a/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java @@ -341,14 +341,13 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti allDocsMatch = false; } - final Weight weight = this; if (allDocsMatch) { // all docs have a value and all points are within bounds, so everything matches return new ScorerSupplier() { @Override public Scorer get(long leadCost) { return new ConstantScoreScorer( - weight, score(), scoreMode, DocIdSetIterator.all(reader.maxDoc())); + score(), scoreMode, DocIdSetIterator.all(reader.maxDoc())); } @Override @@ -376,12 +375,12 @@ && cost() > reader.maxDoc() / 2) { long[] cost = new long[] {reader.maxDoc()}; values.intersect(getInverseIntersectVisitor(result, cost)); final DocIdSetIterator iterator = new BitSetIterator(result, cost[0]); - return new ConstantScoreScorer(weight, score(), scoreMode, iterator); + return new ConstantScoreScorer(score(), scoreMode, iterator); } values.intersect(visitor); DocIdSetIterator iterator = result.build().iterator(); - return new ConstantScoreScorer(weight, score(), scoreMode, iterator); + return new ConstantScoreScorer(score(), scoreMode, iterator); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/ReqExclScorer.java b/lucene/core/src/java/org/apache/lucene/search/ReqExclScorer.java index 9a87ba3f7274..914a1e56724f 100644 --- a/lucene/core/src/java/org/apache/lucene/search/ReqExclScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/ReqExclScorer.java @@ -40,7 +40,6 @@ class ReqExclScorer extends Scorer { * @param exclScorer indicates exclusion. */ public ReqExclScorer(Scorer reqScorer, Scorer exclScorer) { - super(reqScorer.weight); this.reqScorer = reqScorer; reqTwoPhaseIterator = reqScorer.twoPhaseIterator(); if (reqTwoPhaseIterator == null) { diff --git a/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java b/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java index 091323d510be..3e86af3aa8fd 100644 --- a/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java @@ -48,7 +48,6 @@ class ReqOptSumScorer extends Scorer { */ public ReqOptSumScorer(Scorer reqScorer, Scorer optScorer, ScoreMode scoreMode) throws IOException { - super(reqScorer.weight); assert reqScorer != null; assert optScorer != null; this.reqScorer = reqScorer; diff --git a/lucene/core/src/java/org/apache/lucene/search/Scorer.java b/lucene/core/src/java/org/apache/lucene/search/Scorer.java index bf25649ace0c..825a28cb5576 100644 --- a/lucene/core/src/java/org/apache/lucene/search/Scorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/Scorer.java @@ -17,7 +17,6 @@ package org.apache.lucene.search; import java.io.IOException; -import java.util.Objects; /** * Expert: Common scoring functionality for different types of queries. @@ -26,18 +25,7 @@ * increasing order of doc id. */ public abstract class Scorer extends Scorable { - - /** the Scorer's parent Weight */ - protected final Weight weight; - - /** - * Constructs a Scorer - * - * @param weight The scorers Weight. - */ - protected Scorer(Weight weight) { - this.weight = Objects.requireNonNull(weight); - } + protected Scorer() {} /** Returns the doc ID that is currently being scored. */ public abstract int docID(); diff --git a/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java b/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java index e36619dacb1f..0500f4630dc8 100644 --- a/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/SynonymQuery.java @@ -309,9 +309,9 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti if (iterators.size() == 1) { final TermScorer scorer; if (scoreMode == ScoreMode.TOP_SCORES) { - scorer = new TermScorer(this, impacts.get(0), simScorer); + scorer = new TermScorer(impacts.get(0), simScorer); } else { - scorer = new TermScorer(this, iterators.get(0), simScorer); + scorer = new TermScorer(iterators.get(0), simScorer); } float boost = termBoosts.get(0); synonymScorer = @@ -324,7 +324,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti DisiPriorityQueue queue = new DisiPriorityQueue(iterators.size()); for (int i = 0; i < iterators.size(); i++) { PostingsEnum postings = iterators.get(i); - final TermScorer termScorer = new TermScorer(this, postings, simScorer); + final TermScorer termScorer = new TermScorer(postings, simScorer); float boost = termBoosts.get(i); final DisiWrapperFreq wrapper = new DisiWrapperFreq(termScorer, boost); queue.add(wrapper); @@ -348,7 +348,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti iterator = impactsDisi; } - synonymScorer = new SynonymScorer(this, queue, iterator, impactsDisi, simScorer); + synonymScorer = new SynonymScorer(queue, iterator, impactsDisi, simScorer); } return new DefaultScorerSupplier(synonymScorer); } @@ -536,12 +536,10 @@ private static class SynonymScorer extends Scorer { private final LeafSimScorer simScorer; SynonymScorer( - Weight weight, DisiPriorityQueue queue, DocIdSetIterator iterator, ImpactsDISI impactsDisi, LeafSimScorer simScorer) { - super(weight); this.queue = queue; this.iterator = iterator; this.maxScoreCache = impactsDisi.getMaxScoreCache(); diff --git a/lucene/core/src/java/org/apache/lucene/search/TermQuery.java b/lucene/core/src/java/org/apache/lucene/search/TermQuery.java index 8f5de54c7e94..84037acd0d42 100644 --- a/lucene/core/src/java/org/apache/lucene/search/TermQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/TermQuery.java @@ -141,7 +141,6 @@ public Scorer get(long leadCost) throws IOException { topLevelScoringClause); } else { return new TermScorer( - TermWeight.this, termsEnum.postings( null, scoreMode.needsScores() ? PostingsEnum.FREQS : PostingsEnum.NONE), scorer); diff --git a/lucene/core/src/java/org/apache/lucene/search/TermScorer.java b/lucene/core/src/java/org/apache/lucene/search/TermScorer.java index 12d59db76a3f..22c6102b9584 100644 --- a/lucene/core/src/java/org/apache/lucene/search/TermScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/TermScorer.java @@ -34,8 +34,7 @@ public final class TermScorer extends Scorer { private final MaxScoreCache maxScoreCache; /** Construct a {@link TermScorer} that will iterate all documents. */ - public TermScorer(Weight weight, PostingsEnum postingsEnum, LeafSimScorer docScorer) { - super(weight); + public TermScorer(PostingsEnum postingsEnum, LeafSimScorer docScorer) { iterator = this.postingsEnum = postingsEnum; ImpactsEnum impactsEnum = new SlowImpactsEnum(postingsEnum); maxScoreCache = new MaxScoreCache(impactsEnum, docScorer.getSimScorer()); @@ -52,7 +51,6 @@ public TermScorer( ImpactsEnum impactsEnum, LeafSimScorer docScorer, boolean topLevelScoringClause) { - super(weight); postingsEnum = impactsEnum; maxScoreCache = new MaxScoreCache(impactsEnum, docScorer.getSimScorer()); if (topLevelScoringClause) { @@ -107,10 +105,4 @@ public void setMinCompetitiveScore(float minScore) { impactsDisi.setMinCompetitiveScore(minScore); } } - - /** Returns a string representation of this TermScorer. */ - @Override - public String toString() { - return "scorer(" + weight + ")[" + super.toString() + "]"; - } } diff --git a/lucene/core/src/java/org/apache/lucene/search/WANDScorer.java b/lucene/core/src/java/org/apache/lucene/search/WANDScorer.java index d33d3a00d37f..fe5e8803b4cb 100644 --- a/lucene/core/src/java/org/apache/lucene/search/WANDScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/WANDScorer.java @@ -150,9 +150,8 @@ private static long scaleMinScore(float minScore, int scalingFactor) { final ScoreMode scoreMode; - WANDScorer(Weight weight, Collection scorers, int minShouldMatch, ScoreMode scoreMode) + WANDScorer(Collection scorers, int minShouldMatch, ScoreMode scoreMode) throws IOException { - super(weight); if (minShouldMatch >= scorers.size()) { throw new IllegalArgumentException("minShouldMatch should be < the number of scorers"); diff --git a/lucene/core/src/test/org/apache/lucene/search/BaseKnnVectorQueryTestCase.java b/lucene/core/src/test/org/apache/lucene/search/BaseKnnVectorQueryTestCase.java index fac9ceaaf714..fb24b1893dfc 100644 --- a/lucene/core/src/test/org/apache/lucene/search/BaseKnnVectorQueryTestCase.java +++ b/lucene/core/src/test/org/apache/lucene/search/BaseKnnVectorQueryTestCase.java @@ -1008,7 +1008,7 @@ public BitSet getBitSet() { throw new UnsupportedOperationException("reusing BitSet is not supported"); } }; - final var scorer = new ConstantScoreScorer(this, score(), scoreMode, bitSetIterator); + final var scorer = new ConstantScoreScorer(score(), scoreMode, bitSetIterator); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java b/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java index adfc4cab5ca9..35cb547190ff 100644 --- a/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java +++ b/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java @@ -165,9 +165,7 @@ public int hashCode() { static final class JustCompileScorer extends Scorer { - protected JustCompileScorer(Weight weight) { - super(weight); - } + protected JustCompileScorer() {} @Override public float score() { diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBoolean2ScorerSupplier.java b/lucene/core/src/test/org/apache/lucene/search/TestBoolean2ScorerSupplier.java index 58cd8a652bd2..780b6ea56811 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBoolean2ScorerSupplier.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBoolean2ScorerSupplier.java @@ -57,7 +57,6 @@ private static class FakeScorer extends Scorer { private final DocIdSetIterator it; FakeScorer(long cost) { - super(new FakeWeight()); this.it = DocIdSetIterator.all(Math.toIntExact(cost)); } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestConjunctionDISI.java b/lucene/core/src/test/org/apache/lucene/search/TestConjunctionDISI.java index ae896ee41cc8..68d4263b9f42 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestConjunctionDISI.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestConjunctionDISI.java @@ -23,7 +23,6 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; -import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.lucene.tests.util.TestUtil; import org.apache.lucene.util.BitDocIdSet; @@ -86,28 +85,6 @@ private static Scorer scorer(TwoPhaseIterator twoPhaseIterator) { return scorer(TwoPhaseIterator.asDocIdSetIterator(twoPhaseIterator), twoPhaseIterator); } - private static class FakeWeight extends Weight { - - protected FakeWeight() { - super(new MatchNoDocsQuery()); - } - - @Override - public Explanation explain(LeafReaderContext context, int doc) throws IOException { - return null; - } - - @Override - public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { - return null; - } - - @Override - public boolean isCacheable(LeafReaderContext ctx) { - return false; - } - } - /** * Create a {@link Scorer} that wraps the given {@link DocIdSetIterator}. It also accepts a {@link * TwoPhaseIterator} view, which is exposed in {@link Scorer#twoPhaseIterator()}. When the @@ -116,7 +93,7 @@ public boolean isCacheable(LeafReaderContext ctx) { * ConjunctionDISI} takes advantage of the {@link TwoPhaseIterator} view. */ private static Scorer scorer(DocIdSetIterator it, TwoPhaseIterator twoPhaseIterator) { - return new Scorer(new FakeWeight()) { + return new Scorer() { @Override public DocIdSetIterator iterator() { @@ -237,17 +214,13 @@ public void testConjunction() throws IOException { sets[i] = set; iterators[i] = new ConstantScoreScorer( - new FakeWeight(), - 0f, - ScoreMode.TOP_SCORES, - anonymizeIterator(new BitDocIdSet(set).iterator())); + 0f, ScoreMode.TOP_SCORES, anonymizeIterator(new BitDocIdSet(set).iterator())); break; case 1: // bitSet iterator sets[i] = set; iterators[i] = - new ConstantScoreScorer( - new FakeWeight(), 0f, ScoreMode.TOP_SCORES, new BitDocIdSet(set).iterator()); + new ConstantScoreScorer(0f, ScoreMode.TOP_SCORES, new BitDocIdSet(set).iterator()); break; default: // scorer with approximation @@ -282,10 +255,7 @@ public void testConjunctionApproximation() throws IOException { sets[i] = set; iterators[i] = new ConstantScoreScorer( - new FakeWeight(), - 0f, - ScoreMode.COMPLETE_NO_SCORES, - new BitDocIdSet(set).iterator()); + 0f, ScoreMode.COMPLETE_NO_SCORES, new BitDocIdSet(set).iterator()); } else { // scorer with approximation final FixedBitSet confirmed = clearRandomBits(set); @@ -328,17 +298,13 @@ public void testRecursiveConjunctionApproximation() throws IOException { sets[i] = set; newIterator = new ConstantScoreScorer( - new FakeWeight(), - 0f, - ScoreMode.TOP_SCORES, - anonymizeIterator(new BitDocIdSet(set).iterator())); + 0f, ScoreMode.TOP_SCORES, anonymizeIterator(new BitDocIdSet(set).iterator())); break; case 1: // bitSet iterator sets[i] = set; newIterator = - new ConstantScoreScorer( - new FakeWeight(), 0f, ScoreMode.TOP_SCORES, new BitDocIdSet(set).iterator()); + new ConstantScoreScorer(0f, ScoreMode.TOP_SCORES, new BitDocIdSet(set).iterator()); break; default: // scorer with approximation @@ -384,8 +350,7 @@ public void testCollapseSubConjunctions(boolean wrapWithScorer) throws IOExcepti // simple iterator sets[i] = set; scorers.add( - new ConstantScoreScorer( - new FakeWeight(), 0f, ScoreMode.TOP_SCORES, new BitDocIdSet(set).iterator())); + new ConstantScoreScorer(0f, ScoreMode.TOP_SCORES, new BitDocIdSet(set).iterator())); } else { // scorer with approximation final FixedBitSet confirmed = clearRandomBits(set); @@ -404,15 +369,11 @@ public void testCollapseSubConjunctions(boolean wrapWithScorer) throws IOExcepti List subIterators = scorers.subList(subSeqStart, subSeqEnd); Scorer subConjunction; if (wrapWithScorer) { - subConjunction = - new ConjunctionScorer(new FakeWeight(), subIterators, Collections.emptyList()); + subConjunction = new ConjunctionScorer(subIterators, Collections.emptyList()); } else { subConjunction = new ConstantScoreScorer( - new FakeWeight(), - 0f, - ScoreMode.TOP_SCORES, - ConjunctionUtils.intersectScorers(subIterators)); + 0f, ScoreMode.TOP_SCORES, ConjunctionUtils.intersectScorers(subIterators)); } scorers.set(subSeqStart, subConjunction); int toRemove = subSeqEnd - subSeqStart - 1; @@ -423,8 +384,7 @@ public void testCollapseSubConjunctions(boolean wrapWithScorer) throws IOExcepti if (scorers.size() == 1) { // ConjunctionDISI needs two iterators scorers.add( - new ConstantScoreScorer( - new FakeWeight(), 0f, ScoreMode.TOP_SCORES, DocIdSetIterator.all(maxDoc))); + new ConstantScoreScorer(0f, ScoreMode.TOP_SCORES, DocIdSetIterator.all(maxDoc))); } final DocIdSetIterator conjunction = ConjunctionUtils.intersectScorers(scorers); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreScorer.java index f9ea6f74b8fe..e10ed44890ec 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreScorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreScorer.java @@ -205,9 +205,9 @@ ConstantScoreScorer constantScoreScorer(Query query, float score, ScoreMode scor Scorer scorer = weight.scorer(context); if (scorer.twoPhaseIterator() == null) { - return new ConstantScoreScorer(weight, score, scoreMode, scorer.iterator()); + return new ConstantScoreScorer(score, scoreMode, scorer.iterator()); } else { - return new ConstantScoreScorer(weight, score, scoreMode, scorer.twoPhaseIterator()); + return new ConstantScoreScorer(score, scoreMode, scorer.twoPhaseIterator()); } } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestDisiPriorityQueue.java b/lucene/core/src/test/org/apache/lucene/search/TestDisiPriorityQueue.java index 0826cbe7ee90..62dc0a94ca3b 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestDisiPriorityQueue.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestDisiPriorityQueue.java @@ -125,7 +125,7 @@ public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float bo return new ConstantScoreWeight(this, boost) { @Override public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { - final var scorer = new ConstantScoreScorer(this, score(), scoreMode, disi); + final var scorer = new ConstantScoreScorer(score(), scoreMode, disi); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionScoreBlockBoundaryPropagator.java b/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionScoreBlockBoundaryPropagator.java index 803e7a04d987..387e4f984a59 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionScoreBlockBoundaryPropagator.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionScoreBlockBoundaryPropagator.java @@ -20,40 +20,15 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.tests.util.LuceneTestCase; public class TestDisjunctionScoreBlockBoundaryPropagator extends LuceneTestCase { - - private static class FakeWeight extends Weight { - - FakeWeight() { - super(new MatchNoDocsQuery()); - } - - @Override - public Explanation explain(LeafReaderContext context, int doc) throws IOException { - return null; - } - - @Override - public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { - return null; - } - - @Override - public boolean isCacheable(LeafReaderContext ctx) { - return false; - } - } - private static class FakeScorer extends Scorer { final int boundary; final float maxScore; FakeScorer(int boundary, float maxScore) throws IOException { - super(new FakeWeight()); this.boundary = boundary; this.maxScore = maxScore; } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java b/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java index 4b65e52dd44d..cd474ed05590 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java @@ -1629,8 +1629,7 @@ public boolean isCacheable(LeafReaderContext ctx) { @Override public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { - final var scorer = - new ConstantScoreScorer(this, boost, scoreMode, DocIdSetIterator.all(1)); + final var scorer = new ConstantScoreScorer(boost, scoreMode, DocIdSetIterator.all(1)); return new ScorerSupplier() { @Override public Scorer get(long leadCost) throws IOException { @@ -1722,13 +1721,12 @@ public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float bo return new ConstantScoreWeight(this, 1) { @Override public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { - final Weight weight = this; return new ScorerSupplier() { @Override public Scorer get(long leadCost) throws IOException { scorerCreatedCount.incrementAndGet(); return new ConstantScoreScorer( - weight, 1, scoreMode, DocIdSetIterator.all(context.reader().maxDoc())); + 1, scoreMode, DocIdSetIterator.all(context.reader().maxDoc())); } @Override diff --git a/lucene/core/src/test/org/apache/lucene/search/TestMaxScoreBulkScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestMaxScoreBulkScorer.java index fad7b80a388e..4c731201dc65 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestMaxScoreBulkScorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestMaxScoreBulkScorer.java @@ -372,38 +372,6 @@ public void collect(int doc) throws IOException { } } - private static class FakeWeight extends Weight { - - protected FakeWeight() { - super(null); - } - - @Override - public boolean isCacheable(LeafReaderContext ctx) { - return false; - } - - @Override - public Explanation explain(LeafReaderContext context, int doc) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public ScorerSupplier scorerSupplier(LeafReaderContext context) { - return new ScorerSupplier() { - @Override - public Scorer get(long leadCost) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public long cost() { - throw new UnsupportedOperationException(); - } - }; - } - } - private static class FakeScorer extends Scorer { final String toString; @@ -413,7 +381,6 @@ private static class FakeScorer extends Scorer { int cost = 10; protected FakeScorer(String toString) { - super(new FakeWeight()); this.toString = toString; } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java b/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java index 1c0c15431b86..95f6f7ee1247 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java @@ -135,7 +135,7 @@ private Scorer scorer(String[] values, int minShouldMatch, Mode mode) throws Exc } return null; } - return new BulkScorerWrapperScorer(weight, bulkScorer, TestUtil.nextInt(random(), 1, 100)); + return new BulkScorerWrapperScorer(bulkScorer, TestUtil.nextInt(random(), 1, 100)); default: throw new AssertionError(); } @@ -351,7 +351,6 @@ static class SlowMinShouldMatchScorer extends Scorer { SlowMinShouldMatchScorer(BooleanWeight weight, LeafReader reader, IndexSearcher searcher) throws IOException { - super(weight); this.dv = reader.getSortedSetDocValues("dv"); this.maxDoc = reader.maxDoc(); BooleanQuery bq = (BooleanQuery) weight.getQuery(); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java b/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java index dcf644ad1a01..1a9245e6f78c 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java @@ -19,7 +19,6 @@ import java.io.IOException; import org.apache.lucene.document.Document; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; import org.apache.lucene.tests.index.RandomIndexWriter; import org.apache.lucene.tests.util.LuceneTestCase; @@ -29,9 +28,7 @@ public class TestPositiveScoresOnlyCollector extends LuceneTestCase { private static final class SimpleScorer extends Scorer { private int idx = -1; - public SimpleScorer(Weight weight) { - super(weight); - } + public SimpleScorer() {} @Override public float score() { @@ -113,10 +110,7 @@ public void testNegativeScores() throws Exception { writer.commit(); IndexReader ir = writer.getReader(); writer.close(); - IndexSearcher searcher = newSearcher(ir); - Weight fake = - new TermQuery(new Term("fake", "weight")).createWeight(searcher, ScoreMode.COMPLETE, 1f); - Scorer s = new SimpleScorer(fake); + Scorer s = new SimpleScorer(); TopDocsCollector tdc = TopScoreDocCollector.create(scores.length, Integer.MAX_VALUE); Collector c = new PositiveScoresOnlyCollector(tdc); LeafCollector ac = c.getLeafCollector(ir.leaves().get(0)); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java b/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java index 54131afda8b7..d422f85e012f 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java @@ -495,7 +495,7 @@ public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float bo @Override public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { final var scorer = - new Scorer(this) { + new Scorer() { int docID = -1; @Override diff --git a/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java index 43be07108871..6c6a30d9df46 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java @@ -19,7 +19,6 @@ import java.io.IOException; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; import org.apache.lucene.tests.index.RandomIndexWriter; import org.apache.lucene.tests.util.LuceneTestCase; @@ -30,9 +29,7 @@ private static final class SimpleScorer extends Scorer { private int idx = 0; private int doc = -1; - public SimpleScorer(Weight weight) { - super(weight); - } + public SimpleScorer() {} @Override public float score() { @@ -145,10 +142,7 @@ public void testGetScores() throws Exception { writer.commit(); IndexReader ir = writer.getReader(); writer.close(); - IndexSearcher searcher = newSearcher(ir); - Weight fake = - new TermQuery(new Term("fake", "weight")).createWeight(searcher, ScoreMode.COMPLETE, 1f); - Scorer s = new SimpleScorer(fake); + Scorer s = new SimpleScorer(); ScoreCachingCollector scc = new ScoreCachingCollector(scores.length); LeafCollector lc = scc.getLeafCollector(null); lc.setScorer(s); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestScorerPerf.java b/lucene/core/src/test/org/apache/lucene/search/TestScorerPerf.java index 04d8c64671cd..25404eacb308 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestScorerPerf.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestScorerPerf.java @@ -170,10 +170,7 @@ public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float bo public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { final var scorer = new ConstantScoreScorer( - this, - score(), - scoreMode, - new BitSetIterator(docs, docs.approximateCardinality())); + score(), scoreMode, new BitSetIterator(docs, docs.approximateCardinality())); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java b/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java index 41faa7705834..35b44fd719c9 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestSortRandom.java @@ -268,10 +268,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti final var scorer = new ConstantScoreScorer( - this, - score(), - scoreMode, - new BitSetIterator(bits, bits.approximateCardinality())); + score(), scoreMode, new BitSetIterator(bits, bits.approximateCardinality())); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestUsageTrackingFilterCachingPolicy.java b/lucene/core/src/test/org/apache/lucene/search/TestUsageTrackingFilterCachingPolicy.java index 03089f8c2dc2..4ae0d1610874 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestUsageTrackingFilterCachingPolicy.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestUsageTrackingFilterCachingPolicy.java @@ -134,8 +134,7 @@ public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float bo return new ConstantScoreWeight(DummyQuery.this, boost) { @Override public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { - final var scorer = - new ConstantScoreScorer(this, score(), scoreMode, DocIdSetIterator.all(1)); + final var scorer = new ConstantScoreScorer(score(), scoreMode, DocIdSetIterator.all(1)); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestWANDScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestWANDScorer.java index 88bc3ad74605..678a0812ebc7 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestWANDScorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestWANDScorer.java @@ -1024,8 +1024,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti final Scorer scorer; if (optionalScorers.size() > 0) { scorer = - new WANDScorer( - weight, optionalScorers, query.getMinimumNumberShouldMatch(), scoreMode); + new WANDScorer(optionalScorers, query.getMinimumNumberShouldMatch(), scoreMode); } else { scorer = weight.scorer(context); if (scorer == null) return null; diff --git a/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java b/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java index ef41ae380710..dca425f40f4f 100644 --- a/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java +++ b/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java @@ -180,8 +180,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti Scorer scorer = drillDowns[dim].scorer(context); if (scorer == null) { nullCount++; - scorer = - new ConstantScoreScorer(drillDowns[dim], 0f, scoreMode, DocIdSetIterator.empty()); + scorer = new ConstantScoreScorer(0f, scoreMode, DocIdSetIterator.empty()); } FacetsCollector sidewaysCollector = drillSidewaysCollectorManagers[dim].newCollector(); diff --git a/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java b/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java index 4e8ffb192669..1e9f101f555a 100644 --- a/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java +++ b/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java @@ -202,7 +202,7 @@ public float matchCost() { return 100; // TODO: use cost of range.accept() } }; - final var scorer = new ConstantScoreScorer(this, score(), scoreMode, twoPhase); + final var scorer = new ConstantScoreScorer(score(), scoreMode, twoPhase); return new DefaultScorerSupplier(scorer); } @@ -309,7 +309,7 @@ public float matchCost() { return 100; // TODO: use cost of range.accept() } }; - final var scorer = new ConstantScoreScorer(this, score(), scoreMode, twoPhase); + final var scorer = new ConstantScoreScorer(score(), scoreMode, twoPhase); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java b/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java index 0a749c2d3bb7..9869f71718e4 100644 --- a/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java +++ b/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java @@ -189,7 +189,7 @@ public float matchCost() { return 100; // TODO: use cost of range.accept() } }; - final var scorer = new ConstantScoreScorer(this, score(), scoreMode, twoPhase); + final var scorer = new ConstantScoreScorer(score(), scoreMode, twoPhase); return new DefaultScorerSupplier(scorer); } @@ -296,7 +296,7 @@ public float matchCost() { return 100; // TODO: use cost of range.accept() } }; - final var scorer = new ConstantScoreScorer(this, score(), scoreMode, twoPhase); + final var scorer = new ConstantScoreScorer(score(), scoreMode, twoPhase); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java index 812ae228c7bd..5645f1915491 100644 --- a/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java +++ b/lucene/facet/src/test/org/apache/lucene/facet/TestDrillSideways.java @@ -1314,7 +1314,6 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) DocIdSetIterator.all(context.reader().maxDoc()); final var scorer = new ConstantScoreScorer( - this, score(), scoreMode, new TwoPhaseIterator(approximation) { diff --git a/lucene/join/src/java/org/apache/lucene/search/join/BaseGlobalOrdinalScorer.java b/lucene/join/src/java/org/apache/lucene/search/join/BaseGlobalOrdinalScorer.java index 881cbce37ab7..125febd538fd 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/BaseGlobalOrdinalScorer.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/BaseGlobalOrdinalScorer.java @@ -21,7 +21,6 @@ import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.TwoPhaseIterator; -import org.apache.lucene.search.Weight; abstract class BaseGlobalOrdinalScorer extends Scorer { @@ -32,8 +31,7 @@ abstract class BaseGlobalOrdinalScorer extends Scorer { float score; public BaseGlobalOrdinalScorer( - Weight weight, SortedDocValues values, DocIdSetIterator approximationScorer, float boost) { - super(weight); + SortedDocValues values, DocIdSetIterator approximationScorer, float boost) { this.values = values; this.approximation = approximationScorer; this.boost = boost; diff --git a/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsQuery.java index c0c150d23373..5505f7ba28c9 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsQuery.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsQuery.java @@ -184,7 +184,6 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti if (globalOrds != null) { scorer = new OrdinalMapScorer( - this, score(), foundOrds, values, @@ -192,8 +191,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti globalOrds.getGlobalOrds(context.ord)); } else { scorer = - new SegmentOrdinalScorer( - this, score(), foundOrds, values, approximationScorer.iterator()); + new SegmentOrdinalScorer(score(), foundOrds, values, approximationScorer.iterator()); } return new DefaultScorerSupplier(scorer); } @@ -213,13 +211,12 @@ static final class OrdinalMapScorer extends BaseGlobalOrdinalScorer { final LongValues segmentOrdToGlobalOrdLookup; public OrdinalMapScorer( - Weight weight, float score, LongBitSet foundOrds, SortedDocValues values, DocIdSetIterator approximationScorer, LongValues segmentOrdToGlobalOrdLookup) { - super(weight, values, approximationScorer, 1); + super(values, approximationScorer, 1); this.score = score; this.foundOrds = foundOrds; this.segmentOrdToGlobalOrdLookup = segmentOrdToGlobalOrdLookup; @@ -254,12 +251,11 @@ static final class SegmentOrdinalScorer extends BaseGlobalOrdinalScorer { final LongBitSet foundOrds; public SegmentOrdinalScorer( - Weight weight, float score, LongBitSet foundOrds, SortedDocValues values, DocIdSetIterator approximationScorer) { - super(weight, values, approximationScorer, 1); + super(values, approximationScorer, 1); this.score = score; this.foundOrds = foundOrds; } diff --git a/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java index 85dbf2ec29c9..9b118d3cf2e6 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java @@ -222,16 +222,13 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti } else if (globalOrds != null) { scorer = new OrdinalMapScorer( - this, collector, boost, values, approximationScorer.iterator(), globalOrds.getGlobalOrds(context.ord)); } else { - scorer = - new SegmentOrdinalScorer( - this, collector, values, boost, approximationScorer.iterator()); + scorer = new SegmentOrdinalScorer(collector, values, boost, approximationScorer.iterator()); } return new DefaultScorerSupplier(scorer); } @@ -251,13 +248,12 @@ static final class OrdinalMapScorer extends BaseGlobalOrdinalScorer { final GlobalOrdinalsWithScoreCollector collector; public OrdinalMapScorer( - Weight weight, GlobalOrdinalsWithScoreCollector collector, float boost, SortedDocValues values, DocIdSetIterator approximation, LongValues segmentOrdToGlobalOrdLookup) { - super(weight, values, approximation, boost); + super(values, approximation, boost); this.segmentOrdToGlobalOrdLookup = segmentOrdToGlobalOrdLookup; this.collector = collector; } @@ -292,12 +288,11 @@ static final class SegmentOrdinalScorer extends BaseGlobalOrdinalScorer { final GlobalOrdinalsWithScoreCollector collector; public SegmentOrdinalScorer( - Weight weight, GlobalOrdinalsWithScoreCollector collector, SortedDocValues values, float boost, DocIdSetIterator approximation) { - super(weight, values, approximation, boost); + super(values, approximation, boost); this.collector = collector; } diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ParentChildrenBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ParentChildrenBlockJoinQuery.java index 93cef702301f..03b6480622be 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/ParentChildrenBlockJoinQuery.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/ParentChildrenBlockJoinQuery.java @@ -177,7 +177,7 @@ public long cost() { } }; final var scorer = - new Scorer(this) { + new Scorer() { @Override public int docID() { return it.docID(); diff --git a/lucene/join/src/java/org/apache/lucene/search/join/PointInSetIncludingScoreQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/PointInSetIncludingScoreQuery.java index 64b481d1dbab..1ece42078cfe 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/PointInSetIncludingScoreQuery.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/PointInSetIncludingScoreQuery.java @@ -204,7 +204,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti float[] scores = new float[reader.maxDoc()]; values.intersect(new MergePointVisitor(sortedPackedPoints, result, scores)); final var scorer = - new Scorer(this) { + new Scorer() { DocIdSetIterator disi = new BitSetIterator(result, 10L); diff --git a/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java index 8864084a0018..a3fa16858442 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java @@ -183,11 +183,9 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti TermsEnum segmentTermsEnum = terms.iterator(); if (multipleValuesPerDocument) { - scorer = - new MVInOrderScorer(this, segmentTermsEnum, context.reader().maxDoc(), cost, boost); + scorer = new MVInOrderScorer(segmentTermsEnum, context.reader().maxDoc(), cost, boost); } else { - scorer = - new SVInOrderScorer(this, segmentTermsEnum, context.reader().maxDoc(), cost, boost); + scorer = new SVInOrderScorer(segmentTermsEnum, context.reader().maxDoc(), cost, boost); } return new DefaultScorerSupplier(scorer); } @@ -206,9 +204,7 @@ class SVInOrderScorer extends Scorer { final long cost; final float boost; - SVInOrderScorer(Weight weight, TermsEnum termsEnum, int maxDoc, long cost, float boost) - throws IOException { - super(weight); + SVInOrderScorer(TermsEnum termsEnum, int maxDoc, long cost, float boost) throws IOException { FixedBitSet matchingDocs = new FixedBitSet(maxDoc); this.scores = new float[maxDoc]; fillDocsAndScores(matchingDocs, termsEnum); @@ -263,9 +259,8 @@ public DocIdSetIterator iterator() { // related documents. class MVInOrderScorer extends SVInOrderScorer { - MVInOrderScorer(Weight weight, TermsEnum termsEnum, int maxDoc, long cost, float boost) - throws IOException { - super(weight, termsEnum, maxDoc, cost, boost); + MVInOrderScorer(TermsEnum termsEnum, int maxDoc, long cost, float boost) throws IOException { + super(termsEnum, maxDoc, cost, boost); } @Override diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java index e618623103f2..6fd0dc99e6d1 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java @@ -118,7 +118,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext readerContext) throws IOE return null; } - final var scorer = new ToChildBlockJoinScorer(this, parentScorer, parents, doScores); + final var scorer = new ToChildBlockJoinScorer(parentScorer, parents, doScores); return new DefaultScorerSupplier(scorer); } @@ -148,9 +148,7 @@ static class ToChildBlockJoinScorer extends Scorer { private int childDoc = -1; private int parentDoc = 0; - public ToChildBlockJoinScorer( - Weight weight, Scorer parentScorer, BitSet parentBits, boolean doScores) { - super(weight); + public ToChildBlockJoinScorer(Scorer parentScorer, BitSet parentBits, boolean doScores) { this.doScores = doScores; this.parentBits = parentBits; this.parentScorer = parentScorer; diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java index b7d98650a1e2..db21e17ba089 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java @@ -148,8 +148,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti @Override public Scorer get(long leadCost) throws IOException { - return new BlockJoinScorer( - BlockJoinWeight.this, childScorerSupplier.get(leadCost), parents, scoreMode); + return new BlockJoinScorer(childScorerSupplier.get(leadCost), parents, scoreMode); } @Override @@ -274,9 +273,7 @@ static class BlockJoinScorer extends Scorer { private final ParentTwoPhase parentTwoPhase; private float score; - public BlockJoinScorer( - Weight weight, Scorer childScorer, BitSet parentBits, ScoreMode scoreMode) { - super(weight); + public BlockJoinScorer(Scorer childScorer, BitSet parentBits, ScoreMode scoreMode) { // System.out.println("Q.init firstChildDoc=" + firstChildDoc); this.parentBits = parentBits; this.childScorer = childScorer; diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java b/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java index ee2caee00334..1e9fc55c5984 100644 --- a/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java +++ b/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java @@ -586,7 +586,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti } NumericDocValues price = context.reader().getNumericDocValues(field); final var scorer = - new FilterScorer(fieldScorer, this) { + new FilterScorer(fieldScorer) { @Override public float score() throws IOException { assertEquals(in.docID(), price.advance(in.docID())); diff --git a/lucene/misc/src/test/org/apache/lucene/misc/search/TestDiversifiedTopDocsCollector.java b/lucene/misc/src/test/org/apache/lucene/misc/search/TestDiversifiedTopDocsCollector.java index 72359458fd1e..a5f5e9e7f1e2 100644 --- a/lucene/misc/src/test/org/apache/lucene/misc/search/TestDiversifiedTopDocsCollector.java +++ b/lucene/misc/src/test/org/apache/lucene/misc/search/TestDiversifiedTopDocsCollector.java @@ -534,7 +534,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti final var innerScorer = scorerSupplier.get(Long.MAX_VALUE); NumericDocValues scoreFactors = DocValues.getNumeric(context.reader(), scoreField); final var scorer = - new Scorer(this) { + new Scorer() { @Override public float score() throws IOException { diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionMatchQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionMatchQuery.java index 029b41118ada..33b50022a708 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionMatchQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionMatchQuery.java @@ -104,7 +104,7 @@ public float matchCost() { return matchCost; // TODO maybe DoubleValuesSource should have a matchCost? } }; - final var scorer = new ConstantScoreScorer(this, score(), scoreMode, twoPhase); + final var scorer = new ConstantScoreScorer(score(), scoreMode, twoPhase); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java index 72c37ebbabd7..b45ffe789db9 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java @@ -108,7 +108,6 @@ protected class AllScorer extends Scorer { final FunctionValues vals; public AllScorer(LeafReaderContext context, FunctionWeight w, float boost) throws IOException { - super(w); this.weight = w; this.boost = boost; this.reader = context.reader(); diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java index 2c29276f20bf..7069496e2618 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java @@ -32,7 +32,7 @@ * A Query wrapping a {@link ValueSource} that matches docs in which the values in the value source * match a configured range. The score is the float value. This can be a slow query if run by itself * since it must visit all docs; ideally it's combined with other queries. It's mostly a wrapper - * around {@link FunctionValues#getRangeScorer(Weight, LeafReaderContext, String, String, boolean, + * around {@link FunctionValues#getRangeScorer(LeafReaderContext, String, String, boolean, * boolean)}. * *

A similar class is {@code org.apache.lucene.search.DocValuesRangeQuery} in the sandbox module. @@ -169,8 +169,7 @@ public Explanation explain(LeafReaderContext context, int doc) throws IOExceptio public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { FunctionValues functionValues = valueSource.getValues(vsContext, context); final var scorer = - functionValues.getRangeScorer( - this, context, lowerVal, upperVal, includeLower, includeUpper); + functionValues.getRangeScorer(context, lowerVal, upperVal, includeLower, includeUpper); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionValues.java b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionValues.java index ed38e3e723c2..ec3eb99a1980 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionValues.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionValues.java @@ -20,7 +20,6 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.Explanation; import org.apache.lucene.search.Scorer; -import org.apache.lucene.search.Weight; import org.apache.lucene.util.BytesRefBuilder; import org.apache.lucene.util.mutable.MutableValue; import org.apache.lucene.util.mutable.MutableValueFloat; @@ -204,8 +203,8 @@ public Explanation explain(int doc) throws IOException { * Yields a {@link Scorer} that matches all documents, and that which produces scores equal to * {@link #floatVal(int)}. */ - public ValueSourceScorer getScorer(Weight weight, LeafReaderContext readerContext) { - return new ValueSourceScorer(weight, readerContext, this) { + public ValueSourceScorer getScorer(LeafReaderContext readerContext) { + return new ValueSourceScorer(readerContext, this) { @Override public boolean matches(int doc) { return true; @@ -227,7 +226,6 @@ public float matchCost() { // a setup cost - parsing and normalizing params, and doing a binary search on the StringIndex. // TODO: change "reader" to LeafReaderContext public ValueSourceScorer getRangeScorer( - Weight weight, LeafReaderContext readerContext, String lowerVal, String upperVal, @@ -252,7 +250,7 @@ public ValueSourceScorer getRangeScorer( final float u = upper; if (includeLower && includeUpper) { - return new ValueSourceScorer(weight, readerContext, this) { + return new ValueSourceScorer(readerContext, this) { @Override public boolean matches(int doc) throws IOException { if (!exists(doc)) return false; @@ -261,7 +259,7 @@ public boolean matches(int doc) throws IOException { } }; } else if (includeLower && !includeUpper) { - return new ValueSourceScorer(weight, readerContext, this) { + return new ValueSourceScorer(readerContext, this) { @Override public boolean matches(int doc) throws IOException { if (!exists(doc)) return false; @@ -270,7 +268,7 @@ public boolean matches(int doc) throws IOException { } }; } else if (!includeLower && includeUpper) { - return new ValueSourceScorer(weight, readerContext, this) { + return new ValueSourceScorer(readerContext, this) { @Override public boolean matches(int doc) throws IOException { if (!exists(doc)) return false; @@ -279,7 +277,7 @@ public boolean matches(int doc) throws IOException { } }; } else { - return new ValueSourceScorer(weight, readerContext, this) { + return new ValueSourceScorer(readerContext, this) { @Override public boolean matches(int doc) throws IOException { if (!exists(doc)) return false; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSourceScorer.java b/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSourceScorer.java index 8b15a7a64cda..8090b3f9ca38 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSourceScorer.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSourceScorer.java @@ -21,7 +21,6 @@ import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.TwoPhaseIterator; -import org.apache.lucene.search.Weight; /** * {@link Scorer} which returns the result of {@link FunctionValues#floatVal(int)} as the score for @@ -43,9 +42,7 @@ public abstract class ValueSourceScorer extends Scorer { private final TwoPhaseIterator twoPhaseIterator; private final DocIdSetIterator disi; - protected ValueSourceScorer( - Weight weight, LeafReaderContext readerContext, FunctionValues values) { - super(weight); + protected ValueSourceScorer(LeafReaderContext readerContext, FunctionValues values) { this.values = values; final DocIdSetIterator approximation = DocIdSetIterator.all(readerContext.reader().maxDoc()); // no approximation! diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DocTermsIndexDocValues.java b/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DocTermsIndexDocValues.java index adaadd2efc31..5e9449658b78 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DocTermsIndexDocValues.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DocTermsIndexDocValues.java @@ -23,7 +23,6 @@ import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.ValueSourceScorer; -import org.apache.lucene.search.Weight; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; import org.apache.lucene.util.CharsRefBuilder; @@ -117,7 +116,6 @@ public boolean boolVal(int doc) throws IOException { @Override public ValueSourceScorer getRangeScorer( - Weight weight, LeafReaderContext readerContext, String lowerVal, String upperVal, @@ -151,7 +149,7 @@ public ValueSourceScorer getRangeScorer( final int ll = lower; final int uu = upper; - return new ValueSourceScorer(weight, readerContext, this) { + return new ValueSourceScorer(readerContext, this) { @Override public boolean matches(int doc) throws IOException { if (!exists(doc)) return false; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DoubleDocValues.java b/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DoubleDocValues.java index 321704593c27..c5e5ff1d2bc0 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DoubleDocValues.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/DoubleDocValues.java @@ -21,7 +21,6 @@ import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.ValueSourceScorer; -import org.apache.lucene.search.Weight; import org.apache.lucene.util.mutable.MutableValue; import org.apache.lucene.util.mutable.MutableValueDouble; @@ -86,7 +85,6 @@ public String toString(int doc) throws IOException { @Override public ValueSourceScorer getRangeScorer( - Weight weight, LeafReaderContext readerContext, String lowerVal, String upperVal, @@ -110,7 +108,7 @@ public ValueSourceScorer getRangeScorer( final double u = upper; if (includeLower && includeUpper) { - return new ValueSourceScorer(weight, readerContext, this) { + return new ValueSourceScorer(readerContext, this) { @Override public boolean matches(int doc) throws IOException { if (!exists(doc)) return false; @@ -119,7 +117,7 @@ public boolean matches(int doc) throws IOException { } }; } else if (includeLower && !includeUpper) { - return new ValueSourceScorer(weight, readerContext, this) { + return new ValueSourceScorer(readerContext, this) { @Override public boolean matches(int doc) throws IOException { if (!exists(doc)) return false; @@ -128,7 +126,7 @@ public boolean matches(int doc) throws IOException { } }; } else if (!includeLower && includeUpper) { - return new ValueSourceScorer(weight, readerContext, this) { + return new ValueSourceScorer(readerContext, this) { @Override public boolean matches(int doc) throws IOException { if (!exists(doc)) return false; @@ -137,7 +135,7 @@ public boolean matches(int doc) throws IOException { } }; } else { - return new ValueSourceScorer(weight, readerContext, this) { + return new ValueSourceScorer(readerContext, this) { @Override public boolean matches(int doc) throws IOException { if (!exists(doc)) return false; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/IntDocValues.java b/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/IntDocValues.java index 58c19c6ae6ee..79c4aa297447 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/IntDocValues.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/IntDocValues.java @@ -21,7 +21,6 @@ import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.ValueSourceScorer; -import org.apache.lucene.search.Weight; import org.apache.lucene.util.mutable.MutableValue; import org.apache.lucene.util.mutable.MutableValueInt; @@ -81,7 +80,6 @@ public String toString(int doc) throws IOException { @Override public ValueSourceScorer getRangeScorer( - Weight weight, LeafReaderContext readerContext, String lowerVal, String upperVal, @@ -108,7 +106,7 @@ public ValueSourceScorer getRangeScorer( final int ll = lower; final int uu = upper; - return new ValueSourceScorer(weight, readerContext, this) { + return new ValueSourceScorer(readerContext, this) { @Override public boolean matches(int doc) throws IOException { if (!exists(doc)) return false; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/LongDocValues.java b/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/LongDocValues.java index 375c84fa4e33..be57a8bc03d8 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/LongDocValues.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/docvalues/LongDocValues.java @@ -21,7 +21,6 @@ import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.ValueSourceScorer; -import org.apache.lucene.search.Weight; import org.apache.lucene.util.mutable.MutableValue; import org.apache.lucene.util.mutable.MutableValueLong; @@ -90,7 +89,6 @@ protected long externalToLong(String extVal) { @Override public ValueSourceScorer getRangeScorer( - Weight weight, LeafReaderContext readerContext, String lowerVal, String upperVal, @@ -117,7 +115,7 @@ public ValueSourceScorer getRangeScorer( final long ll = lower; final long uu = upper; - return new ValueSourceScorer(weight, readerContext, this) { + return new ValueSourceScorer(readerContext, this) { @Override public boolean matches(int doc) throws IOException { if (!exists(doc)) return false; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/EnumFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/EnumFieldSource.java index a618513bafe7..c46c890d7a76 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/EnumFieldSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/EnumFieldSource.java @@ -24,7 +24,6 @@ import org.apache.lucene.queries.function.FunctionValues; import org.apache.lucene.queries.function.ValueSourceScorer; import org.apache.lucene.queries.function.docvalues.IntDocValues; -import org.apache.lucene.search.Weight; /** * Obtains int field values from {@link org.apache.lucene.index.LeafReader#getNumericDocValues} and @@ -135,7 +134,6 @@ public boolean exists(int doc) throws IOException { @Override public ValueSourceScorer getRangeScorer( - Weight weight, LeafReaderContext readerContext, String lowerVal, String upperVal, @@ -161,7 +159,7 @@ public ValueSourceScorer getRangeScorer( final int ll = lower; final int uu = upper; - return new ValueSourceScorer(weight, readerContext, this) { + return new ValueSourceScorer(readerContext, this) { @Override public boolean matches(int doc) throws IOException { if (!exists(doc)) return false; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/intervals/IntervalQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/intervals/IntervalQuery.java index b42a367f3df2..f4f4b7496136 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/intervals/IntervalQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/intervals/IntervalQuery.java @@ -192,7 +192,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti return null; } final var scorer = - new IntervalScorer(this, intervals, intervalsSource.minExtent(), boost, scoreFunction); + new IntervalScorer(intervals, intervalsSource.minExtent(), boost, scoreFunction); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/intervals/IntervalScorer.java b/lucene/queries/src/java/org/apache/lucene/queries/intervals/IntervalScorer.java index ce096e9ea56b..0633d74518f1 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/intervals/IntervalScorer.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/intervals/IntervalScorer.java @@ -21,7 +21,6 @@ import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.TwoPhaseIterator; -import org.apache.lucene.search.Weight; import org.apache.lucene.search.similarities.Similarity; class IntervalScorer extends Scorer { @@ -35,12 +34,7 @@ class IntervalScorer extends Scorer { private int lastScoredDoc = -1; IntervalScorer( - Weight weight, - IntervalIterator intervals, - int minExtent, - float boost, - IntervalScoreFunction scoreFunction) { - super(weight); + IntervalIterator intervals, int minExtent, float boost, IntervalScoreFunction scoreFunction) { this.intervals = intervals; this.minExtent = minExtent; this.boost = boost; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java index 21e8866331e1..7c4541027791 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java @@ -188,7 +188,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti } LeafSimScorer docScorer = innerWeight.getSimScorer(context); PayloadSpans payloadSpans = new PayloadSpans(spans, decoder); - final var scorer = new PayloadSpanScorer(this, payloadSpans, docScorer); + final var scorer = new PayloadSpanScorer(payloadSpans, docScorer); return new DefaultScorerSupplier(scorer); } } @@ -244,9 +244,8 @@ private class PayloadSpanScorer extends SpanScorer { private final PayloadSpans spans; - private PayloadSpanScorer(SpanWeight weight, PayloadSpans spans, LeafSimScorer docScorer) - throws IOException { - super(weight, spans, docScorer); + private PayloadSpanScorer(PayloadSpans spans, LeafSimScorer docScorer) throws IOException { + super(spans, docScorer); this.spans = spans; } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/payloads/SpanPayloadCheckQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/payloads/SpanPayloadCheckQuery.java index 8c3806933649..6cb2dbd2b0f5 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/payloads/SpanPayloadCheckQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/payloads/SpanPayloadCheckQuery.java @@ -192,7 +192,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti return null; } final LeafSimScorer docScorer = getSimScorer(context); - final var scorer = new SpanScorer(this, spans, docScorer); + final var scorer = new SpanScorer(spans, docScorer); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/spans/SpanContainingQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/spans/SpanContainingQuery.java index 4ac226734203..4752d6bee38d 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/spans/SpanContainingQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/spans/SpanContainingQuery.java @@ -140,13 +140,12 @@ public boolean isCacheable(LeafReaderContext ctx) { @Override public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { - final SpanWeight spanWeight = this; final Spans spans = getSpans(context, Postings.POSITIONS); if (spans == null) { return null; } final LeafSimScorer docScorer = getSimScorer(context); - final var scorer = new SpanScorer(spanWeight, spans, docScorer); + final var scorer = new SpanScorer(spans, docScorer); return new DefaultScorerSupplier(scorer); } } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/spans/SpanNearQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/spans/SpanNearQuery.java index ca97ffef0dcf..69e1a74c80bb 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/spans/SpanNearQuery.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/spans/SpanNearQuery.java @@ -243,13 +243,12 @@ public boolean isCacheable(LeafReaderContext ctx) { @Override public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { - final SpanWeight spanWeight = this; final Spans spans = getSpans(context, Postings.POSITIONS); if (spans == null) { return null; } final LeafSimScorer docScorer = getSimScorer(context); - final var scorer = new SpanScorer(spanWeight, spans, docScorer); + final var scorer = new SpanScorer(spans, docScorer); return new DefaultScorerSupplier(scorer); } } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/spans/SpanScorer.java b/lucene/queries/src/java/org/apache/lucene/queries/spans/SpanScorer.java index cb293272cfec..9737ae5308e1 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/spans/SpanScorer.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/spans/SpanScorer.java @@ -39,8 +39,7 @@ public class SpanScorer extends Scorer { private int lastScoredDoc = -1; // last doc we called setFreqCurrentDoc() for /** Sole constructor. */ - public SpanScorer(SpanWeight weight, Spans spans, LeafSimScorer docScorer) { - super(weight); + public SpanScorer(Spans spans, LeafSimScorer docScorer) { this.spans = Objects.requireNonNull(spans); this.docScorer = docScorer; } diff --git a/lucene/queries/src/java/org/apache/lucene/queries/spans/SpanWeight.java b/lucene/queries/src/java/org/apache/lucene/queries/spans/SpanWeight.java index b8b2f812e4b7..29e1c13e773f 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/spans/SpanWeight.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/spans/SpanWeight.java @@ -143,7 +143,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti return null; } final LeafSimScorer docScorer = getSimScorer(context); - final var scorer = new SpanScorer(this, spans, docScorer); + final var scorer = new SpanScorer(spans, docScorer); return new ScorerSupplier() { @Override public SpanScorer get(long leadCost) throws IOException { diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/TestSortedSetFieldSource.java b/lucene/queries/src/test/org/apache/lucene/queries/function/TestSortedSetFieldSource.java index 3245ec8d40f5..05a946298d36 100644 --- a/lucene/queries/src/test/org/apache/lucene/queries/function/TestSortedSetFieldSource.java +++ b/lucene/queries/src/test/org/apache/lucene/queries/function/TestSortedSetFieldSource.java @@ -28,8 +28,6 @@ import org.apache.lucene.queries.function.valuesource.SortedSetFieldSource; import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortedSetSortField; import org.apache.lucene.store.Directory; @@ -77,14 +75,7 @@ public void testSimple() throws Exception { // test scorer vs = new SortedSetFieldSource("value"); values = vs.getValues(Collections.emptyMap(), ar.getContext()); - ValueSourceScorer vss = - values.getRangeScorer( - new MatchAllDocsQuery().createWeight(searcher, ScoreMode.TOP_SCORES, 1), - ar.getContext(), - "a", - "z", - true, - true); + ValueSourceScorer vss = values.getRangeScorer(ar.getContext(), "a", "z", true, true); DocIdSetIterator iterator = vss.iterator(); assertEquals("baz", values.strVal(iterator.nextDoc())); diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CombinedFieldQuery.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CombinedFieldQuery.java index 28a0391563ea..9fe6b890044f 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CombinedFieldQuery.java +++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CombinedFieldQuery.java @@ -428,13 +428,12 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti for (int i = 0; i < iterators.size(); i++) { float weight = fields.get(i).weight; queue.add( - new WeightedDisiWrapper( - new TermScorer(this, iterators.get(i), nonScoringSimScorer), weight)); + new WeightedDisiWrapper(new TermScorer(iterators.get(i), nonScoringSimScorer), weight)); } // Even though it is called approximation, it is accurate since none of // the sub iterators are two-phase iterators. DocIdSetIterator iterator = new DisjunctionDISIApproximation(queue); - final var scorer = new CombinedFieldScorer(this, queue, iterator, scoringSimScorer); + final var scorer = new CombinedFieldScorer(queue, iterator, scoringSimScorer); return new DefaultScorerSupplier(scorer); } @@ -463,11 +462,7 @@ private static class CombinedFieldScorer extends Scorer { private final MultiNormsLeafSimScorer simScorer; CombinedFieldScorer( - Weight weight, - DisiPriorityQueue queue, - DocIdSetIterator iterator, - MultiNormsLeafSimScorer simScorer) { - super(weight); + DisiPriorityQueue queue, DocIdSetIterator iterator, MultiNormsLeafSimScorer simScorer) { this.queue = queue; this.iterator = iterator; this.simScorer = simScorer; diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CoveringQuery.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CoveringQuery.java index 26b54de1d258..2e71813620a9 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CoveringQuery.java +++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CoveringQuery.java @@ -248,10 +248,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti } final var scorer = new CoveringScorer( - this, - scorers, - minimumNumberMatch.getValues(context, null), - context.reader().maxDoc()); + scorers, minimumNumberMatch.getValues(context, null), context.reader().maxDoc()); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CoveringScorer.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CoveringScorer.java index 49081d2412c9..a4662b2c679b 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CoveringScorer.java +++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CoveringScorer.java @@ -26,7 +26,6 @@ import org.apache.lucene.search.LongValues; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.TwoPhaseIterator; -import org.apache.lucene.search.Weight; /** A {@link Scorer} whose number of matches is per-document. */ final class CoveringScorer extends Scorer { @@ -46,9 +45,7 @@ final class CoveringScorer extends Scorer { final long cost; - CoveringScorer(Weight weight, Collection scorers, LongValues minMatchValues, int maxDoc) { - super(weight); - + CoveringScorer(Collection scorers, LongValues minMatchValues, int maxDoc) { this.numScorers = scorers.size(); this.maxDoc = maxDoc; this.minMatchValues = minMatchValues; diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/MultiRangeQuery.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/MultiRangeQuery.java index ee1f0b2b8d68..66c490b791a1 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/MultiRangeQuery.java +++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/MultiRangeQuery.java @@ -333,14 +333,13 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti allDocsMatch = false; } - final Weight weight = this; if (allDocsMatch) { // all docs have a value and all points are within bounds, so everything matches return new ScorerSupplier() { @Override public Scorer get(long leadCost) { return new ConstantScoreScorer( - weight, score(), scoreMode, DocIdSetIterator.all(reader.maxDoc())); + score(), scoreMode, DocIdSetIterator.all(reader.maxDoc())); } @Override @@ -359,7 +358,7 @@ public long cost() { public Scorer get(long leadCost) throws IOException { values.intersect(visitor); DocIdSetIterator iterator = result.build().iterator(); - return new ConstantScoreScorer(weight, score(), scoreMode, iterator); + return new ConstantScoreScorer(score(), scoreMode, iterator); } @Override diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerScorer.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerScorer.java index 1abb4968a216..a809899f20ad 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerScorer.java +++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerScorer.java @@ -38,8 +38,7 @@ class QueryProfilerScorer extends Scorer { computeMaxScoreTimer, setMinCompetitiveScoreTimer; - QueryProfilerScorer(QueryProfilerWeight w, Scorer scorer, QueryProfilerBreakdown profile) { - super(w); + QueryProfilerScorer(Scorer scorer, QueryProfilerBreakdown profile) { this.scorer = scorer; scoreTimer = profile.getTimer(QueryProfilerTimingType.SCORE); nextDocTimer = profile.getTimer(QueryProfilerTimingType.NEXT_DOC); diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerWeight.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerWeight.java index 77113cd181a9..dbc9816ef18d 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerWeight.java +++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerWeight.java @@ -62,15 +62,13 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti if (subQueryScorerSupplier == null) { return null; } - - final QueryProfilerWeight weight = this; return new ScorerSupplier() { @Override public Scorer get(long loadCost) throws IOException { timer.start(); try { - return new QueryProfilerScorer(weight, subQueryScorerSupplier.get(loadCost), profile); + return new QueryProfilerScorer(subQueryScorerSupplier.get(loadCost), profile); } finally { timer.stop(); } diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/TermAutomatonScorer.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/TermAutomatonScorer.java index 5a44190d1d76..2d0b7ecb85bd 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/TermAutomatonScorer.java +++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/TermAutomatonScorer.java @@ -63,7 +63,6 @@ class TermAutomatonScorer extends Scorer { public TermAutomatonScorer( TermAutomatonWeight weight, EnumAndScorer[] subs, int anyTermID, LeafSimScorer docScorer) throws IOException { - super(weight); // System.out.println(" automaton:\n" + weight.automaton.toDot()); this.runAutomaton = new TermRunAutomaton(weight.automaton, subs.length); this.docScorer = docScorer; @@ -361,11 +360,6 @@ LeafSimScorer getLeafSimScorer() { return docScorer; } - @Override - public String toString() { - return "TermAutomatonScorer(" + weight + ")"; - } - @Override public int docID() { return docID; diff --git a/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestQueryProfilerScorer.java b/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestQueryProfilerScorer.java index 06910995977e..add8db29d3df 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestQueryProfilerScorer.java +++ b/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestQueryProfilerScorer.java @@ -18,14 +18,8 @@ package org.apache.lucene.sandbox.search; import java.io.IOException; -import org.apache.lucene.index.MultiReader; import org.apache.lucene.search.DocIdSetIterator; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.MatchAllDocsQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.Scorer; -import org.apache.lucene.search.Weight; import org.apache.lucene.tests.util.LuceneTestCase; public class TestQueryProfilerScorer extends LuceneTestCase { @@ -34,9 +28,7 @@ private static class FakeScorer extends Scorer { public float maxScore, minCompetitiveScore; - protected FakeScorer(Weight weight) { - super(weight); - } + protected FakeScorer() {} @Override public DocIdSetIterator iterator() { @@ -65,27 +57,17 @@ public void setMinCompetitiveScore(float minScore) { } public void testPropagateMinCompetitiveScore() throws IOException { - Query query = new MatchAllDocsQuery(); - Weight weight = - query.createWeight(new IndexSearcher(new MultiReader()), ScoreMode.TOP_SCORES, 1f); - FakeScorer fakeScorer = new FakeScorer(weight); + FakeScorer fakeScorer = new FakeScorer(); QueryProfilerBreakdown profile = new QueryProfilerBreakdown(); - QueryProfilerWeight queryProfilerWeight = new QueryProfilerWeight(weight, profile); - QueryProfilerScorer queryProfilerScorer = - new QueryProfilerScorer(queryProfilerWeight, fakeScorer, profile); + QueryProfilerScorer queryProfilerScorer = new QueryProfilerScorer(fakeScorer, profile); queryProfilerScorer.setMinCompetitiveScore(0.42f); assertEquals(0.42f, fakeScorer.minCompetitiveScore, 0f); } public void testPropagateMaxScore() throws IOException { - Query query = new MatchAllDocsQuery(); - Weight weight = - query.createWeight(new IndexSearcher(new MultiReader()), ScoreMode.TOP_SCORES, 1f); - FakeScorer fakeScorer = new FakeScorer(weight); + FakeScorer fakeScorer = new FakeScorer(); QueryProfilerBreakdown profile = new QueryProfilerBreakdown(); - QueryProfilerWeight queryProfilerWeight = new QueryProfilerWeight(weight, profile); - QueryProfilerScorer queryProfilerScorer = - new QueryProfilerScorer(queryProfilerWeight, fakeScorer, profile); + QueryProfilerScorer queryProfilerScorer = new QueryProfilerScorer(fakeScorer, profile); queryProfilerScorer.setMinCompetitiveScore(0.42f); fakeScorer.maxScore = 42f; assertEquals(42f, queryProfilerScorer.getMaxScore(DocIdSetIterator.NO_MORE_DOCS), 0f); diff --git a/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestQueryProfilerWeight.java b/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestQueryProfilerWeight.java index 584fb364f1cf..41dc054a0756 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestQueryProfilerWeight.java +++ b/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestQueryProfilerWeight.java @@ -47,13 +47,12 @@ public Explanation explain(LeafReaderContext context, int doc) { @Override public ScorerSupplier scorerSupplier(LeafReaderContext context) { - Weight weight = this; return new ScorerSupplier() { private long cost = 0; @Override public Scorer get(long leadCost) { - return new Scorer(weight) { + return new Scorer() { @Override public DocIdSetIterator iterator() { return null; diff --git a/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestTermAutomatonQuery.java b/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestTermAutomatonQuery.java index 33d7bf829b8e..937bad87b433 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestTermAutomatonQuery.java +++ b/lucene/sandbox/src/test/org/apache/lucene/sandbox/search/TestTermAutomatonQuery.java @@ -609,10 +609,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti } final var scorer = new ConstantScoreScorer( - this, - score(), - scoreMode, - new BitSetIterator(bits, bits.approximateCardinality())); + score(), scoreMode, new BitSetIterator(bits, bits.approximateCardinality())); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/CompositeVerifyQuery.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/CompositeVerifyQuery.java index 98efed7b996f..b28c47c94c37 100644 --- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/CompositeVerifyQuery.java +++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/CompositeVerifyQuery.java @@ -106,7 +106,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti final TwoPhaseIterator predFuncValues = predicateValueSource.iterator(context, indexQueryScorer.iterator()); - final var scorer = new ConstantScoreScorer(this, score(), scoreMode, predFuncValues); + final var scorer = new ConstantScoreScorer(score(), scoreMode, predFuncValues); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/IntersectsRPTVerifyQuery.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/IntersectsRPTVerifyQuery.java index 90bbd91c5511..559a946d0969 100644 --- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/IntersectsRPTVerifyQuery.java +++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/composite/IntersectsRPTVerifyQuery.java @@ -113,7 +113,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti // If both sets are the same, there's nothing to verify; we needn't return a // TwoPhaseIterator if (result.approxDocIdSet == result.exactDocIdSet) { - s = new ConstantScoreScorer(this, score(), scoreMode, approxDISI); + s = new ConstantScoreScorer(score(), scoreMode, approxDISI); } exactIterator = result.exactDocIdSet.iterator(); assert exactIterator != null; @@ -148,7 +148,7 @@ public float matchCost() { } }; - s = new ConstantScoreScorer(this, score(), scoreMode, twoPhaseIterator); + s = new ConstantScoreScorer(score(), scoreMode, twoPhaseIterator); final Scorer scorer = s; return new DefaultScorerSupplier(scorer); } diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/AbstractPrefixTreeQuery.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/AbstractPrefixTreeQuery.java index 2877e8b04bbb..cb1195d18035 100644 --- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/AbstractPrefixTreeQuery.java +++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/prefix/AbstractPrefixTreeQuery.java @@ -99,7 +99,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti if (disi == null) { return null; } - final var scorer = new ConstantScoreScorer(this, score(), scoreMode, disi); + final var scorer = new ConstantScoreScorer(score(), scoreMode, disi); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/serialized/SerializedDVStrategy.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/serialized/SerializedDVStrategy.java index 05686569a7a9..5074b1ba47c3 100644 --- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/serialized/SerializedDVStrategy.java +++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/serialized/SerializedDVStrategy.java @@ -137,7 +137,7 @@ public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float bo public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { DocIdSetIterator approximation = DocIdSetIterator.all(context.reader().maxDoc()); TwoPhaseIterator it = predicateValueSource.iterator(context, approximation); - final var scorer = new ConstantScoreScorer(this, score(), scoreMode, it); + final var scorer = new ConstantScoreScorer(score(), scoreMode, it); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/vector/PointVectorStrategy.java b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/vector/PointVectorStrategy.java index d3ba8434e75a..13b9c10f18ab 100644 --- a/lucene/spatial-extras/src/java/org/apache/lucene/spatial/vector/PointVectorStrategy.java +++ b/lucene/spatial-extras/src/java/org/apache/lucene/spatial/vector/PointVectorStrategy.java @@ -287,7 +287,7 @@ public float matchCost() { return 100; // distance calculation can be heavy! } }; - final var scorer = new ConstantScoreScorer(this, score(), scoreMode, twoPhase); + final var scorer = new ConstantScoreScorer(score(), scoreMode, twoPhase); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInGeo3DShapeQuery.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInGeo3DShapeQuery.java index 399db5da4ed2..c7ee8877dfb5 100644 --- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInGeo3DShapeQuery.java +++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/PointInGeo3DShapeQuery.java @@ -106,8 +106,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti values.intersect(new PointInShapeIntersectVisitor(result, shape, shapeBounds)); - final var scorer = - new ConstantScoreScorer(this, score(), scoreMode, result.build().iterator()); + final var scorer = new ConstantScoreScorer(score(), scoreMode, result.build().iterator()); return new DefaultScorerSupplier(scorer); } diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingScorer.java b/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingScorer.java index fce7de3e02cb..8badba0d12b7 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingScorer.java +++ b/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingScorer.java @@ -24,7 +24,6 @@ import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.TwoPhaseIterator; -import org.apache.lucene.search.Weight; /** Wraps a Scorer with additional checks */ public class AssertingScorer extends Scorer { @@ -37,15 +36,11 @@ enum IteratorState { }; public static Scorer wrap( - Weight weight, - Random random, - Scorer other, - ScoreMode scoreMode, - boolean canCallMinCompetitiveScore) { + Random random, Scorer other, ScoreMode scoreMode, boolean canCallMinCompetitiveScore) { if (other == null) { return null; } - return new AssertingScorer(weight, random, other, scoreMode, canCallMinCompetitiveScore); + return new AssertingScorer(random, other, scoreMode, canCallMinCompetitiveScore); } final Random random; @@ -59,12 +54,7 @@ public static Scorer wrap( int lastShallowTarget = -1; private AssertingScorer( - Weight weight, - Random random, - Scorer in, - ScoreMode scoreMode, - boolean canCallMinCompetitiveScore) { - super(weight); + Random random, Scorer in, ScoreMode scoreMode, boolean canCallMinCompetitiveScore) { this.random = random; this.in = in; this.scoreMode = scoreMode; diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingWeight.java b/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingWeight.java index 68ec5fa3c27c..c25296b9a53f 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingWeight.java +++ b/lucene/test-framework/src/java/org/apache/lucene/tests/search/AssertingWeight.java @@ -72,7 +72,6 @@ public Scorer get(long leadCost) throws IOException { getCalled = true; assert leadCost >= 0 : leadCost; return AssertingScorer.wrap( - in, new Random(random.nextLong()), inScorerSupplier.get(leadCost), scoreMode, diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/search/BlockScoreQueryWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/tests/search/BlockScoreQueryWrapper.java index f56473d807b3..39e78e38964c 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/tests/search/BlockScoreQueryWrapper.java +++ b/lucene/test-framework/src/java/org/apache/lucene/tests/search/BlockScoreQueryWrapper.java @@ -122,7 +122,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti final float[] scores = ArrayUtil.copyOfSubArray(tmpScores, 0, i); final var scorer = - new Scorer(inWeight) { + new Scorer() { int i = 0; diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/search/BulkScorerWrapperScorer.java b/lucene/test-framework/src/java/org/apache/lucene/tests/search/BulkScorerWrapperScorer.java index e7476ecdcb87..d5fb7ed719cb 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/tests/search/BulkScorerWrapperScorer.java +++ b/lucene/test-framework/src/java/org/apache/lucene/tests/search/BulkScorerWrapperScorer.java @@ -23,7 +23,6 @@ import org.apache.lucene.search.LeafCollector; import org.apache.lucene.search.Scorable; import org.apache.lucene.search.Scorer; -import org.apache.lucene.search.Weight; /** A {@link BulkScorer}-backed scorer. */ public class BulkScorerWrapperScorer extends Scorer { @@ -39,8 +38,7 @@ public class BulkScorerWrapperScorer extends Scorer { private int bufferLength; /** Sole constructor. */ - public BulkScorerWrapperScorer(Weight weight, BulkScorer scorer, int bufferSize) { - super(weight); + public BulkScorerWrapperScorer(BulkScorer scorer, int bufferSize) { this.scorer = scorer; docs = new int[bufferSize]; scores = new float[bufferSize]; diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/search/RandomApproximationQuery.java b/lucene/test-framework/src/java/org/apache/lucene/tests/search/RandomApproximationQuery.java index 0ffe4c6f985f..11e7d704b697 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/tests/search/RandomApproximationQuery.java +++ b/lucene/test-framework/src/java/org/apache/lucene/tests/search/RandomApproximationQuery.java @@ -95,7 +95,7 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti return null; } else { final var subScorer = scorerSupplier.get(Long.MAX_VALUE); - scorer = new RandomApproximationScorer(in, subScorer, new Random(random.nextLong())); + scorer = new RandomApproximationScorer(subScorer, new Random(random.nextLong())); } return new DefaultScorerSupplier(scorer); } @@ -106,8 +106,7 @@ private static class RandomApproximationScorer extends Scorer { private final Scorer scorer; private final RandomTwoPhaseView twoPhaseView; - RandomApproximationScorer(Weight weight, Scorer scorer, Random random) { - super(weight); + RandomApproximationScorer(Scorer scorer, Random random) { this.scorer = scorer; this.twoPhaseView = new RandomTwoPhaseView(random, scorer.iterator()); } From 1d43c3add76b730af1afa1d9bc28b5975656d868 Mon Sep 17 00:00:00 2001 From: iamsanjay Date: Tue, 4 Jun 2024 13:49:12 +0530 Subject: [PATCH 3/5] Removed default ctor and weight param where not needed --- .../document/BaseShapeDocValuesQuery.java | 2 -- .../apache/lucene/document/SpatialQuery.java | 25 ++++++++----------- .../java/org/apache/lucene/search/Scorer.java | 1 - .../lucene/search/JustCompileSearch.java | 3 --- .../TestPositiveScoresOnlyCollector.java | 2 -- .../TestScoreCachingWrappingScorer.java | 2 -- 6 files changed, 10 insertions(+), 25 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/document/BaseShapeDocValuesQuery.java b/lucene/core/src/java/org/apache/lucene/document/BaseShapeDocValuesQuery.java index 03cbb3b2007e..9de956bb0391 100644 --- a/lucene/core/src/java/org/apache/lucene/document/BaseShapeDocValuesQuery.java +++ b/lucene/core/src/java/org/apache/lucene/document/BaseShapeDocValuesQuery.java @@ -25,7 +25,6 @@ import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.PointValues.Relation; import org.apache.lucene.search.ConstantScoreScorer; -import org.apache.lucene.search.ConstantScoreWeight; import org.apache.lucene.search.ScoreMode; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.ScorerSupplier; @@ -59,7 +58,6 @@ protected ScorerSupplier getScorerSupplier( LeafReader reader, SpatialVisitor spatialVisitor, ScoreMode scoreMode, - ConstantScoreWeight weight, float boost, float score) throws IOException { diff --git a/lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java b/lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java index 57e93a62e6f5..811591d9a1cd 100644 --- a/lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java +++ b/lucene/core/src/java/org/apache/lucene/document/SpatialQuery.java @@ -150,7 +150,6 @@ protected ScorerSupplier getScorerSupplier( LeafReader reader, SpatialVisitor spatialVisitor, ScoreMode scoreMode, - ConstantScoreWeight weight, float boost, float score) throws IOException { @@ -199,7 +198,7 @@ && hasAnyHits(spatialVisitor, queryRelation, values) == false) { return new RelationScorerSupplier(values, spatialVisitor, queryRelation, field) { @Override public Scorer get(long leadCost) throws IOException { - return getScorer(reader, weight, score, scoreMode); + return getScorer(reader, score, scoreMode); } }; } @@ -214,7 +213,7 @@ public final Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, fl @Override public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException { final LeafReader reader = context.reader(); - return getScorerSupplier(reader, spatialVisitor, scoreMode, this, boost, score()); + return getScorerSupplier(reader, spatialVisitor, scoreMode, boost, score()); } @Override @@ -290,18 +289,17 @@ private abstract static class RelationScorerSupplier extends ScorerSupplier { } protected Scorer getScorer( - final LeafReader reader, final Weight weight, final float boost, final ScoreMode scoreMode) - throws IOException { + final LeafReader reader, final float boost, final ScoreMode scoreMode) throws IOException { switch (queryRelation) { case INTERSECTS: - return getSparseScorer(reader, weight, boost, scoreMode); + return getSparseScorer(reader, boost, scoreMode); case CONTAINS: - return getContainsDenseScorer(reader, weight, boost, scoreMode); + return getContainsDenseScorer(reader, boost, scoreMode); case WITHIN: case DISJOINT: return values.getDocCount() == values.size() - ? getSparseScorer(reader, weight, boost, scoreMode) - : getDenseScorer(reader, weight, boost, scoreMode); + ? getSparseScorer(reader, boost, scoreMode) + : getDenseScorer(reader, boost, scoreMode); default: throw new IllegalArgumentException("Unsupported query type :[" + queryRelation + "]"); } @@ -309,8 +307,7 @@ protected Scorer getScorer( /** Scorer used for INTERSECTS and single value points */ private Scorer getSparseScorer( - final LeafReader reader, final Weight weight, final float boost, final ScoreMode scoreMode) - throws IOException { + final LeafReader reader, final float boost, final ScoreMode scoreMode) throws IOException { if (queryRelation == QueryRelation.DISJOINT && values.getDocCount() == reader.maxDoc() && values.getDocCount() == values.size() @@ -342,8 +339,7 @@ && cost() > reader.maxDoc() / 2) { } /** Scorer used for WITHIN and DISJOINT */ - private Scorer getDenseScorer( - LeafReader reader, Weight weight, final float boost, ScoreMode scoreMode) + private Scorer getDenseScorer(LeafReader reader, final float boost, ScoreMode scoreMode) throws IOException { final FixedBitSet result = new FixedBitSet(reader.maxDoc()); final long[] cost; @@ -371,8 +367,7 @@ private Scorer getDenseScorer( return new ConstantScoreScorer(boost, scoreMode, iterator); } - private Scorer getContainsDenseScorer( - LeafReader reader, Weight weight, final float boost, ScoreMode scoreMode) + private Scorer getContainsDenseScorer(LeafReader reader, final float boost, ScoreMode scoreMode) throws IOException { final FixedBitSet result = new FixedBitSet(reader.maxDoc()); final long[] cost = new long[] {0}; diff --git a/lucene/core/src/java/org/apache/lucene/search/Scorer.java b/lucene/core/src/java/org/apache/lucene/search/Scorer.java index 825a28cb5576..7da2420207ec 100644 --- a/lucene/core/src/java/org/apache/lucene/search/Scorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/Scorer.java @@ -25,7 +25,6 @@ * increasing order of doc id. */ public abstract class Scorer extends Scorable { - protected Scorer() {} /** Returns the doc ID that is currently being scored. */ public abstract int docID(); diff --git a/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java b/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java index 35cb547190ff..df30c5ee0051 100644 --- a/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java +++ b/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java @@ -164,9 +164,6 @@ public int hashCode() { } static final class JustCompileScorer extends Scorer { - - protected JustCompileScorer() {} - @Override public float score() { throw new UnsupportedOperationException(UNSUPPORTED_MSG); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java b/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java index 1a9245e6f78c..c128945bd42f 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java @@ -28,8 +28,6 @@ public class TestPositiveScoresOnlyCollector extends LuceneTestCase { private static final class SimpleScorer extends Scorer { private int idx = -1; - public SimpleScorer() {} - @Override public float score() { return idx == scores.length ? Float.NaN : scores[idx]; diff --git a/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java index 6c6a30d9df46..6131541caa36 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java @@ -29,8 +29,6 @@ private static final class SimpleScorer extends Scorer { private int idx = 0; private int doc = -1; - public SimpleScorer() {} - @Override public float score() { // advance idx on purpose, so that consecutive calls to score will get From 510343bc49be3a570704249b273b2a8913741eb6 Mon Sep 17 00:00:00 2001 From: iamsanjay Date: Wed, 5 Jun 2024 20:53:04 +0530 Subject: [PATCH 4/5] tidy --- lucene/CHANGES.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 1c0acd389c52..62eeaba1c84e 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -468,8 +468,7 @@ API Changes IndexSearcher#search(Query, CollectorManager) for TopFieldCollectorManager and TopScoreDocCollectorManager. (Zach Chen, Adrien Grand, Michael McCandless, Greg Miller, Luca Cavanna) -* GITHUB#12854: Mark DrillSideways#createDrillDownFacetsCollector as @ -Deprecated. (Greg Miller) +* GITHUB#12854: Mark DrillSideways#createDrillDownFacetsCollector as @Deprecated. (Greg Miller) New Features --------------------- From 1cdebc8454aa6c5f602c4520da6187af3225b6a0 Mon Sep 17 00:00:00 2001 From: iamsanjay Date: Wed, 5 Jun 2024 21:07:11 +0530 Subject: [PATCH 5/5] Added migrate docs --- lucene/MIGRATE.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lucene/MIGRATE.md b/lucene/MIGRATE.md index 91d0a6e21fea..64de353b1538 100644 --- a/lucene/MIGRATE.md +++ b/lucene/MIGRATE.md @@ -780,8 +780,16 @@ The `Weight#scorerSupplier` method is now declared abstract, compelling child cl interface. Additionally, `Weight#scorer` is now declared final, with its implementation being delegated to `Weight#scorerSupplier` for the scorer. -### `Scorer#getWeight` is removed (GITHUB#13410) +### Reference to `weight` is removed from Scorer (GITHUB#13410) -The `Scorer#getWeight` method has been removed. Callers must now keep track of the Weight instance -that created the Scorer if they need it instead of relying on `Scorer`. +The `weight` has been removed from the Scorer class. Consequently, the constructor, `Scorer(Weight)`,and a getter, +`Scorer#getWeight`, has also been eliminated. References to weight have also been removed from nearly all the subclasses +of Scorer, including ConstantScoreScorer, TermScorer, and others. + +Additionally, several APIs have been modified to remove the weight reference, as it is no longer necessary. +Specifically, the method `FunctionValues#getScorer(Weight weight, LeafReaderContext readerContext)` has been updated to +`FunctionValues#getScorer(LeafReaderContext readerContext)`. + +Callers must now keep track of the Weight instance that created the Scorer if they need it, instead of relying on +Scorer.