mirror of https://github.com/apache/lucene.git
Remove unchecked Scorable -> Scorer cast in lucene/monitor. (#13405)
While doing an unrelated refactoring, I got hit by this unchecked cast, which is incorrecw when the presearcher query produces some specialized `BulkScorer`.
This commit is contained in:
parent
8773725ac0
commit
9ecf566cca
|
@ -34,8 +34,6 @@ import org.apache.lucene.search.Matches;
|
|||
import org.apache.lucene.search.MatchesIterator;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.ScoreMode;
|
||||
import org.apache.lucene.search.Scorer;
|
||||
import org.apache.lucene.search.Weight;
|
||||
|
||||
/**
|
||||
* A Monitor contains a set of {@link Query} objects with associated IDs, and efficiently matches
|
||||
|
@ -377,9 +375,7 @@ public class Monitor implements Closeable {
|
|||
@Override
|
||||
public void matchQuery(final String id, QueryCacheEntry query, QueryIndex.DataValues dataValues)
|
||||
throws IOException {
|
||||
Scorer scorer = ((Scorer) dataValues.scorer);
|
||||
Weight w = scorer.getWeight();
|
||||
Matches matches = w.matches(dataValues.ctx, scorer.docID());
|
||||
Matches matches = dataValues.weight.matches(dataValues.ctx, dataValues.docID);
|
||||
for (String field : matches) {
|
||||
MatchesIterator mi = matches.getMatches(field);
|
||||
while (mi.next()) {
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.apache.lucene.search.Scorable;
|
|||
import org.apache.lucene.search.ScoreMode;
|
||||
import org.apache.lucene.search.SearcherManager;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
import org.apache.lucene.search.Weight;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.BytesRefHash;
|
||||
|
||||
|
@ -121,8 +122,10 @@ abstract class QueryIndex implements Closeable {
|
|||
SortedDocValues queryId;
|
||||
SortedDocValues cacheId;
|
||||
BinaryDocValues mq;
|
||||
Weight weight;
|
||||
Scorable scorer;
|
||||
LeafReaderContext ctx;
|
||||
int docID;
|
||||
|
||||
void advanceTo(int doc) throws IOException {
|
||||
queryId.advanceExact(doc);
|
||||
|
@ -130,6 +133,7 @@ abstract class QueryIndex implements Closeable {
|
|||
if (mq != null) {
|
||||
mq.advanceExact(doc);
|
||||
}
|
||||
this.docID = doc;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -155,6 +155,11 @@ class ReadonlyQueryIndex extends QueryIndex {
|
|||
this.decomposer = decomposer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeight(Weight weight) {
|
||||
this.dataValues.weight = weight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScorer(Scorable scorer) {
|
||||
this.dataValues.scorer = scorer;
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.apache.lucene.search.Scorable;
|
|||
import org.apache.lucene.search.ScoreMode;
|
||||
import org.apache.lucene.search.SearcherManager;
|
||||
import org.apache.lucene.search.SimpleCollector;
|
||||
import org.apache.lucene.search.Weight;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.apache.lucene.util.NamedThreadFactory;
|
||||
|
@ -363,6 +364,11 @@ class WritableQueryIndex extends QueryIndex {
|
|||
this.matcher = matcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeight(Weight weight) {
|
||||
this.dataValues.weight = weight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScorer(Scorable scorer) {
|
||||
this.dataValues.scorer = scorer;
|
||||
|
|
|
@ -42,7 +42,7 @@ public class TestPresearcherMatchCollector extends MonitorTestBase {
|
|||
PresearcherMatches<QueryMatch> matches = monitor.debug(doc, QueryMatch.SIMPLE_MATCHER);
|
||||
|
||||
assertNotNull(matches.match("1", 0));
|
||||
assertEquals(" field:test", matches.match("1", 0).presearcherMatches);
|
||||
assertEquals(" field:(foo test)", matches.match("1", 0).presearcherMatches);
|
||||
assertNotNull(matches.match("1", 0).queryMatch);
|
||||
|
||||
assertNotNull(matches.match("2", 0));
|
||||
|
@ -51,7 +51,7 @@ public class TestPresearcherMatchCollector extends MonitorTestBase {
|
|||
MatcherAssert.assertThat(pm, containsString("f2:(quuz)"));
|
||||
|
||||
assertNotNull(matches.match("3", 0));
|
||||
assertEquals(" field:foo", matches.match("3", 0).presearcherMatches);
|
||||
assertEquals(" field:(foo test)", matches.match("3", 0).presearcherMatches);
|
||||
assertNull(matches.match("3", 0).queryMatch);
|
||||
|
||||
assertNull(matches.match("4", 0));
|
||||
|
|
Loading…
Reference in New Issue