From e0ff51383cef314cd65a4c54028ac7146379eba3 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Mon, 9 Feb 2015 12:02:03 +0000 Subject: [PATCH] LUCENE-6226: Revert for more API discussions git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1658375 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 4 - .../org/apache/lucene/index/PostingsEnum.java | 9 +- .../apache/lucene/search/BooleanQuery.java | 4 +- .../apache/lucene/search/BooleanWeight.java | 9 +- .../lucene/search/ConstantScoreQuery.java | 5 +- .../lucene/search/DisjunctionMaxQuery.java | 8 +- .../apache/lucene/search/FilteredQuery.java | 4 +- .../apache/lucene/search/IndexSearcher.java | 24 +-- .../lucene/search/MatchAllDocsQuery.java | 2 +- .../lucene/search/MultiPhraseQuery.java | 12 +- .../org/apache/lucene/search/PhraseQuery.java | 12 +- .../java/org/apache/lucene/search/Query.java | 7 +- .../apache/lucene/search/QueryRescorer.java | 2 +- .../lucene/search/QueryWrapperFilter.java | 2 +- .../java/org/apache/lucene/search/Scorer.java | 2 +- .../org/apache/lucene/search/TermQuery.java | 12 +- .../org/apache/lucene/search/TermScorer.java | 1 - .../java/org/apache/lucene/search/Weight.java | 2 +- .../apache/lucene/search/package-info.java | 6 +- .../search/payloads/PayloadNearQuery.java | 2 +- .../search/payloads/PayloadTermQuery.java | 2 +- .../search/spans/FieldMaskingSpanQuery.java | 4 +- .../apache/lucene/search/spans/SpanQuery.java | 2 +- .../lucene/search/JustCompileSearch.java | 10 +- .../lucene/search/TestBooleanCoord.java | 3 +- .../apache/lucene/search/TestBooleanOr.java | 2 +- .../lucene/search/TestBooleanQuery.java | 5 +- .../TestBooleanQueryVisitSubscorers.java | 4 +- .../lucene/search/TestBooleanScorer.java | 2 +- .../lucene/search/TestConstantScoreQuery.java | 3 +- .../search/TestDisjunctionMaxQuery.java | 5 +- .../lucene/search/TestMinShouldMatch2.java | 3 +- .../lucene/search/TestMultiPhraseQuery.java | 3 +- .../apache/lucene/search/TestNeedsScores.java | 27 ++- .../TestPositiveScoresOnlyCollector.java | 3 +- .../lucene/search/TestQueryRescorer.java | 2 +- .../TestScoreCachingWrappingScorer.java | 3 +- .../lucene/search/TestTermQueryPostings.java | 172 ------------------ .../apache/lucene/search/TestTermScorer.java | 7 +- .../lucene/search/TestTopDocsMerge.java | 3 +- .../search/spans/TestNearSpansOrdered.java | 2 +- .../apache/lucene/search/spans/TestSpans.java | 2 +- .../lucene/facet/DrillSidewaysQuery.java | 6 +- .../lucene/search/grouping/TestGrouping.java | 3 +- .../search/join/TermsIncludingScoreQuery.java | 4 +- .../search/join/ToChildBlockJoinQuery.java | 6 +- .../search/join/ToParentBlockJoinQuery.java | 4 +- .../lucene/search/join/TestBlockJoin.java | 4 +- .../apache/lucene/queries/BoostingQuery.java | 4 +- .../lucene/queries/CustomScoreQuery.java | 10 +- .../lucene/queries/function/BoostedQuery.java | 8 +- .../queries/function/FunctionQuery.java | 2 +- .../valuesource/QueryValueSource.java | 3 +- .../lucene/search/TermAutomatonQuery.java | 2 +- .../lucene/search/AssertingIndexSearcher.java | 4 +- .../apache/lucene/search/AssertingQuery.java | 4 +- .../org/apache/lucene/search/QueryUtils.java | 15 +- .../org/apache/solr/schema/LatLonType.java | 2 +- .../solr/search/ExportQParserPlugin.java | 2 +- .../apache/solr/search/JoinQParserPlugin.java | 2 +- .../solr/search/ReRankQParserPlugin.java | 10 +- .../solr/search/SolrConstantScoreQuery.java | 2 +- .../apache/solr/search/SolrIndexSearcher.java | 2 +- .../org/apache/solr/search/WrappedQuery.java | 4 +- .../search/join/IgnoreAcceptDocsQuery.java | 4 +- .../solr/update/DeleteByQueryWrapper.java | 4 +- .../solr/search/TestRankQueryPlugin.java | 6 +- 67 files changed, 154 insertions(+), 361 deletions(-) delete mode 100644 lucene/core/src/test/org/apache/lucene/search/TestTermQueryPostings.java diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index bcc29ef07cb..06e1902f7b1 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -88,10 +88,6 @@ API Changes * LUCENE-6223: Move BooleanQuery.BooleanWeight to BooleanWeight. (Robert Muir) -* LUCENE-6226: Query.createWeight() and IndexSearcher.createNormalizedWeight() - now take an integer bitmask indicating which postings values should be - retrieved from the index. (Alan Woodward, Adrien Grand) - Other * LUCENE-6193: Collapse identical catch branches in try-catch statements. diff --git a/lucene/core/src/java/org/apache/lucene/index/PostingsEnum.java b/lucene/core/src/java/org/apache/lucene/index/PostingsEnum.java index 8ef50cdf981..4d91651bada 100644 --- a/lucene/core/src/java/org/apache/lucene/index/PostingsEnum.java +++ b/lucene/core/src/java/org/apache/lucene/index/PostingsEnum.java @@ -92,16 +92,17 @@ public abstract class PostingsEnum extends DocIdSetIterator { } /** - * Returns the next position, or -1 if positions are not available. - * Should only be called up to freq() times */ + * Returns the next position. If there are no more + * positions, or the iterator does not support positions, + * this will return DocsEnum.NO_MORE_POSITIONS */ public abstract int nextPosition() throws IOException; /** Returns start offset for the current position, or -1 - * if offsets are not available. */ + * if offsets were not indexed. */ public abstract int startOffset() throws IOException; /** Returns end offset for the current position, or -1 if - * offsets are not available. */ + * offsets were not indexed. */ public abstract int endOffset() throws IOException; /** Returns the payload at this position, or null if no diff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java b/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java index 9551e828ae7..9b159bf4f0e 100644 --- a/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java @@ -163,8 +163,8 @@ public class BooleanQuery extends Query implements Iterable { public final Iterator iterator() { return clauses().iterator(); } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { - return new BooleanWeight(this, searcher, postingsFlags, disableCoord); + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { + return new BooleanWeight(this, searcher, needsScores, disableCoord); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java b/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java index 7cb935c54b1..524f5d6b7ea 100644 --- a/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java +++ b/lucene/core/src/java/org/apache/lucene/search/BooleanWeight.java @@ -24,7 +24,6 @@ import java.util.Iterator; import java.util.List; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.similarities.Similarity; import org.apache.lucene.util.Bits; @@ -44,17 +43,17 @@ public class BooleanWeight extends Weight { private final boolean disableCoord; private final boolean needsScores; - public BooleanWeight(BooleanQuery query, IndexSearcher searcher, int postingsFlags, boolean disableCoord) throws IOException { + public BooleanWeight(BooleanQuery query, IndexSearcher searcher, boolean needsScores, boolean disableCoord) throws IOException { super(query); this.query = query; - this.needsScores = (postingsFlags & PostingsEnum.FLAG_FREQS) != 0; + this.needsScores = needsScores; this.similarity = searcher.getSimilarity(); this.disableCoord = disableCoord; weights = new ArrayList<>(query.clauses().size()); for (int i = 0 ; i < query.clauses().size(); i++) { BooleanClause c = query.clauses().get(i); - final int subQueryFlags = c.getOccur() == Occur.MUST_NOT ? PostingsEnum.FLAG_NONE : postingsFlags; - Weight w = c.getQuery().createWeight(searcher, subQueryFlags); + final boolean queryNeedsScores = needsScores && c.getOccur() != Occur.MUST_NOT; + Weight w = c.getQuery().createWeight(searcher, queryNeedsScores); weights.add(w); if (!c.isProhibited()) { maxCoord++; diff --git a/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java b/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java index c668dd2326e..898b395f841 100644 --- a/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java @@ -24,7 +24,6 @@ import java.util.Set; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.Term; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; @@ -112,7 +111,7 @@ public class ConstantScoreQuery extends Query { public ConstantWeight(IndexSearcher searcher) throws IOException { super(ConstantScoreQuery.this); - this.innerWeight = (query == null) ? null : query.createWeight(searcher, PostingsEnum.FLAG_NONE); + this.innerWeight = (query == null) ? null : query.createWeight(searcher, false); } @Override @@ -328,7 +327,7 @@ public class ConstantScoreQuery extends Query { } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { return new ConstantScoreQuery.ConstantWeight(searcher); } diff --git a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java index f995a4de99a..cfa19add59f 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java @@ -118,10 +118,10 @@ public class DisjunctionMaxQuery extends Query implements Iterable { protected ArrayList weights = new ArrayList<>(); // The Weight's for our subqueries, in 1-1 correspondence with disjuncts /** Construct the Weight for this Query searched by searcher. Recursively construct subquery weights. */ - public DisjunctionMaxWeight(IndexSearcher searcher, int postingsFlags) throws IOException { + public DisjunctionMaxWeight(IndexSearcher searcher, boolean needsScores) throws IOException { super(DisjunctionMaxQuery.this); for (Query disjunctQuery : disjuncts) { - weights.add(disjunctQuery.createWeight(searcher, postingsFlags)); + weights.add(disjunctQuery.createWeight(searcher, needsScores)); } } @@ -194,8 +194,8 @@ public class DisjunctionMaxQuery extends Query implements Iterable { /** Create the Weight used to score us */ @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { - return new DisjunctionMaxWeight(searcher, postingsFlags); + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { + return new DisjunctionMaxWeight(searcher, needsScores); } /** Optimize our representation and our subqueries representations diff --git a/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java b/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java index 3948242deb0..5af0b72af7d 100644 --- a/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java @@ -78,8 +78,8 @@ public class FilteredQuery extends Query { * This is accomplished by overriding the Scorer returned by the Weight. */ @Override - public Weight createWeight(final IndexSearcher searcher, int postingsFlags) throws IOException { - final Weight weight = query.createWeight (searcher, postingsFlags); + public Weight createWeight(final IndexSearcher searcher, boolean needsScores) throws IOException { + final Weight weight = query.createWeight (searcher, needsScores); return new Weight(FilteredQuery.this) { @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java index 37bbce29f35..596ede4784f 100644 --- a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java +++ b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java @@ -33,7 +33,6 @@ import org.apache.lucene.index.IndexReaderContext; import org.apache.lucene.index.IndexWriter; // javadocs import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.MultiFields; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.ReaderUtil; import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.StoredFieldVisitor; @@ -241,14 +240,13 @@ public class IndexSearcher { return collector.topDocs(); } else { final TopScoreDocCollector[] collectors = new TopScoreDocCollector[leafSlices.length]; - int postingsFlags = PostingsEnum.FLAG_NONE; + boolean needsScores = false; for (int i = 0; i < leafSlices.length; ++i) { collectors[i] = TopScoreDocCollector.create(numHits, after); - if (collectors[i].needsScores()) - postingsFlags |= PostingsEnum.FLAG_FREQS; + needsScores |= collectors[i].needsScores(); } - final Weight weight = createNormalizedWeight(query, postingsFlags); + final Weight weight = createNormalizedWeight(query, needsScores); final List> topDocsFutures = new ArrayList<>(leafSlices.length); for (int i = 0; i < leafSlices.length; ++i) { final LeafReaderContext[] leaves = leafSlices[i].leaves; @@ -340,8 +338,7 @@ public class IndexSearcher { */ public void search(Query query, Collector results) throws IOException { - int postingsFlags = results.needsScores() ? PostingsEnum.FLAG_FREQS : PostingsEnum.FLAG_NONE; - search(leafContexts, createNormalizedWeight(query, postingsFlags), results); + search(leafContexts, createNormalizedWeight(query, results.needsScores()), results); } /** Search implementation with arbitrary sorting. Finds @@ -465,14 +462,13 @@ public class IndexSearcher { return collector.topDocs(); } else { final TopFieldCollector[] collectors = new TopFieldCollector[leafSlices.length]; - int postingsFlags = PostingsEnum.FLAG_NONE; + boolean needsScores = false; for (int i = 0; i < leafSlices.length; ++i) { collectors[i] = TopFieldCollector.create(sort, numHits, after, fillFields, doDocScores, doMaxScore); - if (collectors[i].needsScores()) - postingsFlags |= PostingsEnum.FLAG_FREQS; + needsScores |= collectors[i].needsScores(); } - final Weight weight = createNormalizedWeight(query, postingsFlags); + final Weight weight = createNormalizedWeight(query, needsScores); final List> topDocsFutures = new ArrayList<>(leafSlices.length); for (int i = 0; i < leafSlices.length; ++i) { final LeafReaderContext[] leaves = leafSlices[i].leaves; @@ -569,7 +565,7 @@ public class IndexSearcher { * entire index. */ public Explanation explain(Query query, int doc) throws IOException { - return explain(createNormalizedWeight(query, PostingsEnum.FLAG_FREQS), doc); + return explain(createNormalizedWeight(query, true), doc); } /** Expert: low-level implementation method @@ -599,9 +595,9 @@ public class IndexSearcher { * can then directly be used to get a {@link Scorer}. * @lucene.internal */ - public Weight createNormalizedWeight(Query query, int postingsFlags) throws IOException { + public Weight createNormalizedWeight(Query query, boolean needsScores) throws IOException { query = rewrite(query); - Weight weight = query.createWeight(this, postingsFlags); + Weight weight = query.createWeight(this, needsScores); float v = weight.getValueForNormalization(); float norm = getSimilarity().queryNorm(v); if (Float.isInfinite(norm) || Float.isNaN(norm)) { diff --git a/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java b/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java index 3800a3824a6..8817abc0eed 100644 --- a/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java @@ -150,7 +150,7 @@ public class MatchAllDocsQuery extends Query { } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) { + public Weight createWeight(IndexSearcher searcher, boolean needsScores) { return new MatchAllDocsWeight(searcher); } diff --git a/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java b/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java index 3c8c23af90c..e515e39e5c6 100644 --- a/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java @@ -142,13 +142,11 @@ public class MultiPhraseQuery extends Query { private final Similarity.SimWeight stats; private final Map termContexts = new HashMap<>(); private final boolean needsScores; - private final int postingsFlags; - public MultiPhraseWeight(IndexSearcher searcher, int postingsFlags) + public MultiPhraseWeight(IndexSearcher searcher, boolean needsScores) throws IOException { super(MultiPhraseQuery.this); - this.needsScores = (postingsFlags & PostingsEnum.FLAG_FREQS) != 0; - this.postingsFlags = postingsFlags | PostingsEnum.FLAG_POSITIONS; + this.needsScores = needsScores; this.similarity = searcher.getSimilarity(); final IndexReaderContext context = searcher.getTopReaderContext(); @@ -230,7 +228,7 @@ public class MultiPhraseQuery extends Query { return null; } termsEnum.seekExact(term.bytes(), termState); - postingsEnum = termsEnum.postings(liveDocs, null, postingsFlags); + postingsEnum = termsEnum.postings(liveDocs, null, PostingsEnum.FLAG_POSITIONS); if (postingsEnum == null) { // term does exist, but has no positions @@ -298,8 +296,8 @@ public class MultiPhraseQuery extends Query { } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { - return new MultiPhraseWeight(searcher, postingsFlags); + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { + return new MultiPhraseWeight(searcher, needsScores); } /** Prints a user-readable version of this query. */ diff --git a/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java b/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java index e79522dadb1..55c47207c6a 100644 --- a/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java @@ -211,15 +211,13 @@ public class PhraseQuery extends Query { private class PhraseWeight extends Weight { private final Similarity similarity; private final Similarity.SimWeight stats; - private final int postingsFlags; private final boolean needsScores; private transient TermContext states[]; - public PhraseWeight(IndexSearcher searcher, int postingsFlags) + public PhraseWeight(IndexSearcher searcher, boolean needsScores) throws IOException { super(PhraseQuery.this); - this.postingsFlags = postingsFlags | PostingsEnum.FLAG_POSITIONS; - this.needsScores = (postingsFlags & PostingsEnum.FLAG_FREQS) != 0; + this.needsScores = needsScores; this.similarity = searcher.getSimilarity(); final IndexReaderContext context = searcher.getTopReaderContext(); states = new TermContext[terms.size()]; @@ -268,7 +266,7 @@ public class PhraseQuery extends Query { return null; } te.seekExact(t.bytes(), state); - PostingsEnum postingsEnum = te.postings(liveDocs, null, postingsFlags); + PostingsEnum postingsEnum = te.postings(liveDocs, null, PostingsEnum.FLAG_POSITIONS); // PhraseQuery on a field that did not index // positions. @@ -320,8 +318,8 @@ public class PhraseQuery extends Query { } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { - return new PhraseWeight(searcher, postingsFlags); + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { + return new PhraseWeight(searcher, needsScores); } /** diff --git a/lucene/core/src/java/org/apache/lucene/search/Query.java b/lucene/core/src/java/org/apache/lucene/search/Query.java index ece27c6348d..cd03ccb9f48 100644 --- a/lucene/core/src/java/org/apache/lucene/search/Query.java +++ b/lucene/core/src/java/org/apache/lucene/search/Query.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.util.Set; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.Term; /** The abstract base class for queries. @@ -75,10 +74,10 @@ public abstract class Query implements Cloneable { *

* Only implemented by primitive queries, which re-write to themselves. * - * @param postingsFlags Bitmask indicating which postings features should be returned - * by this query (see {@link PostingsEnum}) + * @param needsScores True if document scores ({@link Scorer#score}) or match + * frequencies ({@link Scorer#freq}) are needed. */ - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { throw new UnsupportedOperationException("Query " + this + " does not implement createWeight"); } diff --git a/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java b/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java index d89dd201904..b01668d9a86 100644 --- a/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java @@ -61,7 +61,7 @@ public abstract class QueryRescorer extends Rescorer { List leaves = searcher.getIndexReader().leaves(); - Weight weight = searcher.createNormalizedWeight(query, PostingsEnum.FLAG_FREQS); + Weight weight = searcher.createNormalizedWeight(query, true); // Now merge sort docIDs from hits, with reader's leaves: int hitUpto = 0; diff --git a/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java b/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java index 8d84bed6d72..4756d2cd55f 100644 --- a/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java +++ b/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java @@ -53,7 +53,7 @@ public class QueryWrapperFilter extends Filter { public DocIdSet getDocIdSet(final LeafReaderContext context, final Bits acceptDocs) throws IOException { // get a private context that is used to rewrite, createWeight and score eventually final LeafReaderContext privateContext = context.reader().getContext(); - final Weight weight = new IndexSearcher(privateContext).createNormalizedWeight(query, PostingsEnum.FLAG_NONE); + final Weight weight = new IndexSearcher(privateContext).createNormalizedWeight(query, false); return new DocIdSet() { @Override public DocIdSetIterator iterator() throws IOException { diff --git a/lucene/core/src/java/org/apache/lucene/search/Scorer.java b/lucene/core/src/java/org/apache/lucene/search/Scorer.java index 968b24d56df..bf6502ef74c 100644 --- a/lucene/core/src/java/org/apache/lucene/search/Scorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/Scorer.java @@ -73,7 +73,7 @@ public abstract class Scorer extends PostingsEnum { public Collection getChildren() { return Collections.emptyList(); } - + /** A child Scorer and its relationship to its parent. * the meaning of the relationship depends upon the parent query. * @lucene.experimental */ diff --git a/lucene/core/src/java/org/apache/lucene/search/TermQuery.java b/lucene/core/src/java/org/apache/lucene/search/TermQuery.java index 3eeb0d45ad3..3a353e5fdea 100644 --- a/lucene/core/src/java/org/apache/lucene/search/TermQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/TermQuery.java @@ -47,12 +47,12 @@ public class TermQuery extends Query { private final Similarity similarity; private final Similarity.SimWeight stats; private final TermContext termStates; - private final int postingsFlags; + private final boolean needsScores; - public TermWeight(IndexSearcher searcher, int postingsFlags, TermContext termStates) + public TermWeight(IndexSearcher searcher, boolean needsScores, TermContext termStates) throws IOException { super(TermQuery.this); - this.postingsFlags = postingsFlags; + this.needsScores = needsScores; assert termStates != null : "TermContext must not be null"; this.termStates = termStates; this.similarity = searcher.getSimilarity(); @@ -83,7 +83,7 @@ public class TermQuery extends Query { if (termsEnum == null) { return null; } - PostingsEnum docs = termsEnum.postings(acceptDocs, null, postingsFlags); + PostingsEnum docs = termsEnum.postings(acceptDocs, null, needsScores ? PostingsEnum.FLAG_FREQS : PostingsEnum.FLAG_NONE); assert docs != null; return new TermScorer(this, docs, similarity.simScorer(stats, context)); } @@ -168,7 +168,7 @@ public class TermQuery extends Query { } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { final IndexReaderContext context = searcher.getTopReaderContext(); final TermContext termState; if (perReaderTermState == null @@ -184,7 +184,7 @@ public class TermQuery extends Query { // we must not ignore the given docFreq - if set use the given value (lie) if (docFreq != -1) termState.setDocFreq(docFreq); - return new TermWeight(searcher, postingsFlags, termState); + return new TermWeight(searcher, needsScores, termState); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/TermScorer.java b/lucene/core/src/java/org/apache/lucene/search/TermScorer.java index 084bd281346..70808359bf4 100644 --- a/lucene/core/src/java/org/apache/lucene/search/TermScorer.java +++ b/lucene/core/src/java/org/apache/lucene/search/TermScorer.java @@ -26,7 +26,6 @@ import org.apache.lucene.util.BytesRef; /** Expert: A Scorer for documents matching a Term. */ final class TermScorer extends Scorer { - private final PostingsEnum postingsEnum; private final Similarity.SimScorer docScorer; diff --git a/lucene/core/src/java/org/apache/lucene/search/Weight.java b/lucene/core/src/java/org/apache/lucene/search/Weight.java index 16fbfc5ee16..8ba2403078a 100644 --- a/lucene/core/src/java/org/apache/lucene/search/Weight.java +++ b/lucene/core/src/java/org/apache/lucene/search/Weight.java @@ -41,7 +41,7 @@ import org.apache.lucene.util.Bits; * A Weight is used in the following way: *

    *
  1. A Weight is constructed by a top-level query, given a - * IndexSearcher ({@link Query#createWeight(IndexSearcher, int)}). + * IndexSearcher ({@link Query#createWeight(IndexSearcher, boolean)}). *
  2. The {@link #getValueForNormalization()} method is called on the * Weight to compute the query normalization factor * {@link Similarity#queryNorm(float)} of the query clauses contained in the diff --git a/lucene/core/src/java/org/apache/lucene/search/package-info.java b/lucene/core/src/java/org/apache/lucene/search/package-info.java index 64ded263f74..eba4bdd2fb7 100644 --- a/lucene/core/src/java/org/apache/lucene/search/package-info.java +++ b/lucene/core/src/java/org/apache/lucene/search/package-info.java @@ -358,7 +358,7 @@ * {@link org.apache.lucene.search.Query Query} class has several methods that are important for * derived classes: *
      - *
    1. {@link org.apache.lucene.search.Query#createWeight(IndexSearcher,int) createWeight(IndexSearcher searcher,boolean)} — A + *
    2. {@link org.apache.lucene.search.Query#createWeight(IndexSearcher,boolean) createWeight(IndexSearcher searcher,boolean)} — A * {@link org.apache.lucene.search.Weight Weight} is the internal representation of the * Query, so each Query implementation must * provide an implementation of Weight. See the subsection on {@link org.apache.lucene.search.Query#rewrite(org.apache.lucene.index.IndexReader) rewrite(IndexReader reader)} — Rewrites queries into primitive queries. Primitive queries are: * {@link org.apache.lucene.search.TermQuery TermQuery}, * {@link org.apache.lucene.search.BooleanQuery BooleanQuery}, and other queries that implement {@link org.apache.lucene.search.Query#createWeight(IndexSearcher,int) createWeight(IndexSearcher searcher,boolean)}
    3. + * >and other queries that implement {@link org.apache.lucene.search.Query#createWeight(IndexSearcher,boolean) createWeight(IndexSearcher searcher,boolean)} *
    * *

    The Weight Interface

    @@ -509,7 +509,7 @@ *

    Assuming we are not sorting (since sorting doesn't affect the raw Lucene score), * we call one of the search methods of the IndexSearcher, passing in the * {@link org.apache.lucene.search.Weight Weight} object created by - * {@link org.apache.lucene.search.IndexSearcher#createNormalizedWeight(org.apache.lucene.search.Query,int) + * {@link org.apache.lucene.search.IndexSearcher#createNormalizedWeight(org.apache.lucene.search.Query,boolean) * IndexSearcher.createNormalizedWeight(Query,boolean)}, * {@link org.apache.lucene.search.Filter Filter} and the number of results we want. * This method returns a {@link org.apache.lucene.search.TopDocs TopDocs} object, diff --git a/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java b/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java index a9e6b93184e..e46bb45e85e 100644 --- a/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java @@ -71,7 +71,7 @@ public class PayloadNearQuery extends SpanNearQuery { } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { return new PayloadNearSpanWeight(this, searcher); } diff --git a/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java b/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java index b208cc5c6a7..463a6a0f806 100644 --- a/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java @@ -67,7 +67,7 @@ public class PayloadTermQuery extends SpanTermQuery { } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { return new PayloadTermWeight(this, searcher); } diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java index af407d787a5..9b740f6526b 100644 --- a/lucene/core/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java @@ -106,8 +106,8 @@ public class FieldMaskingSpanQuery extends SpanQuery { } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { - return maskedQuery.createWeight(searcher, postingsFlags); + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { + return maskedQuery.createWeight(searcher, needsScores); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanQuery.java index 022a498cdf1..00bed758488 100644 --- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanQuery.java +++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanQuery.java @@ -42,7 +42,7 @@ public abstract class SpanQuery extends Query { public abstract String getField(); @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { return new SpanWeight(this, searcher); } diff --git a/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java b/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java index 2d77407a4f8..843c092fa7d 100644 --- a/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java +++ b/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java @@ -264,11 +264,6 @@ final class JustCompileSearch { throw new UnsupportedOperationException( UNSUPPORTED_MSG ); } - @Override - public boolean needsScores() { - throw new UnsupportedOperationException(UNSUPPORTED_MSG); - } - @Override public TopDocs topDocs() { throw new UnsupportedOperationException( UNSUPPORTED_MSG ); @@ -283,6 +278,11 @@ final class JustCompileSearch { public TopDocs topDocs( int start, int end ) { throw new UnsupportedOperationException( UNSUPPORTED_MSG ); } + + @Override + public boolean needsScores() { + throw new UnsupportedOperationException( UNSUPPORTED_MSG ); + } } static final class JustCompileWeight extends Weight { diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java index f6346a40d23..593a9702973 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java @@ -28,7 +28,6 @@ import org.apache.lucene.index.FieldInvertState; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.Term; import org.apache.lucene.search.similarities.Similarity; import org.apache.lucene.store.Directory; @@ -707,7 +706,7 @@ public class TestBooleanCoord extends LuceneTestCase { /** asserts score for our single matching good doc */ private void assertScore(final float expected, Query query) throws Exception { // test in-order - Weight weight = searcher.createNormalizedWeight(query, PostingsEnum.FLAG_FREQS); + Weight weight = searcher.createNormalizedWeight(query, true); Scorer scorer = weight.scorer(reader.leaves().get(0), null); assertTrue(scorer.docID() == -1 || scorer.docID() == DocIdSetIterator.NO_MORE_DOCS); assertEquals(0, scorer.nextDoc()); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java index 09194c288ee..2f7de6fa0cd 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java @@ -185,7 +185,7 @@ public class TestBooleanOr extends LuceneTestCase { bq.add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD); bq.add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD); - Weight w = s.createNormalizedWeight(bq, PostingsEnum.FLAG_FREQS); + Weight w = s.createNormalizedWeight(bq, true); assertEquals(1, s.getIndexReader().leaves().size()); BulkScorer scorer = w.bulkScorer(s.getIndexReader().leaves().get(0), null); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java index fa4575aabdb..be38c142ff0 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java @@ -34,7 +34,6 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.MultiReader; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.search.similarities.DefaultSimilarity; @@ -232,7 +231,7 @@ public class TestBooleanQuery extends LuceneTestCase { q.add(new BooleanClause(new TermQuery(new Term("field", term)), BooleanClause.Occur.SHOULD)); } - Weight weight = s.createNormalizedWeight(q, PostingsEnum.FLAG_FREQS); + Weight weight = s.createNormalizedWeight(q, true); Scorer scorer = weight.scorer(s.leafContexts.get(0), null); @@ -250,7 +249,7 @@ public class TestBooleanQuery extends LuceneTestCase { // verify exact match: for(int iter2=0;iter2<10;iter2++) { - weight = s.createNormalizedWeight(q, PostingsEnum.FLAG_FREQS); + weight = s.createNormalizedWeight(q, true); scorer = weight.scorer(s.leafContexts.get(0), null); if (VERBOSE) { diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanQueryVisitSubscorers.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanQueryVisitSubscorers.java index 3e8c9c07766..6b555db7af1 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanQueryVisitSubscorers.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanQueryVisitSubscorers.java @@ -282,8 +282,8 @@ public class TestBooleanQueryVisitSubscorers extends LuceneTestCase { static class BooleanQuery2 extends BooleanQuery { @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { - return new BooleanWeight(this, searcher, postingsFlags, false) { + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { + return new BooleanWeight(this, searcher, needsScores, false) { @Override public BulkScorer bulkScorer(LeafReaderContext context, Bits acceptDocs) throws IOException { Scorer scorer = scorer(context, acceptDocs); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java index 569517c2797..0aa716af7a8 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java @@ -70,7 +70,7 @@ public class TestBooleanScorer extends LuceneTestCase { } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { return new Weight(CrazyMustUseBulkScorerQuery.this) { @Override public Explanation explain(LeafReaderContext context, int doc) { diff --git a/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java index 07c7aa8b55c..70ca0947791 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java @@ -22,7 +22,6 @@ import java.io.IOException; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.search.similarities.DefaultSimilarity; @@ -68,7 +67,7 @@ public class TestConstantScoreQuery extends LuceneTestCase { assertEquals("Score differs from expected", expectedScore, this.scorer.score(), 0); count[0]++; } - + @Override public boolean needsScores() { return true; diff --git a/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java index d3ea5893b2b..384f99efcf0 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java @@ -34,7 +34,6 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.SlowCompositeReaderWrapper; import org.apache.lucene.index.StoredDocument; @@ -179,7 +178,7 @@ public class TestDisjunctionMaxQuery extends LuceneTestCase { QueryUtils.check(random(), dq, s); assertTrue(s.getTopReaderContext() instanceof LeafReaderContext); - final Weight dw = s.createNormalizedWeight(dq, PostingsEnum.FLAG_FREQS); + final Weight dw = s.createNormalizedWeight(dq, true); LeafReaderContext context = (LeafReaderContext)s.getTopReaderContext(); final Scorer ds = dw.scorer(context, context.reader().getLiveDocs()); final boolean skipOk = ds.advance(3) != DocIdSetIterator.NO_MORE_DOCS; @@ -195,7 +194,7 @@ public class TestDisjunctionMaxQuery extends LuceneTestCase { dq.add(tq("dek", "DOES_NOT_EXIST")); assertTrue(s.getTopReaderContext() instanceof LeafReaderContext); QueryUtils.check(random(), dq, s); - final Weight dw = s.createNormalizedWeight(dq, PostingsEnum.FLAG_FREQS); + final Weight dw = s.createNormalizedWeight(dq, true); LeafReaderContext context = (LeafReaderContext)s.getTopReaderContext(); final Scorer ds = dw.scorer(context, context.reader().getLiveDocs()); assertTrue("firsttime skipTo found no match", diff --git a/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java b/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java index c3f6f1abce7..829ba688bb3 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java @@ -31,7 +31,6 @@ import org.apache.lucene.document.SortedSetDocValuesField; import org.apache.lucene.document.StringField; import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.LeafReader; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.SortedSetDocValues; import org.apache.lucene.index.Term; @@ -125,7 +124,7 @@ public class TestMinShouldMatch2 extends LuceneTestCase { } bq.setMinimumNumberShouldMatch(minShouldMatch); - BooleanWeight weight = (BooleanWeight) searcher.createNormalizedWeight(bq, PostingsEnum.FLAG_FREQS); + BooleanWeight weight = (BooleanWeight) searcher.createNormalizedWeight(bq, true); switch (mode) { case DOC_VALUES: diff --git a/lucene/core/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java index a3a752cf700..4e36ad98e55 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java @@ -30,7 +30,6 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.MultiFields; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.index.TermsEnum; @@ -345,7 +344,7 @@ public class TestMultiPhraseQuery extends LuceneTestCase { MultiPhraseQuery query = new MultiPhraseQuery(); query.add(new Term[] { new Term("body", "this"), new Term("body", "that") }); query.add(new Term("body", "is")); - Weight weight = query.createWeight(searcher, PostingsEnum.FLAG_FREQS); + Weight weight = query.createWeight(searcher, true); assertEquals(10f * 10f, weight.getValueForNormalization(), 0.001f); writer.close(); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestNeedsScores.java b/lucene/core/src/test/org/apache/lucene/search/TestNeedsScores.java index 4b415d671cf..67a64d94694 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestNeedsScores.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestNeedsScores.java @@ -25,7 +25,6 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.TextField; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; @@ -64,15 +63,15 @@ public class TestNeedsScores extends LuceneTestCase { Query required = new TermQuery(new Term("field", "this")); Query prohibited = new TermQuery(new Term("field", "3")); BooleanQuery bq = new BooleanQuery(); - bq.add(new AssertNeedsScores(required, PostingsEnum.FLAG_FREQS), BooleanClause.Occur.MUST); - bq.add(new AssertNeedsScores(prohibited, PostingsEnum.FLAG_NONE), BooleanClause.Occur.MUST_NOT); + bq.add(new AssertNeedsScores(required, true), BooleanClause.Occur.MUST); + bq.add(new AssertNeedsScores(prohibited, false), BooleanClause.Occur.MUST_NOT); assertEquals(4, searcher.search(bq, 5).totalHits); // we exclude 3 } /** nested inside constant score query */ public void testConstantScoreQuery() throws Exception { Query term = new TermQuery(new Term("field", "this")); - Query constantScore = new ConstantScoreQuery(new AssertNeedsScores(term, PostingsEnum.FLAG_NONE)); + Query constantScore = new ConstantScoreQuery(new AssertNeedsScores(term, false)); assertEquals(5, searcher.search(constantScore, 5).totalHits); } @@ -80,38 +79,38 @@ public class TestNeedsScores extends LuceneTestCase { public void testQueryWrapperFilter() throws Exception { Query query = new MatchAllDocsQuery(); Query term = new TermQuery(new Term("field", "this")); - Filter filter = new QueryWrapperFilter(new AssertNeedsScores(term, PostingsEnum.FLAG_NONE)); + Filter filter = new QueryWrapperFilter(new AssertNeedsScores(term, false)); assertEquals(5, searcher.search(query, filter, 5).totalHits); } /** when not sorting by score */ public void testSortByField() throws Exception { - Query query = new AssertNeedsScores(new MatchAllDocsQuery(), PostingsEnum.FLAG_NONE); + Query query = new AssertNeedsScores(new MatchAllDocsQuery(), false); assertEquals(5, searcher.search(query, 5, Sort.INDEXORDER).totalHits); } /** when sorting by score */ public void testSortByScore() throws Exception { - Query query = new AssertNeedsScores(new MatchAllDocsQuery(), PostingsEnum.FLAG_FREQS); + Query query = new AssertNeedsScores(new MatchAllDocsQuery(), true); assertEquals(5, searcher.search(query, 5, Sort.RELEVANCE).totalHits); } /** - * Wraps a query, checking that the postingsFlags param + * Wraps a query, checking that the needsScores param * passed to Weight.scorer is the expected value. */ static class AssertNeedsScores extends Query { final Query in; - final int value; + final boolean value; - AssertNeedsScores(Query in, int value) { + AssertNeedsScores(Query in, boolean value) { this.in = in; this.value = value; } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { - final Weight w = in.createWeight(searcher, postingsFlags); + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { + final Weight w = in.createWeight(searcher, needsScores); return new Weight(AssertNeedsScores.this) { @Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { @@ -130,7 +129,7 @@ public class TestNeedsScores extends LuceneTestCase { @Override public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException { - assertEquals("query=" + in, value, postingsFlags); + assertEquals("query=" + in, value, needsScores); return w.scorer(context, acceptDocs); } }; @@ -156,7 +155,7 @@ public class TestNeedsScores extends LuceneTestCase { final int prime = 31; int result = super.hashCode(); result = prime * result + ((in == null) ? 0 : in.hashCode()); - result = prime * result + (value * 37); + result = prime * result + (value ? 1231 : 1237); return result; } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java b/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java index cf0cbf2b139..3279ab47a2a 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java @@ -21,7 +21,6 @@ import java.io.IOException; import org.apache.lucene.document.Document; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; @@ -108,7 +107,7 @@ public class TestPositiveScoresOnlyCollector extends LuceneTestCase { IndexReader ir = writer.getReader(); writer.close(); IndexSearcher searcher = newSearcher(ir); - Weight fake = new TermQuery(new Term("fake", "weight")).createWeight(searcher, PostingsEnum.FLAG_FREQS); + Weight fake = new TermQuery(new Term("fake", "weight")).createWeight(searcher, true); Scorer s = new SimpleScorer(fake); TopDocsCollector tdc = TopScoreDocCollector.create(scores.length); Collector c = new PositiveScoresOnlyCollector(tdc); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java b/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java index cc41c1da336..0aac3165da9 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java @@ -425,7 +425,7 @@ public class TestQueryRescorer extends LuceneTestCase { } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { return new Weight(FixedScoreQuery.this) { diff --git a/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java index 8b82b401e67..449acf00b6f 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java @@ -20,7 +20,6 @@ package org.apache.lucene.search; import java.io.IOException; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; @@ -131,7 +130,7 @@ public class TestScoreCachingWrappingScorer extends LuceneTestCase { IndexReader ir = writer.getReader(); writer.close(); IndexSearcher searcher = newSearcher(ir); - Weight fake = new TermQuery(new Term("fake", "weight")).createWeight(searcher, PostingsEnum.FLAG_FREQS); + Weight fake = new TermQuery(new Term("fake", "weight")).createWeight(searcher, true); Scorer s = new SimpleScorer(fake); ScoreCachingCollector scc = new ScoreCachingCollector(scores.length); scc.setScorer(s); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestTermQueryPostings.java b/lucene/core/src/test/org/apache/lucene/search/TestTermQueryPostings.java deleted file mode 100644 index 55305bb8f44..00000000000 --- a/lucene/core/src/test/org/apache/lucene/search/TestTermQueryPostings.java +++ /dev/null @@ -1,172 +0,0 @@ -package org.apache.lucene.search; - -/* - * 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. - */ - -import org.apache.lucene.analysis.MockAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.TextField; -import org.apache.lucene.index.DirectoryReader; -import org.apache.lucene.index.IndexOptions; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.PostingsEnum; -import org.apache.lucene.index.RandomIndexWriter; -import org.apache.lucene.index.SlowCompositeReaderWrapper; -import org.apache.lucene.index.Term; -import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Scorer; -import org.apache.lucene.search.TermQuery; -import org.apache.lucene.search.Weight; -import org.apache.lucene.search.payloads.PayloadHelper; -import org.apache.lucene.search.similarities.DefaultSimilarity; -import org.apache.lucene.store.Directory; -import org.apache.lucene.util.BytesRef; -import org.apache.lucene.util.LuceneTestCase; -import org.junit.Test; - -import java.io.IOException; - -public class TestTermQueryPostings extends LuceneTestCase { - - private static final String FIELD = "f"; - - private static final String[] DOC_FIELDS = new String[]{ - "a b c d", - "a a a a", - "c d e f", - "b d a g" - }; - - @Test - public void testTermQueryPositions() throws IOException { - - Directory directory = newDirectory(); - IndexWriterConfig config = newIndexWriterConfig(new MockAnalyzer(random())); - RandomIndexWriter writer = new RandomIndexWriter(random(), directory, config); - - for (String content : DOC_FIELDS) { - Document doc = new Document(); - doc.add(newField(FIELD, content, TextField.TYPE_NOT_STORED)); - writer.addDocument(doc); - } - - - IndexReader reader = SlowCompositeReaderWrapper.wrap(writer.getReader()); - IndexSearcher searcher = new IndexSearcher(reader); - writer.close(); - - TermQuery tq = new TermQuery(new Term(FIELD, "a")); - Weight weight = searcher.createNormalizedWeight(tq, PostingsEnum.FLAG_POSITIONS); - LeafReaderContext ctx = (LeafReaderContext) searcher.getTopReaderContext(); - Scorer scorer = weight.scorer(ctx, null); - - assertEquals(scorer.nextDoc(), 0); - assertEquals(scorer.nextPosition(), 0); - - assertEquals(scorer.nextDoc(), 1); - assertEquals(scorer.nextPosition(), 0); - assertEquals(scorer.nextPosition(), 1); - assertEquals(scorer.nextPosition(), 2); - assertEquals(scorer.nextPosition(), 3); - - assertEquals(scorer.nextDoc(), 3); - assertEquals(scorer.nextPosition(), 2); - - reader.close(); - directory.close(); - - } - - @Test - public void testTermQueryOffsets() throws IOException { - - Directory directory = newDirectory(); - IndexWriterConfig config = newIndexWriterConfig(new MockAnalyzer(random())); - RandomIndexWriter writer = new RandomIndexWriter(random(), directory, config); - - FieldType fieldType = new FieldType(TextField.TYPE_NOT_STORED); - fieldType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS); - - for (String content : DOC_FIELDS) { - Document doc = new Document(); - doc.add(newField(FIELD, content, fieldType)); - writer.addDocument(doc); - } - - - IndexReader reader = SlowCompositeReaderWrapper.wrap(writer.getReader()); - IndexSearcher searcher = new IndexSearcher(reader); - writer.close(); - - TermQuery tq = new TermQuery(new Term(FIELD, "a")); - Weight weight = searcher.createNormalizedWeight(tq, PostingsEnum.FLAG_OFFSETS); - LeafReaderContext ctx = (LeafReaderContext) searcher.getTopReaderContext(); - Scorer scorer = weight.scorer(ctx, null); - - assertEquals(scorer.nextDoc(), 0); - assertEquals(scorer.nextPosition(), 0); - assertEquals(scorer.startOffset(), 0); - assertEquals(scorer.endOffset(), 1); - - assertEquals(scorer.nextDoc(), 1); - assertEquals(scorer.nextPosition(), 0); - assertEquals(scorer.startOffset(), 0); - assertEquals(scorer.endOffset(), 1); - assertEquals(scorer.nextPosition(), 1); - assertEquals(scorer.startOffset(), 2); - assertEquals(scorer.endOffset(), 3); - assertEquals(scorer.nextPosition(), 2); - assertEquals(scorer.startOffset(), 4); - assertEquals(scorer.endOffset(), 5); - assertEquals(scorer.nextPosition(), 3); - assertEquals(scorer.startOffset(), 6); - assertEquals(scorer.endOffset(), 7); - - assertEquals(scorer.nextDoc(), 3); - assertEquals(scorer.nextPosition(), 2); - assertEquals(scorer.startOffset(), 4); - assertEquals(scorer.endOffset(), 5); - - reader.close(); - directory.close(); - - } - - @Test - public void testTermQueryPayloads() throws Exception { - - PayloadHelper helper = new PayloadHelper(); - IndexSearcher searcher = helper.setUp(random(), new DefaultSimilarity(), 1000); - - TermQuery tq = new TermQuery(new Term(PayloadHelper.FIELD, "seventy")); - Weight weight = searcher.createNormalizedWeight(tq, PostingsEnum.FLAG_PAYLOADS); - - for (LeafReaderContext ctx : searcher.leafContexts) { - Scorer scorer = weight.scorer(ctx, null); - if (scorer.nextDoc() == DocIdSetIterator.NO_MORE_DOCS) - continue; - scorer.nextPosition(); - BytesRef payload = scorer.getPayload(); - assertEquals(payload.length, 1); - } - - helper.tearDown(); - } -} diff --git a/lucene/core/src/test/org/apache/lucene/search/TestTermScorer.java b/lucene/core/src/test/org/apache/lucene/search/TestTermScorer.java index 2f3a2693fd7..751b3dd0771 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestTermScorer.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestTermScorer.java @@ -26,7 +26,6 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.SlowCompositeReaderWrapper; import org.apache.lucene.index.Term; @@ -76,7 +75,7 @@ public class TestTermScorer extends LuceneTestCase { Term allTerm = new Term(FIELD, "all"); TermQuery termQuery = new TermQuery(allTerm); - Weight weight = indexSearcher.createNormalizedWeight(termQuery, PostingsEnum.FLAG_FREQS); + Weight weight = indexSearcher.createNormalizedWeight(termQuery, true); assertTrue(indexSearcher.getTopReaderContext() instanceof LeafReaderContext); LeafReaderContext context = (LeafReaderContext)indexSearcher.getTopReaderContext(); BulkScorer ts = weight.bulkScorer(context, context.reader().getLiveDocs()); @@ -138,7 +137,7 @@ public class TestTermScorer extends LuceneTestCase { Term allTerm = new Term(FIELD, "all"); TermQuery termQuery = new TermQuery(allTerm); - Weight weight = indexSearcher.createNormalizedWeight(termQuery, PostingsEnum.FLAG_FREQS); + Weight weight = indexSearcher.createNormalizedWeight(termQuery, true); assertTrue(indexSearcher.getTopReaderContext() instanceof LeafReaderContext); LeafReaderContext context = (LeafReaderContext) indexSearcher.getTopReaderContext(); Scorer ts = weight.scorer(context, context.reader().getLiveDocs()); @@ -157,7 +156,7 @@ public class TestTermScorer extends LuceneTestCase { Term allTerm = new Term(FIELD, "all"); TermQuery termQuery = new TermQuery(allTerm); - Weight weight = indexSearcher.createNormalizedWeight(termQuery, PostingsEnum.FLAG_FREQS); + Weight weight = indexSearcher.createNormalizedWeight(termQuery, true); assertTrue(indexSearcher.getTopReaderContext() instanceof LeafReaderContext); LeafReaderContext context = (LeafReaderContext) indexSearcher.getTopReaderContext(); Scorer ts = weight.scorer(context, context.reader().getLiveDocs()); diff --git a/lucene/core/src/test/org/apache/lucene/search/TestTopDocsMerge.java b/lucene/core/src/test/org/apache/lucene/search/TestTopDocsMerge.java index 242e18faa99..24e784bbafd 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestTopDocsMerge.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestTopDocsMerge.java @@ -26,7 +26,6 @@ import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.CompositeReaderContext; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReaderContext; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.ReaderUtil; import org.apache.lucene.index.Term; @@ -252,7 +251,7 @@ public class TestTopDocsMerge extends LuceneTestCase { } // ... then all shards: - final Weight w = searcher.createNormalizedWeight(query, PostingsEnum.FLAG_FREQS); + final Weight w = searcher.createNormalizedWeight(query, true); final TopDocs[] shardHits; if (sort == null) { diff --git a/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java b/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java index db971d65dd4..5eb29cf92aa 100644 --- a/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java +++ b/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java @@ -181,7 +181,7 @@ public class TestNearSpansOrdered extends LuceneTestCase { */ public void testSpanNearScorerSkipTo1() throws Exception { SpanNearQuery q = makeQuery(); - Weight w = searcher.createNormalizedWeight(q, PostingsEnum.FLAG_FREQS); + Weight w = searcher.createNormalizedWeight(q, true); IndexReaderContext topReaderContext = searcher.getTopReaderContext(); LeafReaderContext leave = topReaderContext.leaves().get(0); Scorer s = w.scorer(leave, leave.reader().getLiveDocs()); diff --git a/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java index de745f40d60..577679d0a41 100644 --- a/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java +++ b/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java @@ -430,7 +430,7 @@ public class TestSpans extends LuceneTestCase { slop, ordered); - spanScorer = searcher.createNormalizedWeight(snq, PostingsEnum.FLAG_FREQS).scorer(ctx, ctx.reader().getLiveDocs()); + spanScorer = searcher.createNormalizedWeight(snq, true).scorer(ctx, ctx.reader().getLiveDocs()); } finally { searcher.setSimilarity(oldSim); } diff --git a/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java b/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java index 75328e63e6a..8cfd3d46fbf 100644 --- a/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java +++ b/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java @@ -73,8 +73,8 @@ class DrillSidewaysQuery extends Query { } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { - final Weight baseWeight = baseQuery.createWeight(searcher, postingsFlags); + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { + final Weight baseWeight = baseQuery.createWeight(searcher, needsScores); final Object[] drillDowns = new Object[drillDownQueries.length]; for(int dim=0;dim termStates = new HashMap<>(); diff --git a/lucene/test-framework/src/java/org/apache/lucene/search/AssertingIndexSearcher.java b/lucene/test-framework/src/java/org/apache/lucene/search/AssertingIndexSearcher.java index 414583c2354..1cced2508dc 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/search/AssertingIndexSearcher.java +++ b/lucene/test-framework/src/java/org/apache/lucene/search/AssertingIndexSearcher.java @@ -56,8 +56,8 @@ public class AssertingIndexSearcher extends IndexSearcher { /** Ensures, that the returned {@code Weight} is not normalized again, which may produce wrong scores. */ @Override - public Weight createNormalizedWeight(Query query, int postingsFlags) throws IOException { - final Weight w = super.createNormalizedWeight(query, postingsFlags); + public Weight createNormalizedWeight(Query query, boolean needsScores) throws IOException { + final Weight w = super.createNormalizedWeight(query, needsScores); return new AssertingWeight(random, w) { @Override diff --git a/lucene/test-framework/src/java/org/apache/lucene/search/AssertingQuery.java b/lucene/test-framework/src/java/org/apache/lucene/search/AssertingQuery.java index 844c6f2fb80..ae2f9a32602 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/search/AssertingQuery.java +++ b/lucene/test-framework/src/java/org/apache/lucene/search/AssertingQuery.java @@ -42,8 +42,8 @@ public class AssertingQuery extends Query { } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { - return AssertingWeight.wrap(new Random(random.nextLong()), in.createWeight(searcher, postingsFlags)); + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { + return AssertingWeight.wrap(new Random(random.nextLong()), in.createWeight(searcher, needsScores)); } @Override diff --git a/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java b/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java index 9382ebbad3e..080353752b8 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java +++ b/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java @@ -32,7 +32,6 @@ import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.MultiReader; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.store.Directory; import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.store.RAMDirectory; @@ -262,7 +261,7 @@ public class QueryUtils { lastDoc[0] = doc; try { if (scorer == null) { - Weight w = s.createNormalizedWeight(q, PostingsEnum.FLAG_FREQS); + Weight w = s.createNormalizedWeight(q, true); LeafReaderContext context = readerContextArray.get(leafPtr); scorer = w.scorer(context, context.reader().getLiveDocs()); } @@ -314,7 +313,7 @@ public class QueryUtils { final LeafReader previousReader = lastReader[0]; IndexSearcher indexSearcher = LuceneTestCase.newSearcher(previousReader); indexSearcher.setSimilarity(s.getSimilarity()); - Weight w = indexSearcher.createNormalizedWeight(q, PostingsEnum.FLAG_FREQS); + Weight w = indexSearcher.createNormalizedWeight(q, true); LeafReaderContext ctx = (LeafReaderContext)indexSearcher.getTopReaderContext(); Scorer scorer = w.scorer(ctx, ctx.reader().getLiveDocs()); if (scorer != null) { @@ -336,7 +335,7 @@ public class QueryUtils { final LeafReader previousReader = lastReader[0]; IndexSearcher indexSearcher = LuceneTestCase.newSearcher(previousReader, false); indexSearcher.setSimilarity(s.getSimilarity()); - Weight w = indexSearcher.createNormalizedWeight(q, PostingsEnum.FLAG_FREQS); + Weight w = indexSearcher.createNormalizedWeight(q, true); LeafReaderContext ctx = previousReader.getContext(); Scorer scorer = w.scorer(ctx, ctx.reader().getLiveDocs()); if (scorer != null) { @@ -368,7 +367,7 @@ public class QueryUtils { try { long startMS = System.currentTimeMillis(); for (int i=lastDoc[0]+1; i<=doc; i++) { - Weight w = s.createNormalizedWeight(q, PostingsEnum.FLAG_FREQS); + Weight w = s.createNormalizedWeight(q, true); Scorer scorer = w.scorer(context.get(leafPtr), liveDocs); Assert.assertTrue("query collected "+doc+" but skipTo("+i+") says no more docs!",scorer.advance(i) != DocIdSetIterator.NO_MORE_DOCS); Assert.assertEquals("query collected "+doc+" but skipTo("+i+") got to "+scorer.docID(),doc,scorer.docID()); @@ -401,7 +400,7 @@ public class QueryUtils { final LeafReader previousReader = lastReader[0]; IndexSearcher indexSearcher = LuceneTestCase.newSearcher(previousReader); indexSearcher.setSimilarity(s.getSimilarity()); - Weight w = indexSearcher.createNormalizedWeight(q, PostingsEnum.FLAG_FREQS); + Weight w = indexSearcher.createNormalizedWeight(q, true); Scorer scorer = w.scorer((LeafReaderContext)indexSearcher.getTopReaderContext(), previousReader.getLiveDocs()); if (scorer != null) { boolean more = scorer.advance(lastDoc[0] + 1) != DocIdSetIterator.NO_MORE_DOCS; @@ -422,7 +421,7 @@ public class QueryUtils { final LeafReader previousReader = lastReader[0]; IndexSearcher indexSearcher = LuceneTestCase.newSearcher(previousReader); indexSearcher.setSimilarity(s.getSimilarity()); - Weight w = indexSearcher.createNormalizedWeight(q, PostingsEnum.FLAG_FREQS); + Weight w = indexSearcher.createNormalizedWeight(q, true); Scorer scorer = w.scorer((LeafReaderContext)indexSearcher.getTopReaderContext(), previousReader.getLiveDocs()); if (scorer != null) { boolean more = scorer.advance(lastDoc[0] + 1) != DocIdSetIterator.NO_MORE_DOCS; @@ -433,7 +432,7 @@ public class QueryUtils { /** Check that the scorer and bulk scorer advance consistently. */ public static void checkBulkScorerSkipTo(Random r, Query query, IndexSearcher searcher) throws IOException { - Weight weight = searcher.createNormalizedWeight(query, PostingsEnum.FLAG_FREQS); + Weight weight = searcher.createNormalizedWeight(query, true); for (LeafReaderContext context : searcher.getIndexReader().leaves()) { final Scorer scorer = weight.scorer(context, context.reader().getLiveDocs()); final BulkScorer bulkScorer = weight.bulkScorer(context, context.reader().getLiveDocs()); diff --git a/solr/core/src/java/org/apache/solr/schema/LatLonType.java b/solr/core/src/java/org/apache/solr/schema/LatLonType.java index 5a02026f0db..f9521fbed7a 100644 --- a/solr/core/src/java/org/apache/solr/schema/LatLonType.java +++ b/solr/core/src/java/org/apache/solr/schema/LatLonType.java @@ -563,7 +563,7 @@ class SpatialDistanceQuery extends ExtendedQueryBase implements PostFilter { @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { // if we were supposed to use bboxQuery, then we should have been rewritten using that query assert bboxQuery == null; return new SpatialWeight(searcher); diff --git a/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java index efa455a0609..ad0063c5766 100644 --- a/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java +++ b/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java @@ -80,7 +80,7 @@ public class ExportQParserPlugin extends QParserPlugin { } public Weight createWeight(IndexSearcher searcher) throws IOException { - return mainQuery.createWeight(searcher, PostingsEnum.FLAG_FREQS); + return mainQuery.createWeight(searcher, true); } public Query rewrite(IndexReader reader) throws IOException { diff --git a/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java index c9c993731ff..544cf137ebc 100644 --- a/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java +++ b/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java @@ -210,7 +210,7 @@ class JoinQuery extends Query { } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { return new JoinQueryWeight((SolrIndexSearcher)searcher); } diff --git a/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java index b6fc24d7f84..8438aacaca4 100644 --- a/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java +++ b/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java @@ -27,7 +27,6 @@ import com.carrotsearch.hppc.IntFloatOpenHashMap; import com.carrotsearch.hppc.IntIntOpenHashMap; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.Term; import org.apache.lucene.search.Explanation; import org.apache.lucene.search.IndexSearcher; @@ -172,9 +171,8 @@ public class ReRankQParserPlugin extends QParserPlugin { } - @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException{ - return new ReRankWeight(mainQuery, reRankQuery, reRankWeight, searcher, postingsFlags); + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException{ + return new ReRankWeight(mainQuery, reRankQuery, reRankWeight, searcher, needsScores); } } @@ -184,12 +182,12 @@ public class ReRankQParserPlugin extends QParserPlugin { private Weight mainWeight; private double reRankWeight; - public ReRankWeight(Query mainQuery, Query reRankQuery, double reRankWeight, IndexSearcher searcher, int postingsFlags) throws IOException { + public ReRankWeight(Query mainQuery, Query reRankQuery, double reRankWeight, IndexSearcher searcher, boolean needsScores) throws IOException { super(mainQuery); this.reRankQuery = reRankQuery; this.searcher = searcher; this.reRankWeight = reRankWeight; - this.mainWeight = mainQuery.createWeight(searcher, postingsFlags); + this.mainWeight = mainQuery.createWeight(searcher, needsScores); } public float getValueForNormalization() throws IOException { diff --git a/solr/core/src/java/org/apache/solr/search/SolrConstantScoreQuery.java b/solr/core/src/java/org/apache/solr/search/SolrConstantScoreQuery.java index b85f3176968..770d56f6291 100644 --- a/solr/core/src/java/org/apache/solr/search/SolrConstantScoreQuery.java +++ b/solr/core/src/java/org/apache/solr/search/SolrConstantScoreQuery.java @@ -229,7 +229,7 @@ public class SolrConstantScoreQuery extends ConstantScoreQuery implements Extend } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) { + public Weight createWeight(IndexSearcher searcher, boolean needsScores) { try { return new SolrConstantScoreQuery.ConstantWeight(searcher); } catch (IOException e) { diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java index 4b5a5094b13..ececb2ca658 100644 --- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java +++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java @@ -1113,7 +1113,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrIn List weights = new ArrayList<>(notCached.size()); for (Query q : notCached) { Query qq = QueryUtils.makeQueryable(q); - weights.add(createNormalizedWeight(qq, PostingsEnum.FLAG_FREQS)); + weights.add(createNormalizedWeight(qq, true)); } pf.filter = new FilterImpl(answer, weights); } else { diff --git a/solr/core/src/java/org/apache/solr/search/WrappedQuery.java b/solr/core/src/java/org/apache/solr/search/WrappedQuery.java index f02087dcbd4..974e4d00f7a 100644 --- a/solr/core/src/java/org/apache/solr/search/WrappedQuery.java +++ b/solr/core/src/java/org/apache/solr/search/WrappedQuery.java @@ -53,8 +53,8 @@ public class WrappedQuery extends ExtendedQueryBase { } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { - return q.createWeight(searcher, postingsFlags); + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { + return q.createWeight(searcher, needsScores); } @Override diff --git a/solr/core/src/java/org/apache/solr/search/join/IgnoreAcceptDocsQuery.java b/solr/core/src/java/org/apache/solr/search/join/IgnoreAcceptDocsQuery.java index 441f67cec2e..ebc5c41c7d2 100644 --- a/solr/core/src/java/org/apache/solr/search/join/IgnoreAcceptDocsQuery.java +++ b/solr/core/src/java/org/apache/solr/search/join/IgnoreAcceptDocsQuery.java @@ -53,8 +53,8 @@ public class IgnoreAcceptDocsQuery extends Query { } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { - Weight inner = q.createWeight(searcher, postingsFlags); + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { + Weight inner = q.createWeight(searcher, needsScores); return new IADWeight(inner); } diff --git a/solr/core/src/java/org/apache/solr/update/DeleteByQueryWrapper.java b/solr/core/src/java/org/apache/solr/update/DeleteByQueryWrapper.java index 29044d6bab8..cd84d210294 100644 --- a/solr/core/src/java/org/apache/solr/update/DeleteByQueryWrapper.java +++ b/solr/core/src/java/org/apache/solr/update/DeleteByQueryWrapper.java @@ -64,10 +64,10 @@ final class DeleteByQueryWrapper extends Query { } @Override - public Weight createWeight(IndexSearcher searcher, int postingsFlags) throws IOException { + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { final LeafReader wrapped = wrap((LeafReader) searcher.getIndexReader()); final IndexSearcher privateContext = new IndexSearcher(wrapped); - final Weight inner = in.createWeight(privateContext, postingsFlags); + final Weight inner = in.createWeight(privateContext, needsScores); return new Weight(DeleteByQueryWrapper.this) { @Override public Explanation explain(LeafReaderContext context, int doc) throws IOException { throw new UnsupportedOperationException(); } diff --git a/solr/core/src/test/org/apache/solr/search/TestRankQueryPlugin.java b/solr/core/src/test/org/apache/solr/search/TestRankQueryPlugin.java index 3eb7d569128..34f23c1de2c 100644 --- a/solr/core/src/test/org/apache/solr/search/TestRankQueryPlugin.java +++ b/solr/core/src/test/org/apache/solr/search/TestRankQueryPlugin.java @@ -32,7 +32,6 @@ import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexReaderContext; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.ReaderUtil; import org.apache.lucene.search.FieldComparator; import org.apache.lucene.search.IndexSearcher; @@ -115,9 +114,8 @@ public class TestRankQueryPlugin extends QParserPlugin { return false; } - @Override - public Weight createWeight(IndexSearcher indexSearcher, int postingsFlags) throws IOException{ - return q.createWeight(indexSearcher, postingsFlags); + public Weight createWeight(IndexSearcher indexSearcher, boolean needsScores) throws IOException{ + return q.createWeight(indexSearcher, needsScores); } public void setBoost(float boost) {