mirror of https://github.com/apache/lucene.git
Revert "LUCENE-7628: Scorer.getChildren() returns only matching Scorers"
This reverts commit 5bdc492c9c
.
This commit is contained in:
parent
d34f549df6
commit
94e3460305
|
@ -77,11 +77,6 @@ API Changes
|
|||
* LUCENE-7643: Replaced doc-values queries in lucene/sandbox with factory
|
||||
methods on the *DocValuesField classes. (Adrien Grand)
|
||||
|
||||
* LUCENE-7628: Scorer.getChildren() now only returns Scorers that are
|
||||
positioned on the current document, and can throw an IOException.
|
||||
AssertingScorer checks that getChildren() is not called on an unpositioned
|
||||
Scorer. (Alan Woodward, Adrien Grand)
|
||||
|
||||
New Features
|
||||
|
||||
* LUCENE-7623: Add FunctionScoreQuery and FunctionMatchQuery (Alan Woodward,
|
||||
|
|
|
@ -194,9 +194,9 @@ abstract class DisjunctionScorer extends Scorer {
|
|||
protected abstract float score(DisiWrapper topList) throws IOException;
|
||||
|
||||
@Override
|
||||
public final Collection<ChildScorer> getChildren() throws IOException {
|
||||
public final Collection<ChildScorer> getChildren() {
|
||||
ArrayList<ChildScorer> children = new ArrayList<>();
|
||||
for (DisiWrapper scorer = getSubMatches(); scorer != null; scorer = scorer.next) {
|
||||
for (DisiWrapper scorer : subScorers) {
|
||||
children.add(new ChildScorer(scorer.scorer, "SHOULD"));
|
||||
}
|
||||
return children;
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.lucene.search;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.LongStream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
@ -89,6 +90,7 @@ final class MinShouldMatchSumScorer extends Scorer {
|
|||
final DisiWrapper[] tail;
|
||||
int tailSize;
|
||||
|
||||
final Collection<ChildScorer> childScorers;
|
||||
final long cost;
|
||||
|
||||
MinShouldMatchSumScorer(Weight weight, Collection<Scorer> scorers, int minShouldMatch) {
|
||||
|
@ -113,17 +115,17 @@ final class MinShouldMatchSumScorer extends Scorer {
|
|||
addLead(new DisiWrapper(scorer));
|
||||
}
|
||||
|
||||
List<ChildScorer> children = new ArrayList<>();
|
||||
for (Scorer scorer : scorers) {
|
||||
children.add(new ChildScorer(scorer, "SHOULD"));
|
||||
}
|
||||
this.childScorers = Collections.unmodifiableCollection(children);
|
||||
this.cost = cost(scorers.stream().map(Scorer::iterator).mapToLong(DocIdSetIterator::cost), scorers.size(), minShouldMatch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Collection<ChildScorer> getChildren() throws IOException {
|
||||
List<ChildScorer> matchingScorers = new ArrayList<>();
|
||||
updateFreq();
|
||||
for (DisiWrapper s = lead; s != null; s = s.next) {
|
||||
matchingScorers.add(new ChildScorer(s.scorer, "SHOULD"));
|
||||
}
|
||||
return matchingScorers;
|
||||
public final Collection<ChildScorer> getChildren() {
|
||||
return childScorers;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -77,17 +77,9 @@ public abstract class Scorer {
|
|||
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.
|
||||
*
|
||||
* This method should only be called when the Scorer is positioned
|
||||
*
|
||||
* @lucene.experimental
|
||||
*/
|
||||
public Collection<ChildScorer> getChildren() throws IOException {
|
||||
/** Returns child sub-scorers
|
||||
* @lucene.experimental */
|
||||
public Collection<ChildScorer> getChildren() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
|
|
@ -169,7 +169,7 @@ public class TestBooleanQueryVisitSubscorers extends LuceneTestCase {
|
|||
};
|
||||
}
|
||||
|
||||
private void fillLeaves(Scorer scorer, Set<Scorer> set) throws IOException {
|
||||
private void fillLeaves(Scorer scorer, Set<Scorer> set) {
|
||||
if (scorer.getWeight().getQuery() instanceof TermQuery) {
|
||||
set.add(scorer);
|
||||
} else {
|
||||
|
@ -189,39 +189,6 @@ public class TestBooleanQueryVisitSubscorers extends LuceneTestCase {
|
|||
|
||||
}
|
||||
|
||||
public void testDisjunctionMatches() throws IOException {
|
||||
BooleanQuery.Builder bq1 = new BooleanQuery.Builder();
|
||||
bq1.add(new TermQuery(new Term(F1, "lucene")), Occur.SHOULD);
|
||||
bq1.add(new PhraseQuery(F2, "search", "engine"), Occur.SHOULD);
|
||||
|
||||
Weight w1 = scorerSearcher.createNormalizedWeight(bq1.build(), true);
|
||||
Scorer s1 = w1.scorer(reader.leaves().get(0));
|
||||
assertEquals(0, s1.iterator().nextDoc());
|
||||
assertEquals(2, s1.getChildren().size());
|
||||
|
||||
BooleanQuery.Builder bq2 = new BooleanQuery.Builder();
|
||||
bq2.add(new TermQuery(new Term(F1, "lucene")), Occur.SHOULD);
|
||||
bq2.add(new PhraseQuery(F2, "search", "library"), Occur.SHOULD);
|
||||
|
||||
Weight w2 = scorerSearcher.createNormalizedWeight(bq2.build(), true);
|
||||
Scorer s2 = w2.scorer(reader.leaves().get(0));
|
||||
assertEquals(0, s2.iterator().nextDoc());
|
||||
assertEquals(1, s2.getChildren().size());
|
||||
}
|
||||
|
||||
public void testMinShouldMatchMatches() throws IOException {
|
||||
BooleanQuery.Builder bq = new BooleanQuery.Builder();
|
||||
bq.add(new TermQuery(new Term(F1, "lucene")), Occur.SHOULD);
|
||||
bq.add(new TermQuery(new Term(F2, "lucene")), Occur.SHOULD);
|
||||
bq.add(new PhraseQuery(F2, "search", "library"), Occur.SHOULD);
|
||||
bq.setMinimumNumberShouldMatch(2);
|
||||
|
||||
Weight w = scorerSearcher.createNormalizedWeight(bq.build(), true);
|
||||
Scorer s = w.scorer(reader.leaves().get(0));
|
||||
assertEquals(0, s.iterator().nextDoc());
|
||||
assertEquals(2, s.getChildren().size());
|
||||
}
|
||||
|
||||
public void testGetChildrenMinShouldMatchSumScorer() throws IOException {
|
||||
final BooleanQuery.Builder query = new BooleanQuery.Builder();
|
||||
query.add(new TermQuery(new Term(F2, "nutch")), Occur.SHOULD);
|
||||
|
@ -238,9 +205,9 @@ public class TestBooleanQueryVisitSubscorers extends LuceneTestCase {
|
|||
"ConjunctionScorer\n" +
|
||||
" MUST ConstantScoreScorer\n" +
|
||||
" MUST MinShouldMatchSumScorer\n" +
|
||||
" SHOULD TermScorer body:web\n" +
|
||||
" SHOULD TermScorer body:nutch\n" +
|
||||
" SHOULD TermScorer body:crawler\n" +
|
||||
" SHOULD TermScorer body:nutch",
|
||||
" SHOULD TermScorer body:web",
|
||||
summary);
|
||||
}
|
||||
}
|
||||
|
@ -294,7 +261,7 @@ 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 Scorer scorer, final int indent) {
|
||||
builder.append(scorer.getClass().getSimpleName());
|
||||
if (scorer instanceof TermScorer) {
|
||||
TermQuery termQuery = (TermQuery) scorer.getWeight().getQuery();
|
||||
|
|
|
@ -68,6 +68,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 Set<String> relationships;
|
||||
|
||||
public CountingCollector(Collector other) {
|
||||
|
@ -79,15 +80,13 @@ public class TestSubScorerFreqs extends LuceneTestCase {
|
|||
this.relationships = relationships;
|
||||
}
|
||||
|
||||
private Map<Query, Scorer> getSubScorers(Scorer scorer) throws IOException {
|
||||
Map<Query, Scorer> collected = new HashMap<>();
|
||||
public void setSubScorers(Scorer scorer, String relationship) {
|
||||
for (ChildScorer child : scorer.getChildren()) {
|
||||
if (scorer instanceof AssertingScorer || relationships.contains(child.relationship)) {
|
||||
collected.put(scorer.getWeight().getQuery(), scorer);
|
||||
setSubScorers(child.child, child.relationship);
|
||||
}
|
||||
collected.putAll(getSubScorers(child.child));
|
||||
}
|
||||
return collected;
|
||||
subScorers.put(scorer.getWeight().getQuery(), scorer);
|
||||
}
|
||||
|
||||
public LeafCollector getLeafCollector(LeafReaderContext context)
|
||||
|
@ -95,12 +94,9 @@ public class TestSubScorerFreqs extends LuceneTestCase {
|
|||
final int docBase = context.docBase;
|
||||
return new FilterLeafCollector(super.getLeafCollector(context)) {
|
||||
|
||||
Scorer scorer;
|
||||
|
||||
@Override
|
||||
public void collect(int doc) throws IOException {
|
||||
final Map<Query, Float> freqs = new HashMap<Query, Float>();
|
||||
final Map<Query, Scorer> subScorers = getSubScorers(scorer);
|
||||
for (Map.Entry<Query, Scorer> ent : subScorers.entrySet()) {
|
||||
Scorer value = ent.getValue();
|
||||
int matchId = value.docID();
|
||||
|
@ -113,7 +109,8 @@ public class TestSubScorerFreqs extends LuceneTestCase {
|
|||
@Override
|
||||
public void setScorer(Scorer scorer) throws IOException {
|
||||
super.setScorer(scorer);
|
||||
this.scorer = scorer;
|
||||
subScorers.clear();
|
||||
setSubScorers(scorer, "TOP");
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.lucene.facet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -33,7 +32,7 @@ class AssertingSubDocsAtOnceCollector extends SimpleCollector {
|
|||
List<Scorer> allScorers;
|
||||
|
||||
@Override
|
||||
public void setScorer(Scorer s) throws IOException {
|
||||
public void setScorer(Scorer s) {
|
||||
// Gathers all scorers, including s and "under":
|
||||
allScorers = new ArrayList<>();
|
||||
allScorers.add(s);
|
||||
|
|
|
@ -78,7 +78,6 @@ public class AssertingScorer extends Scorer {
|
|||
// collectors (e.g. ToParentBlockJoinCollector) that
|
||||
// need to walk the scorer tree will miss/skip the
|
||||
// Scorer we wrap:
|
||||
assert iterating();
|
||||
return Collections.singletonList(new ChildScorer(in, "SHOULD"));
|
||||
}
|
||||
|
||||
|
|
|
@ -502,7 +502,7 @@ public class LTRScoringQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<ChildScorer> getChildren() throws IOException {
|
||||
public Collection<ChildScorer> getChildren() {
|
||||
return featureTraversalScorer.getChildren();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue