LUCENE-6228: Add Scorable class and make LeafCollector.setScorer() take Scorable

This commit is contained in:
Alan Woodward 2018-09-03 16:46:59 +01:00
parent 1acfca5ebc
commit 910a0231f6
102 changed files with 544 additions and 414 deletions

View File

@ -69,6 +69,10 @@ API Changes
need to be set on top hits via TopFieldCollector#populateScores instead.
(Adrien Grand)
* LUCENE-6228: A new Scorable abstract class has been added, containing only those
methods from Scorer that should be called from Collectors. LeafCollector.setScorer()
now takes a Scorable rather than a Scorer. (Alan Woodward, Adrien Grand)
Changes in Runtime Behavior
* LUCENE-8333: Switch MoreLikeThis.setMaxDocFreqPct to use maxDoc instead of

View File

@ -106,3 +106,10 @@ This RAM-based directory implementation is an old piece of code that uses ineffi
thread synchronization primitives and can be confused as "faster" than the NIO-based
MMapDirectory. It is deprecated and scheduled for removal in future versions of
Lucene. (LUCENE-8467, LUCENE-8438)
## LeafCollector.setScorer() now takes a Scorable rather than a Scorer ##
Scorer has a number of methods that should never be called from Collectors, for example
those that advance the underlying iterators. To hide these, LeafCollector.setScorer()
now takes a Scorable, an abstract class that Scorers can extend, with methods
docId() and score() (LUCENE-6228)

View File

@ -26,7 +26,7 @@ import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.LeafFieldComparator;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.SloppyMath;
@ -78,7 +78,7 @@ class LatLonPointDistanceComparator extends FieldComparator<Double> implements L
}
@Override
public void setScorer(Scorer scorer) {}
public void setScorer(Scorable scorer) {}
@Override
public int compare(int slot1, int slot2) {

View File

@ -250,10 +250,10 @@ final class BlockMaxConjunctionScorer extends Scorer {
}
@Override
public Collection<ChildScorer> getChildren() {
ArrayList<ChildScorer> children = new ArrayList<>();
public Collection<ChildScorable> getChildren() {
ArrayList<ChildScorable> children = new ArrayList<>();
for (Scorer scorer : scorers) {
children.add(new ChildScorer(scorer, "MUST"));
children.add(new ChildScorable(scorer, "MUST"));
}
return children;
}

View File

@ -124,10 +124,10 @@ final class BooleanScorer extends BulkScorer {
final long cost;
final class OrCollector implements LeafCollector {
Scorer scorer;
Scorable scorer;
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
this.scorer = scorer;
}

View File

@ -163,7 +163,7 @@ final class BooleanWeight extends Weight {
FakeScorer fake = new FakeScorer();
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
collector.setScorer(fake);
}

View File

@ -256,7 +256,7 @@ public abstract class CachingCollector extends FilterCollector {
private class ScoreCachingLeafCollector extends NoScoreCachingLeafCollector {
Scorer scorer;
Scorable scorer;
float[] scores;
ScoreCachingLeafCollector(LeafCollector in, int maxDocsToCache) {
@ -265,7 +265,7 @@ public abstract class CachingCollector extends FilterCollector {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
super.setScorer(scorer);
}

View File

@ -91,10 +91,10 @@ class ConjunctionScorer extends Scorer {
}
@Override
public Collection<ChildScorer> getChildren() {
ArrayList<ChildScorer> children = new ArrayList<>();
public Collection<ChildScorable> getChildren() {
ArrayList<ChildScorable> children = new ArrayList<>();
for (Scorer scorer : required) {
children.add(new ChildScorer(scorer, "MUST"));
children.add(new ChildScorable(scorer, "MUST"));
}
return children;
}

View File

@ -87,15 +87,11 @@ public final class ConstantScoreQuery extends Query {
private LeafCollector wrapCollector(LeafCollector collector) {
return new FilterLeafCollector(collector) {
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
// we must wrap again here, but using the scorer passed in as parameter:
in.setScorer(new FilterScorer(scorer) {
in.setScorer(new FilterScorable(scorer) {
@Override
public float score() throws IOException {
return theScore;
}
@Override
public float getMaxScore(int upTo) throws IOException {
public float score() {
return theScore;
}
});
@ -145,8 +141,8 @@ public final class ConstantScoreQuery extends Query {
return score;
}
@Override
public Collection<ChildScorer> getChildren() {
return Collections.singleton(new ChildScorer(innerScorer, "constant"));
public Collection<ChildScorable> getChildren() {
return Collections.singleton(new ChildScorable(innerScorer, "constant"));
}
};
}

View File

@ -198,10 +198,10 @@ abstract class DisjunctionScorer extends Scorer {
protected abstract float score(DisiWrapper topList) throws IOException;
@Override
public final Collection<ChildScorer> getChildren() throws IOException {
ArrayList<ChildScorer> children = new ArrayList<>();
public final Collection<ChildScorable> getChildren() throws IOException {
ArrayList<ChildScorable> children = new ArrayList<>();
for (DisiWrapper scorer = getSubMatches(); scorer != null; scorer = scorer.next) {
children.add(new ChildScorer(scorer.scorer, "SHOULD"));
children.add(new ChildScorable(scorer.scorer, "SHOULD"));
}
return children;
}

View File

@ -41,7 +41,7 @@ import org.apache.lucene.index.NumericDocValues;
* special long-to-double encoding is required.
*
* Scores may be used as a source for value calculations by wrapping a {@link Scorer} using
* {@link #fromScorer(Scorer)} and passing the resulting DoubleValues to {@link #getValues(LeafReaderContext, DoubleValues)}.
* {@link #fromScorer(Scorable)} and passing the resulting DoubleValues to {@link #getValues(LeafReaderContext, DoubleValues)}.
* The scores can then be accessed using the {@link #SCORES} DoubleValuesSource.
*/
public abstract class DoubleValuesSource implements SegmentCacheable {
@ -331,7 +331,7 @@ public abstract class DoubleValuesSource implements SegmentCacheable {
/**
* Returns a DoubleValues instance that wraps scores returned by a Scorer
*/
public static DoubleValues fromScorer(Scorer scorer) {
public static DoubleValues fromScorer(Scorable scorer) {
return new DoubleValues() {
@Override
public double doubleValue() throws IOException {
@ -471,7 +471,7 @@ public abstract class DoubleValuesSource implements SegmentCacheable {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
holder.values = producer.getValues(ctx, fromScorer(scorer));
}
};

View File

@ -56,7 +56,7 @@ final class FakeScorer extends Scorer {
}
@Override
public Collection<ChildScorer> getChildren() {
public Collection<ChildScorable> getChildren() {
throw new UnsupportedOperationException();
}
}

View File

@ -412,7 +412,7 @@ public abstract class FieldComparator<T> {
public static final class RelevanceComparator extends FieldComparator<Float> implements LeafFieldComparator {
private final float[] scores;
private float bottom;
private Scorer scorer;
private Scorable scorer;
private float topValue;
/** Creates a new comparator based on relevance for {@code numHits}. */
@ -454,7 +454,7 @@ public abstract class FieldComparator<T> {
}
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
// wrap with a ScoreCachingWrappingScorer so that successive calls to
// score() will not incur score computation over and
// over again.
@ -546,7 +546,7 @@ public abstract class FieldComparator<T> {
}
@Override
public void setScorer(Scorer scorer) {}
public void setScorer(Scorable scorer) {}
}
/** Sorts by field's natural Term sort order, using
@ -818,7 +818,7 @@ public abstract class FieldComparator<T> {
}
@Override
public void setScorer(Scorer scorer) {}
public void setScorer(Scorable scorer) {}
}
/** Sorts by field's natural Term sort order. All
@ -926,6 +926,6 @@ public abstract class FieldComparator<T> {
}
@Override
public void setScorer(Scorer scorer) {}
public void setScorer(Scorable scorer) {}
}
}

View File

@ -34,7 +34,7 @@ public abstract class FilterLeafCollector implements LeafCollector {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
in.setScorer(scorer);
}

View File

@ -0,0 +1,58 @@
/*
* 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.Collection;
import java.util.Collections;
/**
* Filter a {@link Scorable}, intercepting methods and optionally changing
* their return values
*
* The default implementation simply passes all calls to its delegate, with
* the exception of {@link #setMinCompetitiveScore(float)} which defaults
* to a no-op.
*/
public class FilterScorable extends Scorable {
protected final Scorable in;
/**
* Filter a scorer
* @param in the scorer to filter
*/
public FilterScorable(Scorable in) {
this.in = in;
}
@Override
public float score() throws IOException {
return in.score();
}
@Override
public int docID() {
return in.docID();
}
@Override
public Collection<ChildScorable> getChildren() throws IOException {
return Collections.singletonList(new ChildScorable(in, "FILTER"));
}
}

View File

@ -503,7 +503,7 @@ public class LRUQueryCache implements QueryCache, Accountable {
scorer.score(new LeafCollector() {
@Override
public void setScorer(Scorer scorer) throws IOException {}
public void setScorer(Scorable scorer) throws IOException {}
@Override
public void collect(int doc) throws IOException {
@ -520,7 +520,7 @@ public class LRUQueryCache implements QueryCache, Accountable {
scorer.score(new LeafCollector() {
@Override
public void setScorer(Scorer scorer) throws IOException {}
public void setScorer(Scorable scorer) throws IOException {}
@Override
public void collect(int doc) throws IOException {

View File

@ -76,7 +76,7 @@ public interface LeafCollector {
* {@link #collect(int)}), should save the passed-in Scorer and call
* scorer.score() when needed.
*/
void setScorer(Scorer scorer) throws IOException;
void setScorer(Scorable scorer) throws IOException;
/**
* Called once for every document matching a query, with the unbased document

View File

@ -114,6 +114,6 @@ public interface LeafFieldComparator {
*
* @param scorer Scorer instance that you should use to
* obtain the current hit's score, if necessary. */
void setScorer(Scorer scorer) throws IOException;
void setScorer(Scorable scorer) throws IOException;
}

View File

@ -325,7 +325,7 @@ public abstract class LongValuesSource implements SegmentCacheable {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
holder.values = producer.getValues(ctx, DoubleValuesSource.fromScorer(scorer));
}
};

View File

@ -117,11 +117,11 @@ final class MinShouldMatchSumScorer extends Scorer {
}
@Override
public final Collection<ChildScorer> getChildren() throws IOException {
List<ChildScorer> matchingChildren = new ArrayList<>();
public final Collection<ChildScorable> getChildren() throws IOException {
List<ChildScorable> matchingChildren = new ArrayList<>();
updateFreq();
for (DisiWrapper s = lead; s != null; s = s.next) {
matchingChildren.add(new ChildScorer(s.scorer, "SHOULD"));
matchingChildren.add(new ChildScorable(s.scorer, "SHOULD"));
}
return matchingChildren;
}

View File

@ -151,11 +151,11 @@ public class MultiCollector implements Collector {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
if (cacheScores) {
scorer = new ScoreCachingWrappingScorer(scorer);
}
scorer = new FilterScorer(scorer) {
scorer = new FilterScorable(scorer) {
@Override
public void setMinCompetitiveScore(float minScore) {
// Ignore calls to setMinCompetitiveScore so that if we wrap two
@ -164,10 +164,7 @@ public class MultiCollector implements Collector {
// min scores and take the maximum min score across collectors, but
// this is very unlikely to be helpful in practice.
}
@Override
public float getMaxScore(int upTo) throws IOException {
return in.getMaxScore(upTo);
}
};
for (int i = 0; i < numCollectors; ++i) {
final LeafCollector c = collectors[i];

View File

@ -16,13 +16,13 @@
*/
package org.apache.lucene.search;
import org.apache.lucene.index.LeafReaderContext;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.lucene.index.LeafReaderContext;
/**
* A {@link CollectorManager} implements which wrap a set of {@link CollectorManager}
* as {@link MultiCollector} acts for {@link Collector}.
@ -97,7 +97,7 @@ public class MultiCollectorManager implements CollectorManager<MultiCollectorMan
}
@Override
final public void setScorer(final Scorer scorer) throws IOException {
final public void setScorer(final Scorable scorer) throws IOException {
for (LeafCollector leafCollector : leafCollectors)
if (leafCollector != null)
leafCollector.setScorer(scorer);

View File

@ -83,7 +83,7 @@ final class MultiLeafFieldComparator implements LeafFieldComparator {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
for (LeafFieldComparator comparator : comparators) {
comparator.setScorer(scorer);
}

View File

@ -37,10 +37,10 @@ public class PositiveScoresOnlyCollector extends FilterCollector {
throws IOException {
return new FilterLeafCollector(super.getLeafCollector(context)) {
private Scorer scorer;
private Scorable scorer;
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = new ScoreCachingWrappingScorer(scorer);
in.setScorer(this.scorer);
}

View File

@ -93,8 +93,8 @@ class ReqExclScorer extends Scorer {
}
@Override
public Collection<ChildScorer> getChildren() {
return Collections.singleton(new ChildScorer(reqScorer, "MUST"));
public Collection<ChildScorable> getChildren() {
return Collections.singleton(new ChildScorable(reqScorer, "MUST"));
}
/**

View File

@ -300,10 +300,10 @@ class ReqOptSumScorer extends Scorer {
}
@Override
public Collection<ChildScorer> getChildren() {
ArrayList<ChildScorer> children = new ArrayList<>(2);
children.add(new ChildScorer(reqScorer, "MUST"));
children.add(new ChildScorer(optScorer, "SHOULD"));
public Collection<ChildScorable> getChildren() {
ArrayList<ChildScorable> children = new ArrayList<>(2);
children.add(new ChildScorable(reqScorer, "MUST"));
children.add(new ChildScorable(optScorer, "SHOULD"));
return children;
}
}

View File

@ -0,0 +1,86 @@
/*
* 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.Collection;
import java.util.Collections;
/**
* Allows access to the score of a Query
*/
public abstract class Scorable {
/**
* Returns the score of the current document matching the query.
*/
public abstract float score() throws IOException;
/**
* Returns the doc ID that is currently being scored.
*/
public abstract int docID();
/**
* Optional method: Tell the scorer that its iterator may safely ignore all
* documents whose score is less than the given {@code minScore}. This is a
* no-op by default.
*
* This method may only be called from collectors that use
* {@link ScoreMode#TOP_SCORES}, and successive calls may only set increasing
* values of {@code minScore}.
*/
public void setMinCompetitiveScore(float minScore) {
// no-op by default
}
/**
* Returns child sub-scorers positioned on the current document
* @lucene.experimental
*/
public Collection<ChildScorable> getChildren() throws IOException {
return Collections.emptyList();
}
/** A child Scorer and its relationship to its parent.
* the meaning of the relationship depends upon the parent query.
* @lucene.experimental */
public static class ChildScorable {
/**
* Child Scorer. (note this is typically a direct child, and may
* itself also have children).
*/
public final Scorable child;
/**
* An arbitrary string relating this scorer to the parent.
*/
public final String relationship;
/**
* Creates a new ChildScorer node with the specified relationship.
* <p>
* The relationship can be any be any string that makes sense to
* the parent Scorer.
*/
public ChildScorable(Scorable child, String relationship) {
this.child = child;
this.relationship = relationship;
}
}
}

View File

@ -32,14 +32,15 @@ import java.util.Collections;
* several places, however all they have in hand is a {@link Scorer} object, and
* might end up computing the score of a document more than once.
*/
public final class ScoreCachingWrappingScorer extends FilterScorer {
public final class ScoreCachingWrappingScorer extends Scorable {
private int curDoc = -1;
private float curScore;
private final Scorable in;
/** Creates a new instance by wrapping the given scorer. */
public ScoreCachingWrappingScorer(Scorer scorer) {
super(scorer);
public ScoreCachingWrappingScorer(Scorable scorer) {
this.in = scorer;
}
@Override
@ -53,23 +54,18 @@ public final class ScoreCachingWrappingScorer extends FilterScorer {
return curScore;
}
@Override
public float getMaxScore(int upTo) throws IOException {
return in.getMaxScore(upTo);
}
@Override
public int advanceShallow(int target) throws IOException {
return in.advanceShallow(target);
}
@Override
public void setMinCompetitiveScore(float minScore) {
in.setMinCompetitiveScore(minScore);
}
@Override
public Collection<ChildScorer> getChildren() {
return Collections.singleton(new ChildScorer(in, "CACHED"));
public int docID() {
return in.docID();
}
@Override
public Collection<ChildScorable> getChildren() {
return Collections.singleton(new ChildScorable(in, "CACHED"));
}
}

View File

@ -18,8 +18,6 @@ package org.apache.lucene.search;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
/**
* Expert: Common scoring functionality for different types of queries.
@ -39,7 +37,7 @@ import java.util.Collections;
* TopScoreDocCollector}) will not properly collect hits
* with these scores.
*/
public abstract class Scorer {
public abstract class Scorer extends Scorable {
/** the Scorer's parent Weight. in some cases this may be null */
// TODO can we clean this up?
protected final Weight weight;
@ -52,65 +50,12 @@ public abstract class Scorer {
this.weight = weight;
}
/**
* Returns the doc ID that is currently being scored.
* This will return {@code -1} if the {@link #iterator()} is not positioned
* or {@link DocIdSetIterator#NO_MORE_DOCS} if it has been entirely consumed.
* @see DocIdSetIterator#docID()
*/
public abstract int docID();
/** Returns the score of the current document matching the query.
* Initially invalid, until {@link DocIdSetIterator#nextDoc()} or
* {@link DocIdSetIterator#advance(int)} is called on the {@link #iterator()}
* the first time, or when called from within {@link LeafCollector#collect}.
*/
public abstract float score() throws IOException;
/** returns parent Weight
* @lucene.experimental
*/
public Weight getWeight() {
return weight;
}
/**
* Returns child sub-scorers positioned on the current document
*
* Note that this method should not be called on Scorers passed to {@link LeafCollector#setScorer(Scorer)},
* as these may be synthetic Scorers produced by {@link BulkScorer} which will throw an Exception.
*
* @lucene.experimental
*/
public Collection<ChildScorer> getChildren() throws IOException {
return Collections.emptyList();
}
/** A child Scorer and its relationship to its parent.
* the meaning of the relationship depends upon the parent query.
* @lucene.experimental */
public static class ChildScorer {
/**
* Child Scorer. (note this is typically a direct child, and may
* itself also have children).
*/
public final Scorer child;
/**
* An arbitrary string relating this scorer to the parent.
*/
public final String relationship;
/**
* Creates a new ChildScorer node with the specified relationship.
* <p>
* The relationship can be any be any string that makes sense to
* the parent Scorer.
*/
public ChildScorer(Scorer child, String relationship) {
this.child = child;
this.relationship = relationship;
}
}
/**
* Return a {@link DocIdSetIterator} over matching documents.
@ -144,19 +89,6 @@ public abstract class Scorer {
return null;
}
/**
* Optional method: Tell the scorer that its iterator may safely ignore all
* documents whose score is less than the given {@code minScore}. This is a
* no-op by default.
*
* This method may only be called from collectors that use
* {@link ScoreMode#TOP_SCORES}, and successive calls may only set increasing
* values of {@code minScore}.
*/
public void setMinCompetitiveScore(float minScore) {
// no-op by default
}
/**
* Advance to the block of documents that contains {@code target} in order to
* get scoring information about this block. This method is implicitly called

View File

@ -38,7 +38,7 @@ public abstract class SimpleCollector implements Collector, LeafCollector {
protected void doSetNextReader(LeafReaderContext context) throws IOException {}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
// no-op by default
}

View File

@ -38,5 +38,5 @@ public abstract class SimpleFieldComparator<T> extends FieldComparator<T> implem
}
@Override
public void setScorer(Scorer scorer) throws IOException {}
public void setScorer(Scorable scorer) throws IOException {}
}

View File

@ -49,7 +49,7 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
final LeafFieldComparator comparator;
final int reverseMul;
Scorer scorer;
Scorable scorer;
MultiComparatorLeafCollector(LeafFieldComparator[] comparators, int[] reverseMul) {
if (comparators.length == 1) {
@ -62,7 +62,7 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
comparator.setScorer(scorer);
this.scorer = scorer;
}

View File

@ -38,10 +38,10 @@ public abstract class TopScoreDocCollector extends TopDocsCollector<ScoreDoc> {
abstract static class ScorerLeafCollector implements LeafCollector {
Scorer scorer;
Scorable scorer;
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
}
@ -70,7 +70,7 @@ public abstract class TopScoreDocCollector extends TopDocsCollector<ScoreDoc> {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
super.setScorer(scorer);
if (totalHits >= totalHitsThreshold
&& pqTop != null

View File

@ -197,11 +197,11 @@ final class WANDScorer extends Scorer {
}
@Override
public final Collection<ChildScorer> getChildren() throws IOException {
List<ChildScorer> matchingChildren = new ArrayList<>();
public final Collection<ChildScorable> getChildren() throws IOException {
List<ChildScorable> matchingChildren = new ArrayList<>();
advanceAllTail();
for (DisiWrapper s = lead; s != null; s = s.next) {
matchingChildren.add(new ChildScorer(s.scorer, "SHOULD"));
matchingChildren.add(new ChildScorable(s.scorer, "SHOULD"));
}
return matchingChildren;
}

View File

@ -31,8 +31,8 @@ import org.apache.lucene.search.CollectionStatistics;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.SimpleCollector;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TermStatistics;
@ -198,13 +198,13 @@ public class TestOmitTf extends LuceneTestCase {
searcher.search(q1,
new CountingHitCollector() {
private Scorer scorer;
private Scorable scorer;
@Override
public ScoreMode scoreMode() {
return ScoreMode.COMPLETE;
}
@Override
public final void setScorer(Scorer scorer) {
public final void setScorer(Scorable scorer) {
this.scorer = scorer;
}
@Override
@ -220,13 +220,13 @@ public class TestOmitTf extends LuceneTestCase {
searcher.search(q2,
new CountingHitCollector() {
private Scorer scorer;
private Scorable scorer;
@Override
public ScoreMode scoreMode() {
return ScoreMode.COMPLETE;
}
@Override
public final void setScorer(Scorer scorer) {
public final void setScorer(Scorable scorer) {
this.scorer = scorer;
}
@Override
@ -245,13 +245,13 @@ public class TestOmitTf extends LuceneTestCase {
searcher.search(q3,
new CountingHitCollector() {
private Scorer scorer;
private Scorable scorer;
@Override
public ScoreMode scoreMode() {
return ScoreMode.COMPLETE;
}
@Override
public final void setScorer(Scorer scorer) {
public final void setScorer(Scorable scorer) {
this.scorer = scorer;
}
@Override
@ -268,13 +268,13 @@ public class TestOmitTf extends LuceneTestCase {
searcher.search(q4,
new CountingHitCollector() {
private Scorer scorer;
private Scorable scorer;
@Override
public ScoreMode scoreMode() {
return ScoreMode.COMPLETE;
}
@Override
public final void setScorer(Scorer scorer) {
public final void setScorer(Scorable scorer) {
this.scorer = scorer;
}
@Override

View File

@ -50,7 +50,7 @@ final class JustCompileSearch {
}
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
throw new UnsupportedOperationException(UNSUPPORTED_MSG);
}

View File

@ -46,7 +46,7 @@ public class MultiCollectorTest extends LuceneTestCase {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
setScorerCalled = true;
}
@ -110,9 +110,9 @@ public class MultiCollectorTest extends LuceneTestCase {
return new LeafCollector() {
@Override
public void setScorer(Scorer scorer) throws IOException {
while (expectedScorer.equals(scorer.getClass()) == false && scorer instanceof FilterScorer) {
scorer = ((FilterScorer) scorer).in;
public void setScorer(Scorable scorer) throws IOException {
while (expectedScorer.equals(scorer.getClass()) == false && scorer instanceof FilterScorable) {
scorer = ((FilterScorable) scorer).in;
}
assertEquals(expectedScorer, scorer.getClass());
}

View File

@ -262,7 +262,7 @@ public class TestBooleanOr extends LuceneTestCase {
scorer.score(new LeafCollector() {
@Override
public void setScorer(Scorer scorer) throws IOException {}
public void setScorer(Scorable scorer) throws IOException {}
@Override
public void collect(int doc) throws IOException {

View File

@ -501,7 +501,7 @@ public class TestBooleanQuery extends LuceneTestCase {
final AtomicBoolean matched = new AtomicBoolean();
searcher.search(bq, new SimpleCollector() {
int docBase;
Scorer scorer;
Scorable scorer;
@Override
protected void doSetNextReader(LeafReaderContext context)
@ -516,7 +516,7 @@ public class TestBooleanQuery extends LuceneTestCase {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
}

View File

@ -37,7 +37,6 @@ 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.search.similarities.ClassicSimilarity;
import org.apache.lucene.search.similarities.Similarity;
import org.apache.lucene.store.Directory;
@ -150,7 +149,7 @@ public class TestBooleanQueryVisitSubscorers extends LuceneTestCase {
return new FilterLeafCollector(super.getLeafCollector(context)) {
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
super.setScorer(scorer);
tqsSet.clear();
fillLeaves(scorer, tqsSet);
@ -171,11 +170,11 @@ public class TestBooleanQueryVisitSubscorers extends LuceneTestCase {
};
}
private void fillLeaves(Scorer scorer, Set<Scorer> set) throws IOException {
if (scorer.getWeight().getQuery() instanceof TermQuery) {
set.add(scorer);
private void fillLeaves(Scorable scorer, Set<Scorer> set) throws IOException {
if (scorer instanceof TermScorer) {
set.add((Scorer)scorer);
} else {
for (ChildScorer child : scorer.getChildren()) {
for (Scorable.ChildScorable child : scorer.getChildren()) {
fillLeaves(child.child, set);
}
}
@ -283,7 +282,7 @@ public class TestBooleanQueryVisitSubscorers extends LuceneTestCase {
return new LeafCollector() {
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
final StringBuilder builder = new StringBuilder();
summarizeScorer(builder, scorer, 0);
summaries.add(builder.toString());
@ -296,13 +295,13 @@ public class TestBooleanQueryVisitSubscorers extends LuceneTestCase {
};
}
private static void summarizeScorer(final StringBuilder builder, final Scorer scorer, final int indent) throws IOException {
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.getWeight().getQuery();
TermQuery termQuery = (TermQuery) ((Scorer)scorer).getWeight().getQuery();
builder.append(" ").append(termQuery.getTerm().field()).append(":").append(termQuery.getTerm().text());
}
for (final ChildScorer childScorer : scorer.getChildren()) {
for (final Scorable.ChildScorable childScorer : scorer.getChildren()) {
indent(builder, indent + 1).append(childScorer.relationship).append(" ");
summarizeScorer(builder, childScorer.child, indent + 2);
}

View File

@ -125,13 +125,13 @@ public class TestConjunctions extends LuceneTestCase {
final boolean[] setScorerCalled = new boolean[1];
s.search(q, new SimpleCollector() {
@Override
public void setScorer(Scorer s) throws IOException {
Collection<Scorer.ChildScorer> childScorers = s.getChildren();
public void setScorer(Scorable s) throws IOException {
Collection<Scorer.ChildScorable> childScorers = s.getChildren();
setScorerCalled[0] = true;
assertEquals(2, childScorers.size());
Set<String> terms = new HashSet<>();
for (Scorer.ChildScorer childScorer : childScorers) {
Query query = childScorer.child.getWeight().getQuery();
for (Scorer.ChildScorable childScorer : childScorers) {
Query query = ((Scorer)childScorer.child).getWeight().getQuery();
assertTrue(query instanceof TermQuery);
Term term = ((TermQuery) query).getTerm();
assertEquals("field", term.field());

View File

@ -18,6 +18,7 @@ package org.apache.lucene.search;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@ -56,14 +57,14 @@ public class TestConstantScoreQuery extends LuceneTestCase {
private void checkHits(IndexSearcher searcher, Query q, final float expectedScore, final Class<? extends Scorer> innerScorerClass) throws IOException {
final int[] count = new int[1];
searcher.search(q, new SimpleCollector() {
private Scorer scorer;
private Scorable scorer;
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
this.scorer = scorer;
if (innerScorerClass != null) {
final FilterScorer innerScorer = (FilterScorer) scorer;
assertEquals("inner Scorer is implemented by wrong class", innerScorerClass, innerScorer.in.getClass());
Scorable innerScorer = rootScorer(scorer);
assertEquals("inner Scorer is implemented by wrong class", innerScorerClass, innerScorer.getClass());
}
}
@ -80,6 +81,23 @@ public class TestConstantScoreQuery extends LuceneTestCase {
});
assertEquals("invalid number of results", 1, count[0]);
}
private Scorable rootScorer(Scorable s) {
while (true) {
try {
Collection<Scorable.ChildScorable> children = s.getChildren();
if (children.size() == 0)
return s;
s = children.stream().findFirst().get().child;
}
catch (Exception e) {
// If FakeScorer returns UnsupportedOperationException
// We catch Exception here to deal with the (impossible) IOException too
return s;
}
}
}
public void testWrapped2Times() throws Exception {
Directory directory = null;

View File

@ -210,7 +210,7 @@ public class TestDoubleValuesSource extends LuceneTestCase {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.v = rewritten.getValues(this.ctx, DoubleValuesSource.fromScorer(scorer));
}
@ -238,7 +238,7 @@ public class TestDoubleValuesSource extends LuceneTestCase {
searcher.search(q, new SimpleCollector() {
DoubleValues v;
Scorer scorer;
Scorable scorer;
LeafReaderContext ctx;
@Override
@ -247,7 +247,7 @@ public class TestDoubleValuesSource extends LuceneTestCase {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
this.v = vs.getValues(this.ctx, DoubleValuesSource.fromScorer(scorer));
}

View File

@ -193,7 +193,7 @@ class ElevationComparatorSource extends FieldComparatorSource {
}
@Override
public void setScorer(Scorer scorer) {}
public void setScorer(Scorable scorer) {}
};
}

View File

@ -81,7 +81,7 @@ public class TestMultiCollector extends LuceneTestCase {
public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
return new FilterLeafCollector(super.getLeafCollector(context)) {
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
super.setScorer(scorer);
setScorerCalled.set(true);
}
@ -200,7 +200,7 @@ public class TestMultiCollector extends LuceneTestCase {
};
Collector collector = new SimpleCollector() {
private Scorer scorer;
private Scorable scorer;
float minScore = 0;
@Override
@ -209,7 +209,7 @@ public class TestMultiCollector extends LuceneTestCase {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
}

View File

@ -81,7 +81,7 @@ public class TestReqExclBulkScorer extends LuceneTestCase {
if (random().nextBoolean()) {
reqExcl.score(new LeafCollector() {
@Override
public void setScorer(Scorer scorer) throws IOException {}
public void setScorer(Scorable scorer) throws IOException {}
@Override
public void collect(int doc) throws IOException {
@ -95,7 +95,7 @@ public class TestReqExclBulkScorer extends LuceneTestCase {
final int max = min + random().nextInt(10);
next = reqExcl.score(new LeafCollector() {
@Override
public void setScorer(Scorer scorer) throws IOException {}
public void setScorer(Scorable scorer) throws IOException {}
@Override
public void collect(int doc) throws IOException {

View File

@ -75,7 +75,7 @@ public class TestScoreCachingWrappingScorer extends LuceneTestCase {
private static final class ScoreCachingCollector extends SimpleCollector {
private int idx = 0;
private Scorer scorer;
private Scorable scorer;
float[] mscores;
public ScoreCachingCollector(int numToCollect) {
@ -95,7 +95,7 @@ public class TestScoreCachingWrappingScorer extends LuceneTestCase {
++idx;
}
@Override public void setScorer(Scorer scorer) {
@Override public void setScorer(Scorable scorer) {
this.scorer = new ScoreCachingWrappingScorer(scorer);
}

View File

@ -70,9 +70,9 @@ public class TestSimilarity extends LuceneTestCase {
Term c = new Term("field", "c");
searcher.search(new TermQuery(b), new SimpleCollector() {
private Scorer scorer;
private Scorable scorer;
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
this.scorer = scorer;
}
@Override
@ -91,9 +91,9 @@ public class TestSimilarity extends LuceneTestCase {
//System.out.println(bq.toString("field"));
searcher.search(bq.build(), new SimpleCollector() {
private int base = 0;
private Scorer scorer;
private Scorable scorer;
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
this.scorer = scorer;
}
@Override
@ -115,9 +115,9 @@ public class TestSimilarity extends LuceneTestCase {
//System.out.println(pq.toString("field"));
searcher.search(pq,
new SimpleCollector() {
private Scorer scorer;
private Scorable scorer;
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
this.scorer = scorer;
}
@Override
@ -134,9 +134,9 @@ public class TestSimilarity extends LuceneTestCase {
pq = new PhraseQuery(2, a.field(), a.bytes(), b.bytes());
//System.out.println(pq.toString("field"));
searcher.search(pq, new SimpleCollector() {
private Scorer scorer;
private Scorable scorer;
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
this.scorer = scorer;
}
@Override

View File

@ -185,11 +185,8 @@ public class TestSloppyPhraseQuery extends LuceneTestCase {
Scorer scorer;
@Override
public void setScorer(Scorer scorer) throws IOException {
this.scorer = scorer;
while (this.scorer instanceof AssertingScorer) {
this.scorer = ((AssertingScorer)this.scorer).getIn();
}
public void setScorer(Scorable scorer) throws IOException {
this.scorer = (Scorer) AssertingScorable.unwrap(scorer);
}
@Override
@ -215,11 +212,8 @@ public class TestSloppyPhraseQuery extends LuceneTestCase {
Scorer scorer;
@Override
public void setScorer(Scorer scorer) {
this.scorer = scorer;
while (this.scorer instanceof AssertingScorer) {
this.scorer = ((AssertingScorer)this.scorer).getIn();
}
public void setScorer(Scorable scorer) {
this.scorer = (Scorer) AssertingScorable.unwrap(scorer);
}
@Override

View File

@ -33,7 +33,6 @@ 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.search.similarities.Similarity;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
@ -80,7 +79,7 @@ public class TestSubScorerFreqs extends LuceneTestCase {
private static class CountingCollector extends FilterCollector {
public final Map<Integer, Map<Query, Float>> docCounts = new HashMap<>();
private final Map<Query, Scorer> subScorers = new HashMap<>();
private final Map<Query, Scorable> subScorers = new HashMap<>();
private final Set<String> relationships;
public CountingCollector(Collector other) {
@ -92,13 +91,14 @@ public class TestSubScorerFreqs extends LuceneTestCase {
this.relationships = relationships;
}
public void setSubScorers(Scorer scorer, String relationship) throws IOException {
for (ChildScorer child : scorer.getChildren()) {
if (scorer instanceof AssertingScorer || relationships.contains(child.relationship)) {
setSubScorers(child.child, child.relationship);
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.getWeight().getQuery(), scorer);
subScorers.put(((Scorer)scorer).getWeight().getQuery(), scorer);
}
public LeafCollector getLeafCollector(LeafReaderContext context)
@ -109,8 +109,8 @@ public class TestSubScorerFreqs extends LuceneTestCase {
@Override
public void collect(int doc) throws IOException {
final Map<Query, Float> freqs = new HashMap<Query, Float>();
for (Map.Entry<Query, Scorer> ent : subScorers.entrySet()) {
Scorer value = ent.getValue();
for (Map.Entry<Query, Scorable> ent : subScorers.entrySet()) {
Scorable value = ent.getValue();
int matchId = value.docID();
freqs.put(ent.getKey(), matchId == doc ? value.score() : 0.0f);
}
@ -119,10 +119,10 @@ public class TestSubScorerFreqs extends LuceneTestCase {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
super.setScorer(scorer);
subScorers.clear();
setSubScorers(scorer, "TOP");
setSubScorers(scorer);
}
};

View File

@ -94,10 +94,10 @@ public class TestTermScorer extends LuceneTestCase {
ts.score(new SimpleCollector() {
private int base = 0;
private Scorer scorer;
private Scorable scorer;
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
this.scorer = scorer;
}

View File

@ -342,7 +342,7 @@ public class TestTimeLimitingCollector extends LuceneTestCase {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
// scorer is not needed
}

View File

@ -61,7 +61,7 @@ public class TestTopDocsCollector extends LuceneTestCase {
}
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
// Don't do anything. Assign scores in random
}
};

View File

@ -243,8 +243,8 @@ public class TestTopFieldCollector extends LuceneTestCase {
final LeafCollector in = topCollector.getLeafCollector(context);
return new FilterLeafCollector(in) {
@Override
public void setScorer(final Scorer scorer) throws IOException {
Scorer s = new Scorer(null) {
public void setScorer(final Scorable scorer) throws IOException {
Scorable s = new FilterScorable(scorer) {
int lastComputedDoc = -1;
@ -257,21 +257,6 @@ public class TestTopFieldCollector extends LuceneTestCase {
return scorer.score();
}
@Override
public float getMaxScore(int upTo) throws IOException {
return scorer.getMaxScore(upTo);
}
@Override
public int docID() {
return scorer.docID();
}
@Override
public DocIdSetIterator iterator() {
return scorer.iterator();
}
};
super.setScorer(s);
}

View File

@ -607,8 +607,8 @@ class DrillSidewaysScorer extends BulkScorer {
}
@Override
public Collection<ChildScorer> getChildren() {
return Collections.singletonList(new ChildScorer(baseScorer, "MUST"));
public Collection<ChildScorable> getChildren() {
return Collections.singletonList(new ChildScorable(baseScorer, "MUST"));
}
@Override

View File

@ -27,9 +27,9 @@ import org.apache.lucene.search.FieldDoc;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MultiCollector;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.SimpleCollector;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.TopDocs;
@ -52,7 +52,7 @@ import org.apache.lucene.util.DocIdSetBuilder;
public class FacetsCollector extends SimpleCollector implements Collector {
private LeafReaderContext context;
private Scorer scorer;
private Scorable scorer;
private int totalHits;
private float[] scores;
private final boolean keepScores;
@ -137,7 +137,7 @@ public class FacetsCollector extends SimpleCollector implements Collector {
}
@Override
public final void setScorer(Scorer scorer) throws IOException {
public final void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
}

View File

@ -20,9 +20,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Scorer.ChildScorer;
import org.apache.lucene.search.SimpleCollector;
/** Verifies in collect() that all child subScorers are on
@ -31,17 +30,17 @@ class AssertingSubDocsAtOnceCollector extends SimpleCollector {
// TODO: allow wrapping another Collector
List<Scorer> allScorers;
List<Scorable> allScorers;
@Override
public void setScorer(Scorer s) throws IOException {
public void setScorer(Scorable s) throws IOException {
// Gathers all scorers, including s and "under":
allScorers = new ArrayList<>();
allScorers.add(s);
int upto = 0;
while(upto < allScorers.size()) {
s = allScorers.get(upto++);
for (ChildScorer sub : s.getChildren()) {
for (Scorable.ChildScorable sub : s.getChildren()) {
allScorers.add(sub.child);
}
}
@ -49,7 +48,7 @@ class AssertingSubDocsAtOnceCollector extends SimpleCollector {
@Override
public void collect(int docID) {
for(Scorer s : allScorers) {
for(Scorable s : allScorers) {
if (docID != s.docID()) {
throw new IllegalStateException("subScorer=" + s + " has docID=" + s.docID() + " != collected docID=" + docID);
}

View File

@ -25,8 +25,8 @@ import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.LeafFieldComparator;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.SimpleCollector;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
@ -52,7 +52,7 @@ public abstract class AllGroupHeadsCollector<T> extends SimpleCollector {
protected Map<T, GroupHead<T>> heads = new HashMap<>();
protected LeafReaderContext context;
protected Scorer scorer;
protected Scorable scorer;
/**
* Create a new AllGroupHeadsCollector based on the type of within-group Sort required
@ -169,7 +169,7 @@ public abstract class AllGroupHeadsCollector<T> extends SimpleCollector {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
for (GroupHead<T> head : heads.values()) {
head.setScorer(scorer);
@ -179,7 +179,7 @@ public abstract class AllGroupHeadsCollector<T> extends SimpleCollector {
/**
* Create a new GroupHead for the given group value, initialized with a doc, context and scorer
*/
protected abstract GroupHead<T> newGroupHead(int doc, T value, LeafReaderContext context, Scorer scorer) throws IOException;
protected abstract GroupHead<T> newGroupHead(int doc, T value, LeafReaderContext context, Scorable scorer) throws IOException;
/**
* Represents a group head. A group head is the most relevant document for a particular group.
@ -213,7 +213,7 @@ public abstract class AllGroupHeadsCollector<T> extends SimpleCollector {
/**
* Called for each segment
*/
protected abstract void setScorer(Scorer scorer) throws IOException;
protected abstract void setScorer(Scorable scorer) throws IOException;
/**
* Compares the specified document for a specified comparator against the current most relevant document.
@ -246,7 +246,7 @@ public abstract class AllGroupHeadsCollector<T> extends SimpleCollector {
}
@Override
protected GroupHead<T> newGroupHead(int doc, T value, LeafReaderContext ctx, Scorer scorer) throws IOException {
protected GroupHead<T> newGroupHead(int doc, T value, LeafReaderContext ctx, Scorable scorer) throws IOException {
return new SortingGroupHead<>(sort, value, doc, ctx, scorer);
}
}
@ -256,7 +256,7 @@ public abstract class AllGroupHeadsCollector<T> extends SimpleCollector {
final FieldComparator[] comparators;
final LeafFieldComparator[] leafComparators;
protected SortingGroupHead(Sort sort, T groupValue, int doc, LeafReaderContext context, Scorer scorer) throws IOException {
protected SortingGroupHead(Sort sort, T groupValue, int doc, LeafReaderContext context, Scorable scorer) throws IOException {
super(groupValue, doc, context.docBase);
final SortField[] sortFields = sort.getSort();
comparators = new FieldComparator[sortFields.length];
@ -279,7 +279,7 @@ public abstract class AllGroupHeadsCollector<T> extends SimpleCollector {
}
@Override
protected void setScorer(Scorer scorer) throws IOException {
protected void setScorer(Scorable scorer) throws IOException {
for (LeafFieldComparator c : leafComparators) {
c.setScorer(scorer);
}
@ -310,17 +310,17 @@ public abstract class AllGroupHeadsCollector<T> extends SimpleCollector {
}
@Override
protected GroupHead<T> newGroupHead(int doc, T value, LeafReaderContext context, Scorer scorer) throws IOException {
protected GroupHead<T> newGroupHead(int doc, T value, LeafReaderContext context, Scorable scorer) throws IOException {
return new ScoringGroupHead<>(scorer, value, doc, context.docBase);
}
}
private static class ScoringGroupHead<T> extends GroupHead<T> {
private Scorer scorer;
private Scorable scorer;
private float topScore;
protected ScoringGroupHead(Scorer scorer, T groupValue, int doc, int docBase) throws IOException {
protected ScoringGroupHead(Scorable scorer, T groupValue, int doc, int docBase) throws IOException {
super(groupValue, doc, docBase);
assert scorer.docID() == doc;
this.scorer = scorer;
@ -328,7 +328,7 @@ public abstract class AllGroupHeadsCollector<T> extends SimpleCollector {
}
@Override
protected void setScorer(Scorer scorer) {
protected void setScorer(Scorable scorer) {
this.scorer = scorer;
}

View File

@ -22,8 +22,8 @@ import java.util.HashSet;
import java.util.Set;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.SimpleCollector;
/**
@ -70,7 +70,7 @@ public class AllGroupsCollector<T> extends SimpleCollector {
}
@Override
public void setScorer(Scorer scorer) throws IOException {}
public void setScorer(Scorable scorer) throws IOException {}
@Override
protected void doSetNextReader(LeafReaderContext context) throws IOException {

View File

@ -24,6 +24,7 @@ import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.LeafCollector;
import org.apache.lucene.search.LeafFieldComparator;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.SimpleCollector;
@ -93,7 +94,7 @@ public class BlockGroupingCollector extends SimpleCollector {
private int docBase;
private int groupEndDocID;
private DocIdSetIterator lastDocPerGroupBits;
private Scorer scorer;
private Scorable scorer;
private final GroupQueue groupQueue;
private boolean groupCompetes;
@ -357,7 +358,7 @@ public class BlockGroupingCollector extends SimpleCollector {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
for (LeafFieldComparator comparator : leafComparators) {
comparator.setScorer(scorer);

View File

@ -26,8 +26,8 @@ import java.util.TreeSet;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.LeafFieldComparator;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.SimpleCollector;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
@ -150,7 +150,7 @@ public class FirstPassGroupingCollector<T> extends SimpleCollector {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
for (LeafFieldComparator comparator : leafComparators) {
comparator.setScorer(scorer);
}

View File

@ -24,8 +24,8 @@ import java.util.List;
import java.util.NavigableSet;
import java.util.TreeSet;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.SimpleCollector;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.PriorityQueue;
@ -110,7 +110,7 @@ public abstract class GroupFacetCollector extends SimpleCollector {
protected abstract SegmentResult createSegmentResult() throws IOException;
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
}
@Override

View File

@ -25,7 +25,7 @@ import java.util.Map;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.LeafCollector;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Scorable;
/**
* Concrete implementations of this class define what to collect for individual
@ -84,7 +84,7 @@ public abstract class GroupReducer<T, C extends Collector> {
/**
* Set the Scorer on all group collectors
*/
public final void setScorer(Scorer scorer) throws IOException {
public final void setScorer(Scorable scorer) throws IOException {
for (GroupCollector<C> collector : groups.values()) {
collector.leafCollector.setScorer(scorer);
}

View File

@ -21,8 +21,8 @@ import java.util.Collection;
import java.util.Objects;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.SimpleCollector;
/**
@ -77,7 +77,7 @@ public class SecondPassGroupingCollector<T> extends SimpleCollector {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
groupReducer.setScorer(scorer);
}

View File

@ -24,9 +24,9 @@ import java.util.function.Supplier;
import org.apache.lucene.search.FilterCollector;
import org.apache.lucene.search.MultiCollector;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.SimpleCollector;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.TopDocs;
@ -67,7 +67,7 @@ public class TopGroupsCollector<T> extends SecondPassGroupingCollector<T> {
}
private static class MaxScoreCollector extends SimpleCollector {
private Scorer scorer;
private Scorable scorer;
private float maxScore = Float.MIN_VALUE;
private boolean collectedAnyHits = false;
@ -83,7 +83,7 @@ public class TopGroupsCollector<T> extends SecondPassGroupingCollector<T> {
}
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
this.scorer = scorer;
}

View File

@ -24,11 +24,11 @@ import org.apache.lucene.analysis.MockTokenizer;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.DirectoryReader;
@ -39,6 +39,7 @@ import org.apache.lucene.index.Term;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.SimpleCollector;
import org.apache.lucene.search.TopDocs;
@ -128,7 +129,7 @@ public class HighlighterPhraseTest extends LuceneTestCase {
}
@Override
public void setScorer(org.apache.lucene.search.Scorer scorer) {
public void setScorer(Scorable scorer) {
// Do Nothing
}

View File

@ -24,7 +24,7 @@ import org.apache.lucene.index.OrdinalMap;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.LeafCollector;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.util.LongBitSet;
import org.apache.lucene.util.LongValues;
@ -85,7 +85,7 @@ final class GlobalOrdinalsCollector implements Collector {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
}
}
@ -105,7 +105,7 @@ final class GlobalOrdinalsCollector implements Collector {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
}
}

View File

@ -25,7 +25,7 @@ import org.apache.lucene.index.OrdinalMap;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.LeafCollector;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.util.LongBitSet;
import org.apache.lucene.util.LongValues;
@ -104,7 +104,7 @@ abstract class GlobalOrdinalsWithScoreCollector implements Collector {
private final SortedDocValues docTermOrds;
private final LongValues segmentOrdToGlobalOrdLookup;
private Scorer scorer;
private Scorable scorer;
OrdinalMapCollector(SortedDocValues docTermOrds, LongValues segmentOrdToGlobalOrdLookup) {
this.docTermOrds = docTermOrds;
@ -126,7 +126,7 @@ abstract class GlobalOrdinalsWithScoreCollector implements Collector {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
}
}
@ -134,7 +134,7 @@ abstract class GlobalOrdinalsWithScoreCollector implements Collector {
final class SegmentOrdinalCollector implements LeafCollector {
private final SortedDocValues docTermOrds;
private Scorer scorer;
private Scorable scorer;
SegmentOrdinalCollector(SortedDocValues docTermOrds) {
this.docTermOrds = docTermOrds;
@ -155,7 +155,7 @@ abstract class GlobalOrdinalsWithScoreCollector implements Collector {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
}
}
@ -247,7 +247,7 @@ abstract class GlobalOrdinalsWithScoreCollector implements Collector {
return new LeafCollector() {
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
}
@Override
@ -262,7 +262,7 @@ abstract class GlobalOrdinalsWithScoreCollector implements Collector {
} else {
return new LeafCollector() {
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
}
@Override

View File

@ -44,7 +44,7 @@ import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.PointInSetQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.SimpleCollector;
import org.apache.lucene.search.join.DocValuesTermsCollector.Function;
import org.apache.lucene.util.BytesRef;
@ -195,7 +195,7 @@ public final class JoinUtil {
collector = new SimpleCollector() {
SortedNumericDocValues sortedNumericDocValues;
Scorer scorer;
Scorable scorer;
@Override
public void collect(int doc) throws IOException {
@ -216,7 +216,7 @@ public final class JoinUtil {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
}
@ -229,7 +229,7 @@ public final class JoinUtil {
collector = new SimpleCollector() {
NumericDocValues numericDocValues;
Scorer scorer;
Scorable scorer;
private int lastDocID = -1;
private boolean docsInOrder(int docID) {
@ -260,7 +260,7 @@ public final class JoinUtil {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
}

View File

@ -21,7 +21,7 @@ import java.util.Arrays;
import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefHash;
@ -34,7 +34,7 @@ abstract class TermsWithScoreCollector<DV> extends DocValuesTermsCollector<DV>
final BytesRefHash collectedTerms = new BytesRefHash();
final ScoreMode scoreMode;
Scorer scorer;
Scorable scorer;
float[] scoreSums = new float[INITIAL_ARRAY_SIZE];
TermsWithScoreCollector(Function<DV> docValuesCall, ScoreMode scoreMode) {
@ -58,7 +58,7 @@ abstract class TermsWithScoreCollector<DV> extends DocValuesTermsCollector<DV>
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
}

View File

@ -142,8 +142,8 @@ public class ToChildBlockJoinQuery extends Query {
}
@Override
public Collection<ChildScorer> getChildren() {
return Collections.singleton(new ChildScorer(parentScorer, "BLOCK_JOIN"));
public Collection<ChildScorable> getChildren() {
return Collections.singleton(new ChildScorable(parentScorer, "BLOCK_JOIN"));
}
@Override

View File

@ -280,8 +280,8 @@ public class ToParentBlockJoinQuery extends Query {
}
@Override
public Collection<ChildScorer> getChildren() {
return Collections.singleton(new ChildScorer(childScorer, "BLOCK_JOIN"));
public Collection<ChildScorable> getChildren() {
return Collections.singleton(new ChildScorable(childScorer, "BLOCK_JOIN"));
}
@Override

View File

@ -1426,7 +1426,7 @@ public class TestJoinUtil extends LuceneTestCase {
if (multipleValuesPerDocument) {
searcher.search(new TermQuery(new Term("value", uniqueRandomValue)), new SimpleCollector() {
private Scorer scorer;
private Scorable scorer;
private SortedSetDocValues docTermOrds;
@Override
@ -1453,7 +1453,7 @@ public class TestJoinUtil extends LuceneTestCase {
}
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
this.scorer = scorer;
}
@ -1465,7 +1465,7 @@ public class TestJoinUtil extends LuceneTestCase {
} else {
searcher.search(new TermQuery(new Term("value", uniqueRandomValue)), new SimpleCollector() {
private Scorer scorer;
private Scorable scorer;
private BinaryDocValues terms;
@Override
@ -1494,7 +1494,7 @@ public class TestJoinUtil extends LuceneTestCase {
}
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
this.scorer = scorer;
}
@ -1557,7 +1557,7 @@ public class TestJoinUtil extends LuceneTestCase {
}
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
}
@Override

View File

@ -38,8 +38,8 @@ import org.apache.lucene.document.FieldType;
import org.apache.lucene.index.*;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.SimpleCollector;
import org.apache.lucene.search.similarities.Similarity;
import org.apache.lucene.store.RAMDirectory;
@ -687,7 +687,7 @@ public class MemoryIndex {
try {
final float[] scores = new float[1]; // inits to 0.0f (no match)
searcher.search(query, new SimpleCollector() {
private Scorer scorer;
private Scorable scorer;
@Override
public void collect(int doc) throws IOException {
@ -695,7 +695,7 @@ public class MemoryIndex {
}
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
this.scorer = scorer;
}

View File

@ -175,10 +175,10 @@ public abstract class DiversifiedTopDocsCollector extends
final NumericDocValues keySource = getKeys(context);
return new LeafCollector() {
Scorer scorer;
Scorable scorer;
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
}

View File

@ -36,7 +36,7 @@ public class DocValuesStatsCollector implements Collector {
if (!shouldProcess) {
// Stats cannot be computed for this segment, therefore consider all matching documents as a 'miss'.
return new LeafCollector() {
@Override public void setScorer(Scorer scorer) throws IOException {}
@Override public void setScorer(Scorable scorer) throws IOException {}
@Override
public void collect(int doc) throws IOException {
@ -47,7 +47,7 @@ public class DocValuesStatsCollector implements Collector {
}
return new LeafCollector() {
@Override public void setScorer(Scorer scorer) throws IOException {}
@Override public void setScorer(Scorable scorer) throws IOException {}
@Override
public void collect(int doc) throws IOException {

View File

@ -18,15 +18,15 @@ package org.apache.lucene.queryparser.surround.query;
import java.io.IOException;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.queryparser.surround.parser.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.SimpleCollector;
import org.apache.lucene.queryparser.surround.parser.QueryParser;
import org.junit.Assert;
public class BooleanQueryTst {
@ -58,7 +58,7 @@ public class BooleanQueryTst {
class TestCollector extends SimpleCollector { // FIXME: use check hits from Lucene tests
int totalMatched;
boolean[] encountered;
private Scorer scorer = null;
private Scorable scorer = null;
private int docBase = 0;
TestCollector() {
@ -67,7 +67,7 @@ public class BooleanQueryTst {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
}

View File

@ -57,11 +57,11 @@ final class CoveringScorer extends Scorer {
}
@Override
public final Collection<ChildScorer> getChildren() throws IOException {
List<ChildScorer> matchingChildren = new ArrayList<>();
public final Collection<ChildScorable> getChildren() throws IOException {
List<ChildScorable> matchingChildren = new ArrayList<>();
setTopListAndFreqIfNecessary();
for (DisiWrapper s = topList; s != null; s = s.next) {
matchingChildren.add(new ChildScorer(s.scorer, "SHOULD"));
matchingChildren.add(new ChildScorable(s.scorer, "SHOULD"));
}
return matchingChildren;
}

View File

@ -25,7 +25,7 @@ import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.LeafFieldComparator;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.spatial3d.geom.DistanceStyle;
import org.apache.lucene.spatial3d.geom.GeoDistanceShape;
import org.apache.lucene.spatial3d.geom.PlanetModel;
@ -60,7 +60,7 @@ class Geo3DPointDistanceComparator extends FieldComparator<Double> implements Le
}
@Override
public void setScorer(Scorer scorer) {}
public void setScorer(Scorable scorer) {}
@Override
public int compare(int slot1, int slot2) {

View File

@ -25,7 +25,7 @@ import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.LeafFieldComparator;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.spatial3d.geom.DistanceStyle;
import org.apache.lucene.spatial3d.geom.GeoOutsideDistance;
import org.apache.lucene.spatial3d.geom.PlanetModel;
@ -50,7 +50,7 @@ class Geo3DPointOutsideDistanceComparator extends FieldComparator<Double> implem
}
@Override
public void setScorer(Scorer scorer) {}
public void setScorer(Scorable scorer) {}
@Override
public int compare(int slot1, int slot2) {

View File

@ -44,7 +44,7 @@ import static org.apache.lucene.search.suggest.document.TopSuggestDocs.SuggestSc
* Subclasses should only override
* {@link TopSuggestDocsCollector#collect(int, CharSequence, CharSequence, float)}.
* <p>
* NOTE: {@link #setScorer(org.apache.lucene.search.Scorer)} and
* NOTE: {@link #setScorer(org.apache.lucene.search.Scorable)} and
* {@link #collect(int)} is not used
*
* @lucene.experimental

View File

@ -59,7 +59,7 @@ final class AssertingBulkScorer extends BulkScorer {
@Override
public void score(LeafCollector collector, Bits acceptDocs) throws IOException {
assert max == 0;
collector = new AssertingLeafCollector(random, collector, 0, PostingsEnum.NO_MORE_DOCS, scoreMode);
collector = new AssertingLeafCollector(collector, 0, PostingsEnum.NO_MORE_DOCS);
if (random.nextBoolean()) {
try {
final int next = score(collector, acceptDocs, 0, PostingsEnum.NO_MORE_DOCS);
@ -77,7 +77,7 @@ final class AssertingBulkScorer extends BulkScorer {
assert min >= this.max: "Scoring backward: min=" + min + " while previous max was max=" + this.max;
assert min <= max : "max must be greater than min, got min=" + min + ", and max=" + max;
this.max = max;
collector = new AssertingLeafCollector(random, collector, min, max, scoreMode);
collector = new AssertingLeafCollector(collector, min, max);
final int next = in.score(collector, acceptDocs, min, max);
assert next >= max;
if (max >= maxDoc || next >= maxDoc) {

View File

@ -17,7 +17,6 @@
package org.apache.lucene.search;
import java.io.IOException;
import java.util.Random;
import org.apache.lucene.index.LeafReaderContext;
@ -26,27 +25,25 @@ import org.apache.lucene.index.LeafReaderContext;
*/
class AssertingCollector extends FilterCollector {
private final Random random;
private int maxDoc = -1;
/** Wrap the given collector in order to add assertions. */
public static Collector wrap(Random random, Collector in) {
public static Collector wrap(Collector in) {
if (in instanceof AssertingCollector) {
return in;
}
return new AssertingCollector(random, in);
return new AssertingCollector(in);
}
private AssertingCollector(Random random, Collector in) {
private AssertingCollector(Collector in) {
super(in);
this.random = random;
}
@Override
public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
final LeafCollector in = super.getLeafCollector(context);
final int docBase = context.docBase;
return new AssertingLeafCollector(random, in, 0, DocIdSetIterator.NO_MORE_DOCS, scoreMode()) {
return new AssertingLeafCollector(in, 0, DocIdSetIterator.NO_MORE_DOCS) {
@Override
public void collect(int doc) throws IOException {
// check that documents are scored in order globally,

View File

@ -69,7 +69,7 @@ public class AssertingIndexSearcher extends IndexSearcher {
@Override
protected void search(List<LeafReaderContext> leaves, Weight weight, Collector collector) throws IOException {
assert weight instanceof AssertingWeight;
super.search(leaves, weight, AssertingCollector.wrap(random, collector));
super.search(leaves, weight, AssertingCollector.wrap(collector));
}
@Override

View File

@ -17,32 +17,27 @@
package org.apache.lucene.search;
import java.io.IOException;
import java.util.Random;
/** Wraps another Collector and checks that
* order is respected. */
class AssertingLeafCollector extends FilterLeafCollector {
private final Random random;
private final int min;
private final int max;
private final ScoreMode scoreMode;
private Scorer scorer;
private Scorable scorer;
private int lastCollected = -1;
AssertingLeafCollector(Random random, LeafCollector collector, int min, int max, ScoreMode scoreMode) {
AssertingLeafCollector(LeafCollector collector, int min, int max) {
super(collector);
this.random = random;
this.min = min;
this.max = max;
this.scoreMode = scoreMode;
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
super.setScorer(AssertingScorer.wrap(random, scorer, scoreMode));
super.setScorer(AssertingScorable.wrap(scorer));
}
@Override

View File

@ -0,0 +1,64 @@
/*
* 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;
/**
* Wraps another Scorable and asserts that scores are reasonable
* and only called when positioned
*/
public class AssertingScorable extends FilterScorable {
public AssertingScorable(Scorable in) {
super(in);
}
@Override
public float score() throws IOException {
int docId = docID();
assert docId != -1 && docId != DocIdSetIterator.NO_MORE_DOCS : "score() called on unpositioned Scorable docid=" + docID();
final float score = in.score();
assert !Float.isNaN(score) : "NaN score for in="+in;
return score;
}
@Override
public void setMinCompetitiveScore(float minScore) {
in.setMinCompetitiveScore(minScore);
}
public static Scorable wrap(Scorable in) {
if (in instanceof AssertingScorable) {
return in;
}
return new AssertingScorable(in);
}
public static Scorable unwrap(Scorable in) {
while (true) {
if (in instanceof AssertingScorable)
in = ((AssertingScorable)in).in;
else if (in instanceof AssertingScorer)
in = ((AssertingScorer)in).in;
else
return in;
}
}
}

View File

@ -107,12 +107,12 @@ public class AssertingScorer extends Scorer {
}
@Override
public Collection<ChildScorer> getChildren() {
public Collection<ChildScorable> getChildren() {
// We cannot hide that we hold a single child, else
// collectors (e.g. ToParentBlockJoinCollector) that
// need to walk the scorer tree will miss/skip the
// Scorer we wrap:
return Collections.singletonList(new ChildScorer(in, "SHOULD"));
return Collections.singletonList(new ChildScorable(in, "SHOULD"));
}
@Override

View File

@ -48,9 +48,9 @@ public class BulkScorerWrapperScorer extends Scorer {
final int min = Math.max(target, next);
final int max = min + docs.length;
next = scorer.score(new LeafCollector() {
Scorer scorer;
Scorable scorer;
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
}
@Override

View File

@ -119,7 +119,7 @@ public class CheckHits {
}
private int base = 0;
@Override
public void setScorer(Scorer scorer) throws IOException {}
public void setScorer(Scorable scorer) throws IOException {}
@Override
public void collect(int doc) {
bag.add(Integer.valueOf(doc + base));
@ -487,7 +487,7 @@ public class CheckHits {
String d;
boolean deep;
Scorer scorer;
Scorable scorer;
private int base = 0;
/** Constructs an instance which does shallow tests on the Explanation */
@ -502,7 +502,7 @@ public class CheckHits {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
}

View File

@ -295,13 +295,13 @@ public class QueryUtils {
final LeafReader lastReader[] = {null};
s.search(q, new SimpleCollector() {
private Scorer sc;
private Scorable sc;
private Scorer scorer;
private DocIdSetIterator iterator;
private int leafPtr;
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
this.sc = scorer;
}
@ -437,10 +437,10 @@ public class QueryUtils {
final List<LeafReaderContext> context = s.getTopReaderContext().leaves();
Query rewritten = s.rewrite(q);
s.search(q,new SimpleCollector() {
private Scorer scorer;
private Scorable scorer;
private int leafPtr;
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
this.scorer = scorer;
}
@Override
@ -550,9 +550,9 @@ public class QueryUtils {
iterator.advance(min);
}
final int next = bulkScorer.score(new LeafCollector() {
Scorer scorer2;
Scorable scorer2;
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer2 = scorer;
}
@Override
@ -571,7 +571,7 @@ public class QueryUtils {
if (scorer.docID() == DocIdSetIterator.NO_MORE_DOCS) {
bulkScorer.score(new LeafCollector() {
@Override
public void setScorer(Scorer scorer) throws IOException {}
public void setScorer(Scorable scorer) throws IOException {}
@Override
public void collect(int doc) throws IOException {

View File

@ -508,7 +508,7 @@ public class LTRScoringQuery extends Query {
}
@Override
public Collection<ChildScorer> getChildren() throws IOException {
public Collection<ChildScorable> getChildren() throws IOException {
return featureTraversalScorer.getChildren();
}
@ -592,10 +592,10 @@ public class LTRScoringQuery extends Query {
}
@Override
public final Collection<ChildScorer> getChildren() {
final ArrayList<ChildScorer> children = new ArrayList<>();
public final Collection<ChildScorable> getChildren() {
final ArrayList<ChildScorable> children = new ArrayList<>();
for (final DisiWrapper scorer : subScorers) {
children.add(new ChildScorer(scorer.scorer, "SHOULD"));
children.add(new ChildScorable(scorer.scorer, "SHOULD"));
}
return children;
}
@ -674,10 +674,10 @@ public class LTRScoringQuery extends Query {
}
@Override
public final Collection<ChildScorer> getChildren() {
final ArrayList<ChildScorer> children = new ArrayList<>();
public final Collection<ChildScorable> getChildren() {
final ArrayList<ChildScorable> children = new ArrayList<>();
for (final Scorer scorer : featureScorers) {
children.add(new ChildScorer(scorer, "SHOULD"));
children.add(new ChildScorable(scorer, "SHOULD"));
}
return children;
}

View File

@ -35,9 +35,9 @@ import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
@ -280,7 +280,7 @@ public class TestLTRReRankingPipeline extends LuceneTestCase {
LTRScoringQuery.ModelWeight wgt = query.createWeight(null, ScoreMode.COMPLETE, 1f);
LTRScoringQuery.ModelWeight.ModelScorer modelScr = wgt.scorer(null);
modelScr.getDocInfo().setOriginalDocScore(1f);
for (final Scorer.ChildScorer feat : modelScr.getChildren()) {
for (final Scorable.ChildScorable feat : modelScr.getChildren()) {
assertNotNull(((Feature.FeatureWeight.FeatureScorer) feat.child).getDocInfo().getOriginalDocScore());
}
@ -296,7 +296,7 @@ public class TestLTRReRankingPipeline extends LuceneTestCase {
wgt = query.createWeight(null, ScoreMode.COMPLETE, 1f);
modelScr = wgt.scorer(null);
modelScr.getDocInfo().setOriginalDocScore(1f);
for (final Scorer.ChildScorer feat : modelScr.getChildren()) {
for (final Scorable.ChildScorable feat : modelScr.getChildren()) {
assertNotNull(((Feature.FeatureWeight.FeatureScorer) feat.child).getDocInfo().getOriginalDocScore());
}
}

View File

@ -50,9 +50,9 @@ import org.apache.lucene.search.Collector;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.LeafCollector;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.TermInSetQuery;
import org.apache.lucene.search.TopDocs;
@ -565,7 +565,7 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia
return new LeafCollector() {
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
for (ObjectCursor<LeafCollector> c : leafCollectors.values()) {
c.value.setScorer(scorer);
}
@ -642,7 +642,7 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia
return new LeafCollector() {
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
for (ObjectCursor<LeafCollector> c : leafCollectors.values()) {
c.value.setScorer(scorer);
}

View File

@ -1497,7 +1497,7 @@ public class QueryComponent extends SearchComponent
}
@Override
public Collection<ChildScorer> getChildren() {
public Collection<ChildScorable> getChildren() {
throw new UnsupportedOperationException();
}
}

View File

@ -54,6 +54,7 @@ import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.LeafFieldComparator;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Sort;
@ -968,7 +969,7 @@ public class CollapsingQParserPlugin extends QParserPlugin {
@Override public ScoreMode scoreMode() { return needsScores ? ScoreMode.COMPLETE : super.scoreMode(); }
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.collapseStrategy.setScorer(scorer);
}
@ -1443,7 +1444,7 @@ public class CollapsingQParserPlugin extends QParserPlugin {
private static abstract class OrdFieldValueStrategy {
protected int nullPolicy;
protected int[] ords;
protected Scorer scorer;
protected Scorable scorer;
protected FloatArrayList nullScores;
protected float nullScore;
protected float[] scores;
@ -1520,7 +1521,7 @@ public class CollapsingQParserPlugin extends QParserPlugin {
return collapsedSet;
}
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
}
@ -1934,7 +1935,7 @@ public class CollapsingQParserPlugin extends QParserPlugin {
}
@Override
public void setScorer(Scorer s) throws IOException {
public void setScorer(Scorable s) throws IOException {
super.setScorer(s);
this.compareState.setScorer(s);
}
@ -2645,7 +2646,7 @@ public class CollapsingQParserPlugin extends QParserPlugin {
leafFieldComparators[clause] = fieldComparators[clause].getLeafComparator(context);
}
}
public void setScorer(Scorer s) throws IOException {
public void setScorer(Scorable s) throws IOException {
for (int clause = 0; clause < numClauses; clause++) {
leafFieldComparators[clause].setScorer(s);
}

View File

@ -20,10 +20,10 @@ package org.apache.solr.search;
import java.io.IOException;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.LeafCollector;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.LeafCollector;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.SimpleCollector;
@ -35,7 +35,7 @@ public class DelegatingCollector extends SimpleCollector {
protected Collector delegate;
protected LeafCollector leafDelegate;
protected Scorer scorer;
protected Scorable scorer;
protected LeafReaderContext context;
protected int docBase;
@ -56,7 +56,7 @@ public class DelegatingCollector extends SimpleCollector {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
this.scorer = scorer;
if (leafDelegate != null) {
leafDelegate.setScorer(scorer);

View File

@ -20,8 +20,8 @@ import java.io.IOException;
import java.util.ArrayList;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.SimpleCollector;
import org.apache.lucene.util.FixedBitSet;
@ -92,7 +92,7 @@ public class DocSetCollector extends SimpleCollector {
}
@Override
public void setScorer(Scorer scorer) throws IOException {
public void setScorer(Scorable scorer) throws IOException {
}
@Override

View File

@ -25,9 +25,9 @@ import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.LeafCollector;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.TopDocsCollector;
import org.apache.lucene.search.TotalHits;
@ -147,7 +147,7 @@ public class ExportQParserPlugin extends QParserPlugin {
return new LeafCollector() {
@Override
public void setScorer(Scorer scorer) throws IOException {}
public void setScorer(Scorable scorer) throws IOException {}
@Override
public void collect(int docId) throws IOException{

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import com.google.common.primitives.Longs;
import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
@ -30,8 +31,8 @@ import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.LeafCollector;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Weight;
import org.apache.lucene.util.BitDocIdSet;
import org.apache.lucene.util.Bits;
@ -46,8 +47,6 @@ import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.StrField;
import com.google.common.primitives.Longs;
/**
* syntax fq={!hash workers=11 worker=4 keys=field1,field2}
* */
@ -257,7 +256,7 @@ public class HashQParserPlugin extends QParserPlugin {
this.worker = worker;
}
public void setScorer(Scorer scorer) throws IOException{
public void setScorer(Scorable scorer) throws IOException{
leafCollector.setScorer(scorer);
}

View File

@ -19,13 +19,13 @@ package org.apache.solr.search;
import java.io.IOException;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.Scorable;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.SimpleCollector;
/** A {@link Collector} for the maximum score value. */
public class MaxScoreCollector extends SimpleCollector {
private Scorer scorer;
private Scorable scorer;
private float maxScore = Float.MIN_VALUE;
private boolean collectedAnyHits = false;
@ -43,7 +43,7 @@ public class MaxScoreCollector extends SimpleCollector {
}
@Override
public void setScorer(Scorer scorer) {
public void setScorer(Scorable scorer) {
this.scorer = scorer;
}

Some files were not shown because too many files have changed in this diff Show More