Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Scorer#getWeight #13440

Merged
merged 7 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------

Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo the new line?


New Features
---------------------
Expand Down
6 changes: 6 additions & 0 deletions lucene/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

9 changes: 0 additions & 9 deletions lucene/core/src/java/org/apache/lucene/search/Scorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Scorer.ChildScorable> childScorers = s.getChildren();
setScorerCalled.set(true);
assertEquals(2, childScorers.size());
public void setWeight(Weight weight) {
BooleanQuery query = (BooleanQuery) weight.getQuery();
List<BooleanClause> clauseList = query.clauses();
assertEquals(2, clauseList.size());
Set<String> 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());
}
Expand All @@ -164,6 +164,13 @@ public void setScorer(Scorable s) throws IOException {
assertTrue(terms.contains("b"));
}

@Override
public void setScorer(Scorable s) throws IOException {
Collection<Scorer.ChildScorable> childScorers = s.getChildren();
setScorerCalled.set(true);
assertEquals(2, childScorers.size());
}

@Override
public void collect(int doc) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
Loading