mirror of
https://github.com/apache/lucene.git
synced 2025-03-04 07:19:18 +00:00
LUCENE-6278: Remove Scorer.freq()
This commit is contained in:
parent
cfea3d5e83
commit
183571c085
@ -57,6 +57,8 @@ API Changes
|
||||
* LUCENE-8014: Similarity.computeSlopFactor() and
|
||||
Similarity.computePayloadFactor() have been deprecated. (Alan Woodward)
|
||||
|
||||
* LUCENE-6278: Scorer.freq() has been removed (Alan Woodward)
|
||||
|
||||
Bug Fixes
|
||||
|
||||
* LUCENE-7991: KNearestNeighborDocumentClassifier.knnSearch no longer applies
|
||||
|
@ -450,7 +450,6 @@ final class Sorter {
|
||||
|
||||
float score;
|
||||
int doc = -1;
|
||||
int freq = 1;
|
||||
|
||||
@Override
|
||||
public int docID() {
|
||||
@ -461,11 +460,6 @@ final class Sorter {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return freq;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float score() throws IOException {
|
||||
return score;
|
||||
|
@ -134,10 +134,6 @@ final class Boolean2ScorerSupplier extends ScorerSupplier {
|
||||
public float score() throws IOException {
|
||||
return 0f;
|
||||
}
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -182,7 +182,6 @@ final class BooleanScorer extends BulkScorer {
|
||||
final FakeScorer fakeScorer = this.fakeScorer;
|
||||
final Bucket bucket = buckets[i];
|
||||
if (bucket.freq >= minShouldMatch) {
|
||||
fakeScorer.freq = bucket.freq;
|
||||
fakeScorer.score = (float) bucket.score;
|
||||
final int doc = base | i;
|
||||
fakeScorer.doc = doc;
|
||||
|
@ -72,9 +72,6 @@ public abstract class CachingCollector extends FilterCollector {
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int freq() { throw new UnsupportedOperationException(); }
|
||||
|
||||
}
|
||||
|
||||
private static class NoScoreCachingCollector extends CachingCollector {
|
||||
|
@ -61,11 +61,6 @@ class ConjunctionScorer extends Scorer {
|
||||
return (float) sum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() {
|
||||
return scorers.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ChildScorer> getChildren() {
|
||||
ArrayList<ChildScorer> children = new ArrayList<>();
|
||||
|
@ -94,10 +94,6 @@ public final class ConstantScoreQuery extends Query {
|
||||
public float score() throws IOException {
|
||||
return theScore;
|
||||
}
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -141,10 +137,6 @@ public final class ConstantScoreQuery extends Query {
|
||||
return score;
|
||||
}
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return 1;
|
||||
}
|
||||
@Override
|
||||
public Collection<ChildScorer> getChildren() {
|
||||
return Collections.singleton(new ChildScorer(innerScorer, "constant"));
|
||||
}
|
||||
|
@ -73,10 +73,5 @@ public final class ConstantScoreScorer extends Scorer {
|
||||
return score;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -175,16 +175,6 @@ abstract class DisjunctionScorer extends Scorer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int freq() throws IOException {
|
||||
DisiWrapper subMatches = getSubMatches();
|
||||
int freq = 1;
|
||||
for (DisiWrapper w = subMatches.next; w != null; w = w.next) {
|
||||
freq += 1;
|
||||
}
|
||||
return freq;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final float score() throws IOException {
|
||||
return score(getSubMatches());
|
||||
|
@ -90,8 +90,7 @@ final class ExactPhraseScorer extends Scorer {
|
||||
return "ExactPhraseScorer(" + weight + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() {
|
||||
final int freq() {
|
||||
return freq;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@ import java.util.Collection;
|
||||
final class FakeScorer extends Scorer {
|
||||
float score;
|
||||
int doc = -1;
|
||||
int freq = 1;
|
||||
|
||||
public FakeScorer() {
|
||||
super(null);
|
||||
@ -35,11 +34,6 @@ final class FakeScorer extends Scorer {
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() {
|
||||
return freq;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float score() {
|
||||
return score;
|
||||
|
@ -59,11 +59,6 @@ public abstract class FilterScorer extends Scorer {
|
||||
return in.score();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return in.freq();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int docID() {
|
||||
return in.docID();
|
||||
|
@ -314,13 +314,6 @@ final class MinShouldMatchSumScorer extends Scorer {
|
||||
tailSize = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
// we need to know about all matches
|
||||
updateFreq();
|
||||
return freq;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float score() throws IOException {
|
||||
// we need to know about all matches
|
||||
|
@ -302,7 +302,7 @@ public class MultiPhraseQuery extends Query {
|
||||
if (scorer != null) {
|
||||
int newDoc = scorer.iterator().advance(doc);
|
||||
if (newDoc == doc) {
|
||||
float freq = slop == 0 ? scorer.freq() : ((SloppyPhraseScorer)scorer).sloppyFreq();
|
||||
float freq = slop == 0 ? ((ExactPhraseScorer)scorer).freq() : ((SloppyPhraseScorer)scorer).sloppyFreq();
|
||||
SimScorer docScorer = similarity.simScorer(stats, context);
|
||||
Explanation freqExplanation = Explanation.match(freq, "phraseFreq=" + freq);
|
||||
Explanation scoreExplanation = docScorer.explain(doc, freqExplanation);
|
||||
|
@ -458,7 +458,7 @@ public class PhraseQuery extends Query {
|
||||
if (scorer != null) {
|
||||
int newDoc = scorer.iterator().advance(doc);
|
||||
if (newDoc == doc) {
|
||||
float freq = slop == 0 ? scorer.freq() : ((SloppyPhraseScorer)scorer).sloppyFreq();
|
||||
float freq = slop == 0 ? ((ExactPhraseScorer)scorer).freq() : ((SloppyPhraseScorer)scorer).sloppyFreq();
|
||||
SimScorer docScorer = similarity.simScorer(stats, context);
|
||||
Explanation freqExplanation = Explanation.match(freq, "phraseFreq=" + freq);
|
||||
Explanation scoreExplanation = docScorer.explain(doc, freqExplanation);
|
||||
|
@ -59,8 +59,7 @@ public abstract class Query {
|
||||
* <p>
|
||||
* Only implemented by primitive queries, which re-write to themselves.
|
||||
*
|
||||
* @param needsScores True if document scores ({@link Scorer#score}) or match
|
||||
* frequencies ({@link Scorer#freq}) are needed.
|
||||
* @param needsScores True if document scores ({@link Scorer#score}) are needed.
|
||||
* @param boost The boost that is propagated by the parent queries.
|
||||
*/
|
||||
public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
|
||||
|
@ -71,11 +71,6 @@ class ReqExclScorer extends Scorer {
|
||||
return reqApproximation.docID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return reqScorer.freq();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float score() throws IOException {
|
||||
return reqScorer.score(); // reqScorer may be null when next() or skipTo() already return false
|
||||
|
@ -85,13 +85,6 @@ class ReqOptSumScorer extends Scorer {
|
||||
return score;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
// we might have deferred advance()
|
||||
score();
|
||||
return optIterator.docID() == reqScorer.docID() ? 2 : 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ChildScorer> getChildren() {
|
||||
ArrayList<ChildScorer> children = new ArrayList<>(2);
|
||||
|
@ -67,9 +67,6 @@ public abstract class Scorer {
|
||||
*/
|
||||
public abstract float score() throws IOException;
|
||||
|
||||
/** Returns the freq of this Scorer on the current document */
|
||||
public abstract int freq() throws IOException;
|
||||
|
||||
/** returns parent Weight
|
||||
* @lucene.experimental
|
||||
*/
|
||||
|
@ -516,8 +516,7 @@ final class SloppyPhraseScorer extends Scorer {
|
||||
return tg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() {
|
||||
int freq() {
|
||||
return numMatches;
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ public final class SynonymQuery extends Query {
|
||||
freq = synScorer.tf(synScorer.getSubMatches());
|
||||
} else {
|
||||
assert scorer instanceof TermScorer;
|
||||
freq = scorer.freq();
|
||||
freq = ((TermScorer)scorer).freq();
|
||||
}
|
||||
SimScorer docScorer = similarity.simScorer(simWeight, context);
|
||||
Explanation freqExplanation = Explanation.match(freq, "termFreq=" + freq);
|
||||
@ -238,7 +238,7 @@ public final class SynonymQuery extends Query {
|
||||
final int tf(DisiWrapper topList) throws IOException {
|
||||
int tf = 0;
|
||||
for (DisiWrapper w = topList; w != null; w = w.next) {
|
||||
tf += w.scorer.freq();
|
||||
tf += ((TermScorer)w.scorer).freq();
|
||||
}
|
||||
return tf;
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ public class TermQuery extends Query {
|
||||
|
||||
@Override
|
||||
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
|
||||
Scorer scorer = scorer(context);
|
||||
TermScorer scorer = (TermScorer) scorer(context);
|
||||
if (scorer != null) {
|
||||
int newDoc = scorer.iterator().advance(doc);
|
||||
if (newDoc == doc) {
|
||||
|
@ -50,8 +50,7 @@ final class TermScorer extends Scorer {
|
||||
return postingsEnum.docID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
final int freq() throws IOException {
|
||||
return postingsEnum.freq();
|
||||
}
|
||||
|
||||
|
@ -405,12 +405,6 @@
|
||||
* {@link org.apache.lucene.search.similarities.Similarity.SimScorer#score(int, float) SimScorer.score(int doc, float freq)}.
|
||||
* </li>
|
||||
* <li>
|
||||
* {@link org.apache.lucene.search.Scorer#freq freq()} — Returns the number of matches
|
||||
* for the current document. This value can be determined in any appropriate way for an application. For instance, the
|
||||
* {@link org.apache.lucene.search.TermScorer TermScorer} simply defers to the term frequency from the inverted index:
|
||||
* {@link org.apache.lucene.index.PostingsEnum#freq PostingsEnum.freq()}.
|
||||
* </li>
|
||||
* <li>
|
||||
* {@link org.apache.lucene.search.Scorer#getChildren getChildren()} — Returns any child subscorers
|
||||
* underneath this scorer. This allows for users to navigate the scorer hierarchy and receive more fine-grained
|
||||
* details on the scoring process.
|
||||
|
@ -134,12 +134,6 @@ public class SpanScorer extends Scorer {
|
||||
return scoreCurrentDoc();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int freq() throws IOException {
|
||||
ensureFreq();
|
||||
return numMatches;
|
||||
}
|
||||
|
||||
/** Returns the intermediate "sloppy freq" adjusted for edit distance
|
||||
* @lucene.internal */
|
||||
final float sloppyFreq() throws IOException {
|
||||
|
@ -175,11 +175,6 @@ final class JustCompileSearch {
|
||||
throw new UnsupportedOperationException(UNSUPPORTED_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() {
|
||||
throw new UnsupportedOperationException(UNSUPPORTED_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int docID() {
|
||||
throw new UnsupportedOperationException(UNSUPPORTED_MSG);
|
||||
|
@ -50,11 +50,6 @@ public class TestBoolean2ScorerSupplier extends LuceneTestCase {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocIdSetIterator iterator() {
|
||||
return it;
|
||||
|
@ -30,6 +30,7 @@ import org.apache.lucene.analysis.MockAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field.Store;
|
||||
import org.apache.lucene.document.TextField;
|
||||
import org.apache.lucene.index.FieldInvertState;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
@ -37,7 +38,9 @@ import org.apache.lucene.index.RandomIndexWriter;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.BooleanClause.Occur;
|
||||
import org.apache.lucene.search.Scorer.ChildScorer;
|
||||
import org.apache.lucene.search.similarities.BasicStats;
|
||||
import org.apache.lucene.search.similarities.ClassicSimilarity;
|
||||
import org.apache.lucene.search.similarities.Similarity;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
|
||||
@ -73,7 +76,7 @@ public class TestBooleanQueryVisitSubscorers extends LuceneTestCase {
|
||||
searcher = new IndexSearcher(reader);
|
||||
searcher.setSimilarity(new ClassicSimilarity());
|
||||
scorerSearcher = new ScorerIndexSearcher(reader);
|
||||
scorerSearcher.setSimilarity(new ClassicSimilarity());
|
||||
scorerSearcher.setSimilarity(new CountingSimilarity());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -113,7 +116,7 @@ public class TestBooleanQueryVisitSubscorers extends LuceneTestCase {
|
||||
BooleanQuery.Builder bq = new BooleanQuery.Builder();
|
||||
bq.add(new TermQuery(new Term(F2, "lucene")), BooleanClause.Occur.MUST);
|
||||
bq.add(new TermQuery(new Term(F2, "is")), BooleanClause.Occur.MUST);
|
||||
Map<Integer,Integer> tfs = getDocCounts(searcher, bq.build());
|
||||
Map<Integer,Integer> tfs = getDocCounts(scorerSearcher, bq.build());
|
||||
assertEquals(3, tfs.size()); // 3 documents
|
||||
assertEquals(2, tfs.get(0).intValue()); // f2:lucene + f2:is
|
||||
assertEquals(3, tfs.get(1).intValue()); // f2:is + f2:is + f2:lucene
|
||||
@ -159,7 +162,7 @@ public class TestBooleanQueryVisitSubscorers extends LuceneTestCase {
|
||||
int freq = 0;
|
||||
for(Scorer scorer : tqsSet) {
|
||||
if (doc == scorer.docID()) {
|
||||
freq += scorer.freq();
|
||||
freq += scorer.score();
|
||||
}
|
||||
}
|
||||
docCounts.put(doc + docBase, freq);
|
||||
@ -317,4 +320,28 @@ public class TestBooleanQueryVisitSubscorers extends LuceneTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
// 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 SimWeight computeWeight(float boost, CollectionStatistics collectionStats, TermStatistics... termStats) {
|
||||
return new BasicStats("", boost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimScorer simScorer(SimWeight weight, LeafReaderContext context) throws IOException {
|
||||
return new SimScorer() {
|
||||
@Override
|
||||
public float score(int doc, float freq) throws IOException {
|
||||
return freq;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,9 +33,6 @@ public class TestCachingCollector extends LuceneTestCase {
|
||||
|
||||
@Override
|
||||
public float score() throws IOException { return 0; }
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException { return 0; }
|
||||
|
||||
@Override
|
||||
public int docID() { return 0; }
|
||||
|
@ -146,11 +146,6 @@ public class TestConjunctionDISI extends LuceneTestCase {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,6 @@ public class TestMinShouldMatch2 extends LuceneTestCase {
|
||||
DocIdSetIterator actualIt = actual.iterator();
|
||||
while ((doc = expectedIt.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
|
||||
assertEquals(doc, actualIt.nextDoc());
|
||||
assertEquals(expected.freq(), actual.freq());
|
||||
float expectedScore = expected.score();
|
||||
float actualScore = actual.score();
|
||||
assertEquals(expectedScore, actualScore, CheckHits.explainToleranceDelta(expectedScore, actualScore));
|
||||
@ -169,7 +168,6 @@ public class TestMinShouldMatch2 extends LuceneTestCase {
|
||||
int doc;
|
||||
while ((doc = expectedIt.advance(prevDoc+amount)) != DocIdSetIterator.NO_MORE_DOCS) {
|
||||
assertEquals(doc, actualIt.advance(prevDoc+amount));
|
||||
assertEquals(expected.freq(), actual.freq());
|
||||
float expectedScore = expected.score();
|
||||
float actualScore = actual.score();
|
||||
assertEquals(expectedScore, actualScore, CheckHits.explainToleranceDelta(expectedScore, actualScore));
|
||||
@ -347,11 +345,6 @@ public class TestMinShouldMatch2 extends LuceneTestCase {
|
||||
return (float)score;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return currentMatched;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int docID() {
|
||||
return currentDoc;
|
||||
|
@ -36,10 +36,6 @@ public class TestPositiveScoresOnlyCollector extends LuceneTestCase {
|
||||
@Override public float score() {
|
||||
return idx == scores.length ? Float.NaN : scores[idx];
|
||||
}
|
||||
|
||||
@Override public int freq() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override public int docID() { return idx; }
|
||||
|
||||
|
@ -437,11 +437,6 @@ public class TestQueryRescorer extends LuceneTestCase {
|
||||
return docID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocIdSetIterator iterator() {
|
||||
return new DocIdSetIterator() {
|
||||
|
@ -42,10 +42,6 @@ public class TestScoreCachingWrappingScorer extends LuceneTestCase {
|
||||
// once per document.
|
||||
return idx == scores.length ? Float.NaN : scores[idx++];
|
||||
}
|
||||
|
||||
@Override public int freq() throws IOException {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override public int docID() { return doc; }
|
||||
|
||||
|
@ -187,12 +187,18 @@ public class TestSloppyPhraseQuery extends LuceneTestCase {
|
||||
@Override
|
||||
public void setScorer(Scorer scorer) throws IOException {
|
||||
this.scorer = scorer;
|
||||
while (this.scorer instanceof AssertingScorer) {
|
||||
this.scorer = ((AssertingScorer)this.scorer).getIn();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collect(int doc) throws IOException {
|
||||
totalHits++;
|
||||
max = Math.max(max, scorer.freq());
|
||||
if (scorer instanceof SloppyPhraseScorer)
|
||||
max = Math.max(max, ((SloppyPhraseScorer)scorer).freq());
|
||||
else
|
||||
max = Math.max(max, ((ExactPhraseScorer)scorer).freq());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -209,11 +215,14 @@ public class TestSloppyPhraseQuery extends LuceneTestCase {
|
||||
@Override
|
||||
public void setScorer(Scorer scorer) {
|
||||
this.scorer = scorer;
|
||||
while (this.scorer instanceof AssertingScorer) {
|
||||
this.scorer = ((AssertingScorer)this.scorer).getIn();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collect(int doc) throws IOException {
|
||||
assertFalse(Float.isInfinite(scorer.freq()));
|
||||
assertFalse(Float.isInfinite(((SloppyPhraseScorer)scorer).freq()));
|
||||
assertFalse(Float.isInfinite(scorer.score()));
|
||||
}
|
||||
|
||||
|
@ -17,16 +17,28 @@
|
||||
package org.apache.lucene.search;
|
||||
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.lucene.analysis.MockAnalyzer;
|
||||
import org.apache.lucene.document.*;
|
||||
import org.apache.lucene.index.*;
|
||||
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.RandomIndexWriter;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.BooleanClause.Occur;
|
||||
import org.apache.lucene.search.Scorer.ChildScorer;
|
||||
import org.apache.lucene.store.*;
|
||||
import org.apache.lucene.util.*;
|
||||
import org.apache.lucene.search.similarities.BasicStats;
|
||||
import org.apache.lucene.search.similarities.Similarity;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@ -54,6 +66,7 @@ public class TestSubScorerFreqs extends LuceneTestCase {
|
||||
}
|
||||
|
||||
s = newSearcher(w.getReader());
|
||||
s.setSimilarity(new CountingSimilarity());
|
||||
w.close();
|
||||
}
|
||||
|
||||
@ -100,7 +113,7 @@ public class TestSubScorerFreqs extends LuceneTestCase {
|
||||
for (Map.Entry<Query, Scorer> ent : subScorers.entrySet()) {
|
||||
Scorer value = ent.getValue();
|
||||
int matchId = value.docID();
|
||||
freqs.put(ent.getKey(), matchId == doc ? value.freq() : 0.0f);
|
||||
freqs.put(ent.getKey(), matchId == doc ? value.score() : 0.0f);
|
||||
}
|
||||
docCounts.put(doc + docBase, freqs);
|
||||
super.collect(doc);
|
||||
@ -208,4 +221,28 @@ public class TestSubScorerFreqs extends LuceneTestCase {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 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 SimWeight computeWeight(float boost, CollectionStatistics collectionStats, TermStatistics... termStats) {
|
||||
return new BasicStats("", boost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimScorer simScorer(SimWeight weight, LeafReaderContext context) throws IOException {
|
||||
return new SimScorer() {
|
||||
@Override
|
||||
public float score(int doc, float freq) throws IOException {
|
||||
return freq;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -225,11 +225,6 @@ public class TestTopFieldCollector extends LuceneTestCase {
|
||||
return scorer.score();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return scorer.freq();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int docID() {
|
||||
return scorer.docID();
|
||||
|
@ -26,7 +26,6 @@ class FakeScorer extends Scorer {
|
||||
|
||||
float score;
|
||||
int doc = -1;
|
||||
int freq = 1;
|
||||
|
||||
FakeScorer() {
|
||||
super(null);
|
||||
@ -42,11 +41,6 @@ class FakeScorer extends Scorer {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return freq;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float score() throws IOException {
|
||||
return score;
|
||||
|
@ -591,11 +591,6 @@ class DrillSidewaysScorer extends BulkScorer {
|
||||
return collectDocID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() {
|
||||
return 1+dims.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocIdSetIterator iterator() {
|
||||
throw new UnsupportedOperationException("FakeScorer doesn't support nextDoc()");
|
||||
|
@ -25,7 +25,6 @@ class FakeScorer extends Scorer {
|
||||
|
||||
float score;
|
||||
int doc = -1;
|
||||
int freq = 1;
|
||||
|
||||
FakeScorer() {
|
||||
super(null);
|
||||
@ -41,11 +40,6 @@ class FakeScorer extends Scorer {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return freq;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float score() throws IOException {
|
||||
return score;
|
||||
|
@ -57,11 +57,6 @@ abstract class BaseGlobalOrdinalScorer extends Scorer {
|
||||
return createTwoPhaseIterator(approximation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected abstract TwoPhaseIterator createTwoPhaseIterator(DocIdSetIterator approximation);
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ class FakeScorer extends Scorer {
|
||||
|
||||
float score;
|
||||
int doc = -1;
|
||||
int freq = 1;
|
||||
|
||||
FakeScorer() {
|
||||
super(null);
|
||||
@ -41,11 +40,6 @@ class FakeScorer extends Scorer {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return freq;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float score() throws IOException {
|
||||
return score;
|
||||
|
@ -183,11 +183,6 @@ public class ParentChildrenBlockJoinQuery extends Query {
|
||||
return childrenScorer.score();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return childrenScorer.freq();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocIdSetIterator iterator() {
|
||||
return it;
|
||||
|
@ -169,11 +169,6 @@ abstract class PointInSetIncludingScoreQuery extends Query {
|
||||
return scores[docID()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int docID() {
|
||||
return disi.docID();
|
||||
|
@ -185,11 +185,6 @@ class TermsIncludingScoreQuery extends Query {
|
||||
return scores[docID()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int docID() {
|
||||
return matchingDocsIterator.docID();
|
||||
|
@ -129,7 +129,6 @@ public class ToChildBlockJoinQuery extends Query {
|
||||
private final boolean doScores;
|
||||
|
||||
private float parentScore;
|
||||
private int parentFreq = 1;
|
||||
|
||||
private int childDoc = -1;
|
||||
private int parentDoc = 0;
|
||||
@ -199,7 +198,6 @@ public class ToChildBlockJoinQuery extends Query {
|
||||
if (childDoc < parentDoc) {
|
||||
if (doScores) {
|
||||
parentScore = parentScorer.score();
|
||||
parentFreq = parentScorer.freq();
|
||||
}
|
||||
//System.out.println(" " + childDoc);
|
||||
return childDoc;
|
||||
@ -247,7 +245,6 @@ public class ToChildBlockJoinQuery extends Query {
|
||||
|
||||
if (doScores) {
|
||||
parentScore = parentScorer.score();
|
||||
parentFreq = parentScorer.freq();
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,11 +279,6 @@ public class ToChildBlockJoinQuery extends Query {
|
||||
public float score() throws IOException {
|
||||
return parentScore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return parentFreq;
|
||||
}
|
||||
|
||||
int getParentDoc() {
|
||||
return parentDoc;
|
||||
|
@ -236,7 +236,6 @@ public class ToParentBlockJoinQuery extends Query {
|
||||
private final ParentApproximation parentApproximation;
|
||||
private final ParentTwoPhase parentTwoPhase;
|
||||
private float score;
|
||||
private int freq;
|
||||
|
||||
public BlockJoinScorer(Weight weight, Scorer childScorer, BitSet parentBits, ScoreMode scoreMode) {
|
||||
super(weight);
|
||||
@ -286,12 +285,6 @@ public class ToParentBlockJoinQuery extends Query {
|
||||
setScoreAndFreq();
|
||||
return score;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
setScoreAndFreq();
|
||||
return freq;
|
||||
}
|
||||
|
||||
private void setScoreAndFreq() throws IOException {
|
||||
if (childApproximation.docID() >= parentApproximation.docID()) {
|
||||
@ -330,7 +323,6 @@ public class ToParentBlockJoinQuery extends Query {
|
||||
score /= freq;
|
||||
}
|
||||
this.score = (float) score;
|
||||
this.freq = freq;
|
||||
}
|
||||
|
||||
public Explanation explain(LeafReaderContext context, Weight childWeight) throws IOException {
|
||||
@ -350,7 +342,6 @@ public class ToParentBlockJoinQuery extends Query {
|
||||
}
|
||||
}
|
||||
|
||||
assert freq() == matches;
|
||||
return Explanation.match(score(), String.format(Locale.ROOT,
|
||||
"Score based on %d child docs in range from %d to %d, best match:", matches, start, end), bestChild
|
||||
);
|
||||
|
@ -123,11 +123,6 @@ public class FunctionQuery extends Query {
|
||||
return score>Float.NEGATIVE_INFINITY ? score : -Float.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public Explanation explain(int doc) throws IOException {
|
||||
float sc = boost * vals.floatVal(doc);
|
||||
|
||||
|
@ -106,11 +106,6 @@ public abstract class ValueSource {
|
||||
return score;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocIdSetIterator iterator() {
|
||||
throw new UnsupportedOperationException();
|
||||
|
@ -89,9 +89,4 @@ public abstract class ValueSourceScorer extends Scorer {
|
||||
return score > Float.NEGATIVE_INFINITY ? score : -Float.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ public class PayloadScoreQuery extends SpanQuery {
|
||||
if (scorer == null || scorer.iterator().advance(doc) != doc)
|
||||
return Explanation.noMatch("No match");
|
||||
|
||||
scorer.freq(); // force freq calculation
|
||||
scorer.score(); // force freq calculation
|
||||
Explanation payloadExpl = scorer.getPayloadExplanation();
|
||||
|
||||
if (includeSpanScore) {
|
||||
|
@ -200,12 +200,6 @@ final class CoveringScorer extends Scorer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
setTopListAndFreqIfNecessary();
|
||||
return freq;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float score() throws IOException {
|
||||
// we need to know about all matches
|
||||
|
@ -349,11 +349,6 @@ class TermAutomatonScorer extends Scorer {
|
||||
return "TermAutomatonScorer(" + weight + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() {
|
||||
return freq;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int docID() {
|
||||
return docID;
|
||||
@ -365,6 +360,11 @@ class TermAutomatonScorer extends Scorer {
|
||||
return docScorer.score(docID, freq);
|
||||
}
|
||||
|
||||
// for tests
|
||||
final int freq() {
|
||||
return freq;
|
||||
}
|
||||
|
||||
static class TermRunAutomaton extends RunAutomaton {
|
||||
public TermRunAutomaton(Automaton a, int termCount) {
|
||||
super(a, termCount);
|
||||
|
@ -262,59 +262,6 @@ public class TestTermAutomatonQuery extends LuceneTestCase {
|
||||
dir.close();
|
||||
}
|
||||
|
||||
public void testFreq() throws Exception {
|
||||
Directory dir = newDirectory();
|
||||
RandomIndexWriter w = new RandomIndexWriter(random(), dir);
|
||||
Document doc = new Document();
|
||||
// matches freq == 3
|
||||
doc.add(newTextField("field", "here comes the sun foo bar here comes another sun here comes shiny sun", Field.Store.NO));
|
||||
w.addDocument(doc);
|
||||
|
||||
doc = new Document();
|
||||
// doesn't match
|
||||
doc.add(newTextField("field", "here comes the other sun", Field.Store.NO));
|
||||
w.addDocument(doc);
|
||||
IndexReader r = w.getReader();
|
||||
IndexSearcher s = newSearcher(r);
|
||||
|
||||
TermAutomatonQuery q = new TermAutomatonQuery("field");
|
||||
int init = q.createState();
|
||||
int s1 = q.createState();
|
||||
q.addTransition(init, s1, "comes");
|
||||
int s2 = q.createState();
|
||||
q.addAnyTransition(s1, s2);
|
||||
int s3 = q.createState();
|
||||
q.setAccept(s3, true);
|
||||
q.addTransition(s2, s3, "sun");
|
||||
q.finish();
|
||||
|
||||
s.search(q, new SimpleCollector() {
|
||||
private Scorer scorer;
|
||||
|
||||
@Override
|
||||
public void setScorer(Scorer scorer) {
|
||||
this.scorer = scorer;
|
||||
while (scorer instanceof AssertingScorer) {
|
||||
scorer = ((AssertingScorer) scorer).getIn();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collect(int docID) throws IOException {
|
||||
assertEquals(3, scorer.freq());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsScores() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
w.close();
|
||||
r.close();
|
||||
dir.close();
|
||||
}
|
||||
|
||||
public void testSegsMissingTerms() throws Exception {
|
||||
Directory dir = newDirectory();
|
||||
RandomIndexWriter w = new RandomIndexWriter(random(), dir);
|
||||
|
@ -81,13 +81,6 @@ public class AssertingScorer extends Scorer {
|
||||
return Collections.singletonList(new ChildScorer(in, "SHOULD"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
assert needsScores;
|
||||
assert iterating();
|
||||
return in.freq();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int docID() {
|
||||
return in.docID();
|
||||
|
@ -31,7 +31,6 @@ public class BulkScorerWrapperScorer extends Scorer {
|
||||
private int next = 0;
|
||||
|
||||
private final int[] docs;
|
||||
private final int[] freqs;
|
||||
private final float[] scores;
|
||||
private int bufferLength;
|
||||
|
||||
@ -40,7 +39,6 @@ public class BulkScorerWrapperScorer extends Scorer {
|
||||
super(weight);
|
||||
this.scorer = scorer;
|
||||
docs = new int[bufferSize];
|
||||
freqs = new int[bufferSize];
|
||||
scores = new float[bufferSize];
|
||||
}
|
||||
|
||||
@ -58,7 +56,6 @@ public class BulkScorerWrapperScorer extends Scorer {
|
||||
@Override
|
||||
public void collect(int doc) throws IOException {
|
||||
docs[bufferLength] = doc;
|
||||
freqs[bufferLength] = scorer.freq();
|
||||
scores[bufferLength] = scorer.score();
|
||||
bufferLength += 1;
|
||||
}
|
||||
@ -72,11 +69,6 @@ public class BulkScorerWrapperScorer extends Scorer {
|
||||
return scores[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return freqs[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int docID() {
|
||||
return doc;
|
||||
|
@ -108,11 +108,6 @@ public class RandomApproximationQuery extends Query {
|
||||
return scorer.score();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return scorer.freq();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int docID() {
|
||||
return scorer.docID();
|
||||
|
@ -521,11 +521,6 @@ public class LTRScoringQuery extends Query {
|
||||
return featureTraversalScorer.score();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return featureTraversalScorer.freq();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocIdSetIterator iterator() {
|
||||
return featureTraversalScorer.iterator();
|
||||
@ -580,16 +575,6 @@ public class LTRScoringQuery extends Query {
|
||||
return makeNormalizedFeaturesAndScore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
final DisiWrapper subMatches = subScorers.topList();
|
||||
int freq = 1;
|
||||
for (DisiWrapper w = subMatches.next; w != null; w = w.next) {
|
||||
freq += 1;
|
||||
}
|
||||
return freq;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocIdSetIterator iterator() {
|
||||
return itr;
|
||||
@ -681,11 +666,6 @@ public class LTRScoringQuery extends Query {
|
||||
return children;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return freq;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocIdSetIterator iterator() {
|
||||
return new DenseIterator();
|
||||
|
@ -297,11 +297,6 @@ public abstract class Feature extends Query {
|
||||
return docInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int docID() {
|
||||
return itr.docID();
|
||||
|
@ -107,11 +107,6 @@ public class OriginalScoreFeature extends Feature {
|
||||
return (docInfo != null && docInfo.hasOriginalDocScore() ? docInfo.getOriginalDocScore() : originalScorer.score());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return originalScorer.freq();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int docID() {
|
||||
return originalScorer.docID();
|
||||
|
@ -1480,11 +1480,6 @@ public class QueryComponent extends SearchComponent
|
||||
return score;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocIdSetIterator iterator() {
|
||||
throw new UnsupportedOperationException();
|
||||
|
@ -484,11 +484,6 @@ class SpatialDistanceQuery extends ExtendedQueryBase implements PostFilter {
|
||||
return (float)(dist * qWeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public Explanation explain(Explanation base, int doc) throws IOException {
|
||||
if (base.isMatch() == false) {
|
||||
return base;
|
||||
|
@ -315,11 +315,7 @@ public class GraphQuery extends Query {
|
||||
// current position of the doc iterator.
|
||||
return iter.docID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -456,11 +456,6 @@ public class TestRankQueryPlugin extends QParserPlugin {
|
||||
return score;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int freq() throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocIdSetIterator iterator() {
|
||||
throw new UnsupportedOperationException();
|
||||
|
Loading…
x
Reference in New Issue
Block a user