You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2015/02/06 17:20:39 UTC
svn commit: r1657883 [1/3] - in /lucene/dev/branches/branch_5x: ./ lucene/
lucene/core/ lucene/core/src/java/org/apache/lucene/search/
lucene/core/src/java/org/apache/lucene/search/payloads/
lucene/core/src/java/org/apache/lucene/search/spans/ lucene/c...
Author: jpountz
Date: Fri Feb 6 16:20:37 2015
New Revision: 1657883
URL: http://svn.apache.org/r1657883
Log:
LUCENE-6220: Move needsScores to Query.createWeight.
Modified:
lucene/dev/branches/branch_5x/ (props changed)
lucene/dev/branches/branch_5x/lucene/ (props changed)
lucene/dev/branches/branch_5x/lucene/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_5x/lucene/core/ (props changed)
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Query.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TopDocs.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TopFieldCollector.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Weight.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/package.html
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWeight.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanQueryVisitSubscorers.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanScorer.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestNeedsScores.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTermScorer.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTopDocsMerge.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java
lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java
lucene/dev/branches/branch_5x/lucene/facet/ (props changed)
lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysQuery.java
lucene/dev/branches/branch_5x/lucene/grouping/ (props changed)
lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java
lucene/dev/branches/branch_5x/lucene/grouping/src/test/org/apache/lucene/search/grouping/TestGrouping.java
lucene/dev/branches/branch_5x/lucene/highlighter/ (props changed)
lucene/dev/branches/branch_5x/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
lucene/dev/branches/branch_5x/lucene/join/ (props changed)
lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java
lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinIndexSearcher.java
lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java
lucene/dev/branches/branch_5x/lucene/queries/ (props changed)
lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java
lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java
lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java
lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java
lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/QueryValueSource.java
lucene/dev/branches/branch_5x/lucene/sandbox/ (props changed)
lucene/dev/branches/branch_5x/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonQuery.java
lucene/dev/branches/branch_5x/lucene/sandbox/src/test/org/apache/lucene/sandbox/queries/TestSlowCollationMethods.java
lucene/dev/branches/branch_5x/lucene/test-framework/ (props changed)
lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingIndexSearcher.java
lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingQuery.java
lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java
lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java
lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java
lucene/dev/branches/branch_5x/solr/ (props changed)
lucene/dev/branches/branch_5x/solr/core/ (props changed)
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/response/transform/ChildDocTransformerFactory.java
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/LatLonType.java
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/JoinQParserPlugin.java
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/SolrConstantScoreQuery.java
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/WrappedQuery.java
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/TopGroupsShardResponseProcessor.java
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/join/BlockJoinChildQParser.java
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/join/IgnoreAcceptDocsQuery.java
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/update/DeleteByQueryWrapper.java
lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/search/TestRankQueryPlugin.java
Modified: lucene/dev/branches/branch_5x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/CHANGES.txt?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Fri Feb 6 16:20:37 2015
@@ -40,8 +40,8 @@ API Changes
* LUCENE-6217: Add IndexWriter.isOpen and getTragicException. (Simon
Willnauer, Mike McCandless)
-* LUCENE-6218: Add Collector.needsScores() and needsScores parameter
- to Weight.scorer(). (Robert Muir)
+* LUCENE-6218, LUCENE-6220: Add Collector.needsScores() and needsScores
+ parameter to Query.createWeight(). (Robert Muir, Adrien Grand)
Other
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java Fri Feb 6 16:20:37 2015
@@ -174,15 +174,19 @@ public class BooleanQuery extends Query
protected ArrayList<Weight> weights;
protected int maxCoord; // num optional + num required
private final boolean disableCoord;
+ private final boolean needsScores;
- public BooleanWeight(IndexSearcher searcher, boolean disableCoord)
+ public BooleanWeight(IndexSearcher searcher, boolean needsScores, boolean disableCoord)
throws IOException {
+ super(BooleanQuery.this);
+ this.needsScores = needsScores;
this.similarity = searcher.getSimilarity();
this.disableCoord = disableCoord;
weights = new ArrayList<>(clauses.size());
for (int i = 0 ; i < clauses.size(); i++) {
BooleanClause c = clauses.get(i);
- Weight w = c.getQuery().createWeight(searcher);
+ final boolean queryNeedsScores = needsScores && c.getOccur() != Occur.MUST_NOT;
+ Weight w = c.getQuery().createWeight(searcher, queryNeedsScores);
weights.add(w);
if (!c.isProhibited()) {
maxCoord++;
@@ -191,9 +195,6 @@ public class BooleanQuery extends Query
}
@Override
- public Query getQuery() { return BooleanQuery.this; }
-
- @Override
public float getValueForNormalization() throws IOException {
float sum = 0.0f;
for (int i = 0 ; i < weights.size(); i++) {
@@ -242,7 +243,7 @@ public class BooleanQuery extends Query
for (Iterator<Weight> wIter = weights.iterator(); wIter.hasNext();) {
Weight w = wIter.next();
BooleanClause c = cIter.next();
- if (w.scorer(context, context.reader().getLiveDocs(), true) == null) {
+ if (w.scorer(context, context.reader().getLiveDocs()) == null) {
if (c.isRequired()) {
fail = true;
Explanation r = new Explanation(0.0f, "no match on required clause (" + c.getQuery().toString() + ")");
@@ -307,12 +308,12 @@ public class BooleanQuery extends Query
/** Try to build a boolean scorer for this weight. Returns null if {@link BooleanScorer}
* cannot be used. */
// pkg-private for forcing use of BooleanScorer in tests
- BooleanScorer booleanScorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException {
+ BooleanScorer booleanScorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
List<BulkScorer> optional = new ArrayList<BulkScorer>();
Iterator<BooleanClause> cIter = clauses.iterator();
for (Weight w : weights) {
BooleanClause c = cIter.next();
- BulkScorer subScorer = w.bulkScorer(context, acceptDocs, needsScores);
+ BulkScorer subScorer = w.bulkScorer(context, acceptDocs);
if (subScorer == null) {
if (c.isRequired()) {
return null;
@@ -342,8 +343,8 @@ public class BooleanQuery extends Query
}
@Override
- public BulkScorer bulkScorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException {
- final BooleanScorer bulkScorer = booleanScorer(context, acceptDocs, needsScores);
+ public BulkScorer bulkScorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
+ final BooleanScorer bulkScorer = booleanScorer(context, acceptDocs);
if (bulkScorer != null) { // BooleanScorer is applicable
// TODO: what is the right heuristic here?
final long costThreshold;
@@ -366,11 +367,11 @@ public class BooleanQuery extends Query
return bulkScorer;
}
}
- return super.bulkScorer(context, acceptDocs, needsScores);
+ return super.bulkScorer(context, acceptDocs);
}
@Override
- public Scorer scorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException {
+ public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
// initially the user provided value,
// but if minNrShouldMatch == optional.size(),
// we will optimize and move these to required, making this 0
@@ -382,7 +383,7 @@ public class BooleanQuery extends Query
Iterator<BooleanClause> cIter = clauses.iterator();
for (Weight w : weights) {
BooleanClause c = cIter.next();
- Scorer subScorer = w.scorer(context, acceptDocs, needsScores && c.isProhibited() == false);
+ Scorer subScorer = w.scorer(context, acceptDocs);
if (subScorer == null) {
if (c.isRequired()) {
return null;
@@ -532,8 +533,8 @@ public class BooleanQuery extends Query
}
@Override
- public Weight createWeight(IndexSearcher searcher) throws IOException {
- return new BooleanWeight(searcher, disableCoord);
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
+ return new BooleanWeight(searcher, needsScores, disableCoord);
}
@Override
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java Fri Feb 6 16:20:37 2015
@@ -109,12 +109,8 @@ public class ConstantScoreQuery extends
private float queryWeight;
public ConstantWeight(IndexSearcher searcher) throws IOException {
- this.innerWeight = (query == null) ? null : query.createWeight(searcher);
- }
-
- @Override
- public Query getQuery() {
- return ConstantScoreQuery.this;
+ super(ConstantScoreQuery.this);
+ this.innerWeight = (query == null) ? null : query.createWeight(searcher, false);
}
@Override
@@ -134,14 +130,14 @@ public class ConstantScoreQuery extends
}
@Override
- public BulkScorer bulkScorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException {
+ public BulkScorer bulkScorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
final DocIdSetIterator disi;
if (filter != null) {
assert query == null;
- return super.bulkScorer(context, acceptDocs, needsScores);
+ return super.bulkScorer(context, acceptDocs);
} else {
assert query != null && innerWeight != null;
- BulkScorer bulkScorer = innerWeight.bulkScorer(context, acceptDocs, false);
+ BulkScorer bulkScorer = innerWeight.bulkScorer(context, acceptDocs);
if (bulkScorer == null) {
return null;
}
@@ -150,7 +146,7 @@ public class ConstantScoreQuery extends
}
@Override
- public Scorer scorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException {
+ public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
final DocIdSetIterator disi;
if (filter != null) {
assert query == null;
@@ -161,7 +157,7 @@ public class ConstantScoreQuery extends
disi = dis.iterator();
} else {
assert query != null && innerWeight != null;
- disi = innerWeight.scorer(context, acceptDocs, false);
+ disi = innerWeight.scorer(context, acceptDocs);
}
if (disi == null) {
@@ -172,7 +168,7 @@ public class ConstantScoreQuery extends
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
- final Scorer cs = scorer(context, context.reader().getLiveDocs(), true);
+ final Scorer cs = scorer(context, context.reader().getLiveDocs());
final boolean exists = (cs != null && cs.advance(doc) == doc);
final ComplexExplanation result = new ComplexExplanation();
@@ -279,7 +275,7 @@ public class ConstantScoreQuery extends
}
@Override
- public Weight createWeight(IndexSearcher searcher) throws IOException {
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
return new ConstantScoreQuery.ConstantWeight(searcher);
}
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java Fri Feb 6 16:20:37 2015
@@ -118,16 +118,13 @@ public class DisjunctionMaxQuery extends
protected ArrayList<Weight> 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) throws IOException {
+ public DisjunctionMaxWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
+ super(DisjunctionMaxQuery.this);
for (Query disjunctQuery : disjuncts) {
- weights.add(disjunctQuery.createWeight(searcher));
+ weights.add(disjunctQuery.createWeight(searcher, needsScores));
}
}
- /** Return our associated DisjunctionMaxQuery */
- @Override
- public Query getQuery() { return DisjunctionMaxQuery.this; }
-
/** Compute the sub of squared weights of us applied to our subqueries. Used for normalization. */
@Override
public float getValueForNormalization() throws IOException {
@@ -153,11 +150,11 @@ public class DisjunctionMaxQuery extends
/** Create the scorer used to score our associated DisjunctionMaxQuery */
@Override
- public Scorer scorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException {
+ public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
List<Scorer> scorers = new ArrayList<>();
for (Weight w : weights) {
// we will advance() subscorers
- Scorer subScorer = w.scorer(context, acceptDocs, needsScores);
+ Scorer subScorer = w.scorer(context, acceptDocs);
if (subScorer != null) {
scorers.add(subScorer);
}
@@ -197,8 +194,8 @@ public class DisjunctionMaxQuery extends
/** Create the Weight used to score us */
@Override
- public Weight createWeight(IndexSearcher searcher) throws IOException {
- return new DisjunctionMaxWeight(searcher);
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
+ return new DisjunctionMaxWeight(searcher, needsScores);
}
/** Optimize our representation and our subqueries representations
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java Fri Feb 6 16:20:37 2015
@@ -78,9 +78,9 @@ public class FilteredQuery extends Query
* This is accomplished by overriding the Scorer returned by the Weight.
*/
@Override
- public Weight createWeight(final IndexSearcher searcher) throws IOException {
- final Weight weight = query.createWeight (searcher);
- return new Weight() {
+ public Weight createWeight(final IndexSearcher searcher, boolean needsScores) throws IOException {
+ final Weight weight = query.createWeight (searcher, needsScores);
+ return new Weight(FilteredQuery.this) {
@Override
public float getValueForNormalization() throws IOException {
@@ -111,15 +111,9 @@ public class FilteredQuery extends Query
}
}
- // return this query
- @Override
- public Query getQuery() {
- return FilteredQuery.this;
- }
-
// return a filtering scorer
@Override
- public Scorer scorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException {
+ public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
assert filter != null;
DocIdSet filterDocIdSet = filter.getDocIdSet(context, acceptDocs);
@@ -128,12 +122,12 @@ public class FilteredQuery extends Query
return null;
}
- return strategy.filteredScorer(context, weight, filterDocIdSet, needsScores);
+ return strategy.filteredScorer(context, weight, filterDocIdSet);
}
// return a filtering top scorer
@Override
- public BulkScorer bulkScorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException {
+ public BulkScorer bulkScorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
assert filter != null;
DocIdSet filterDocIdSet = filter.getDocIdSet(context, acceptDocs);
@@ -142,7 +136,7 @@ public class FilteredQuery extends Query
return null;
}
- return strategy.filteredBulkScorer(context, weight, filterDocIdSet, needsScores);
+ return strategy.filteredBulkScorer(context, weight, filterDocIdSet);
}
};
}
@@ -465,7 +459,7 @@ public class FilteredQuery extends Query
* @throws IOException if an {@link IOException} occurs
*/
public abstract Scorer filteredScorer(LeafReaderContext context,
- Weight weight, DocIdSet docIdSet, boolean needsScores) throws IOException;
+ Weight weight, DocIdSet docIdSet) throws IOException;
/**
* Returns a filtered {@link BulkScorer} based on this
@@ -480,8 +474,8 @@ public class FilteredQuery extends Query
* @return a filtered top scorer
*/
public BulkScorer filteredBulkScorer(LeafReaderContext context,
- Weight weight, DocIdSet docIdSet, boolean needsScores) throws IOException {
- Scorer scorer = filteredScorer(context, weight, docIdSet, needsScores);
+ Weight weight, DocIdSet docIdSet) throws IOException {
+ Scorer scorer = filteredScorer(context, weight, docIdSet);
if (scorer == null) {
return null;
}
@@ -502,7 +496,7 @@ public class FilteredQuery extends Query
public static class RandomAccessFilterStrategy extends FilterStrategy {
@Override
- public Scorer filteredScorer(LeafReaderContext context, Weight weight, DocIdSet docIdSet, boolean needsScores) throws IOException {
+ public Scorer filteredScorer(LeafReaderContext context, Weight weight, DocIdSet docIdSet) throws IOException {
final DocIdSetIterator filterIter = docIdSet.iterator();
if (filterIter == null) {
// this means the filter does not accept any documents.
@@ -514,11 +508,11 @@ public class FilteredQuery extends Query
final boolean useRandomAccess = filterAcceptDocs != null && useRandomAccess(filterAcceptDocs, filterIter.cost());
if (useRandomAccess) {
// if we are using random access, we return the inner scorer, just with other acceptDocs
- return weight.scorer(context, filterAcceptDocs, needsScores);
+ return weight.scorer(context, filterAcceptDocs);
} else {
// we are gonna advance() this scorer, so we set inorder=true/toplevel=false
// we pass null as acceptDocs, as our filter has already respected acceptDocs, no need to do twice
- final Scorer scorer = weight.scorer(context, null, needsScores);
+ final Scorer scorer = weight.scorer(context, null);
return (scorer == null) ? null : new LeapFrogScorer(weight, filterIter, scorer, scorer);
}
}
@@ -551,14 +545,14 @@ public class FilteredQuery extends Query
@Override
public Scorer filteredScorer(LeafReaderContext context,
- Weight weight, DocIdSet docIdSet, boolean needsScores) throws IOException {
+ Weight weight, DocIdSet docIdSet) throws IOException {
final DocIdSetIterator filterIter = docIdSet.iterator();
if (filterIter == null) {
// this means the filter does not accept any documents.
return null;
}
// we pass null as acceptDocs, as our filter has already respected acceptDocs, no need to do twice
- final Scorer scorer = weight.scorer(context, null, needsScores);
+ final Scorer scorer = weight.scorer(context, null);
if (scorer == null) {
return null;
}
@@ -587,28 +581,28 @@ public class FilteredQuery extends Query
private static final class QueryFirstFilterStrategy extends FilterStrategy {
@Override
public Scorer filteredScorer(final LeafReaderContext context,
- Weight weight, DocIdSet docIdSet, boolean needsScores) throws IOException {
+ Weight weight, DocIdSet docIdSet) throws IOException {
Bits filterAcceptDocs = docIdSet.bits();
if (filterAcceptDocs == null) {
// Filter does not provide random-access Bits; we
// must fallback to leapfrog:
- return LEAP_FROG_QUERY_FIRST_STRATEGY.filteredScorer(context, weight, docIdSet, needsScores);
+ return LEAP_FROG_QUERY_FIRST_STRATEGY.filteredScorer(context, weight, docIdSet);
}
- final Scorer scorer = weight.scorer(context, null, needsScores);
+ final Scorer scorer = weight.scorer(context, null);
return scorer == null ? null : new QueryFirstScorer(weight,
filterAcceptDocs, scorer);
}
@Override
public BulkScorer filteredBulkScorer(final LeafReaderContext context,
- Weight weight, DocIdSet docIdSet, boolean needsScores) throws IOException {
+ Weight weight, DocIdSet docIdSet) throws IOException {
Bits filterAcceptDocs = docIdSet.bits();
if (filterAcceptDocs == null) {
// Filter does not provide random-access Bits; we
// must fallback to leapfrog:
- return LEAP_FROG_QUERY_FIRST_STRATEGY.filteredBulkScorer(context, weight, docIdSet, needsScores);
+ return LEAP_FROG_QUERY_FIRST_STRATEGY.filteredBulkScorer(context, weight, docIdSet);
}
- final Scorer scorer = weight.scorer(context, null, needsScores);
+ final Scorer scorer = weight.scorer(context, null);
return scorer == null ? null : new QueryFirstBulkScorer(scorer, filterAcceptDocs);
}
}
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java Fri Feb 6 16:20:37 2015
@@ -226,8 +226,53 @@ public class IndexSearcher {
* @throws BooleanQuery.TooManyClauses If a query would exceed
* {@link BooleanQuery#getMaxClauseCount()} clauses.
*/
- public TopDocs searchAfter(ScoreDoc after, Query query, int n) throws IOException {
- return search(createNormalizedWeight(query), after, n);
+ public TopDocs searchAfter(ScoreDoc after, Query query, int numHits) throws IOException {
+ final int limit = Math.max(1, reader.maxDoc());
+ if (after != null && after.doc >= limit) {
+ throw new IllegalArgumentException("after.doc exceeds the number of documents in the reader: after.doc="
+ + after.doc + " limit=" + limit);
+ }
+ numHits = Math.min(numHits, limit);
+
+ if (executor == null) {
+ final TopScoreDocCollector collector = TopScoreDocCollector.create(numHits, after);
+ search(query, collector);
+ return collector.topDocs();
+ } else {
+ final TopScoreDocCollector[] collectors = new TopScoreDocCollector[leafSlices.length];
+ boolean needsScores = false;
+ for (int i = 0; i < leafSlices.length; ++i) {
+ collectors[i] = TopScoreDocCollector.create(numHits, after);
+ needsScores |= collectors[i].needsScores();
+ }
+
+ final Weight weight = createNormalizedWeight(query, needsScores);
+ final List<Future<TopDocs>> topDocsFutures = new ArrayList<>(leafSlices.length);
+ for (int i = 0; i < leafSlices.length; ++i) {
+ final LeafReaderContext[] leaves = leafSlices[i].leaves;
+ final TopScoreDocCollector collector = collectors[i];
+ topDocsFutures.add(executor.submit(new Callable<TopDocs>() {
+ @Override
+ public TopDocs call() throws Exception {
+ search(Arrays.asList(leaves), weight, collector);
+ return collector.topDocs();
+ }
+ }));
+ }
+
+ final TopDocs[] topDocs = new TopDocs[leafSlices.length];
+ for (int i = 0; i < topDocs.length; ++i) {
+ try {
+ topDocs[i] = topDocsFutures.get(i).get();
+ } catch (InterruptedException e) {
+ throw new ThreadInterruptedException(e);
+ } catch (ExecutionException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ return TopDocs.merge(numHits, topDocs);
+ }
}
/** Finds the top <code>n</code>
@@ -242,7 +287,7 @@ public class IndexSearcher {
* {@link BooleanQuery#getMaxClauseCount()} clauses.
*/
public TopDocs searchAfter(ScoreDoc after, Query query, Filter filter, int n) throws IOException {
- return search(createNormalizedWeight(wrapFilter(query, filter)), after, n);
+ return searchAfter(after, wrapFilter(query, filter), n);
}
/** Finds the top <code>n</code>
@@ -253,7 +298,7 @@ public class IndexSearcher {
*/
public TopDocs search(Query query, int n)
throws IOException {
- return search(query, null, n);
+ return searchAfter(null, query, n);
}
@@ -265,7 +310,7 @@ public class IndexSearcher {
*/
public TopDocs search(Query query, Filter filter, int n)
throws IOException {
- return search(createNormalizedWeight(wrapFilter(query, filter)), null, n);
+ return search(wrapFilter(query, filter), n);
}
/** Lower-level search API.
@@ -281,7 +326,7 @@ public class IndexSearcher {
*/
public void search(Query query, Filter filter, Collector results)
throws IOException {
- search(leafContexts, createNormalizedWeight(wrapFilter(query, filter)), results);
+ search(wrapFilter(query, filter), results);
}
/** Lower-level search API.
@@ -293,7 +338,7 @@ public class IndexSearcher {
*/
public void search(Query query, Collector results)
throws IOException {
- search(leafContexts, createNormalizedWeight(query), results);
+ search(leafContexts, createNormalizedWeight(query, results.needsScores()), results);
}
/** Search implementation with arbitrary sorting. Finds
@@ -310,7 +355,7 @@ public class IndexSearcher {
*/
public TopFieldDocs search(Query query, Filter filter, int n,
Sort sort) throws IOException {
- return search(createNormalizedWeight(wrapFilter(query, filter)), n, sort, false, false);
+ return search(query, filter, n, sort, false, false);
}
/** Search implementation with arbitrary sorting, plus
@@ -329,7 +374,7 @@ public class IndexSearcher {
*/
public TopFieldDocs search(Query query, Filter filter, int n,
Sort sort, boolean doDocScores, boolean doMaxScore) throws IOException {
- return search(createNormalizedWeight(wrapFilter(query, filter)), n, sort, doDocScores, doMaxScore);
+ return searchAfter(null, query, filter, n, sort, doDocScores, doMaxScore);
}
/** Finds the top <code>n</code>
@@ -343,13 +388,8 @@ public class IndexSearcher {
* @throws BooleanQuery.TooManyClauses If a query would exceed
* {@link BooleanQuery#getMaxClauseCount()} clauses.
*/
- public TopDocs searchAfter(ScoreDoc after, Query query, Filter filter, int n, Sort sort) throws IOException {
- if (after != null && !(after instanceof FieldDoc)) {
- // TODO: if we fix type safety of TopFieldDocs we can
- // remove this
- throw new IllegalArgumentException("after must be a FieldDoc; got " + after);
- }
- return search(createNormalizedWeight(wrapFilter(query, filter)), (FieldDoc) after, n, sort, true, false, false);
+ public TopFieldDocs searchAfter(ScoreDoc after, Query query, Filter filter, int n, Sort sort) throws IOException {
+ return searchAfter(after, query, filter, n, sort, false, false);
}
/**
@@ -362,7 +402,7 @@ public class IndexSearcher {
*/
public TopFieldDocs search(Query query, int n,
Sort sort) throws IOException {
- return search(createNormalizedWeight(query), n, sort, false, false);
+ return search(query, null, n, sort, false, false);
}
/** Finds the top <code>n</code>
@@ -377,12 +417,7 @@ public class IndexSearcher {
* {@link BooleanQuery#getMaxClauseCount()} clauses.
*/
public TopDocs searchAfter(ScoreDoc after, Query query, int n, Sort sort) throws IOException {
- if (after != null && !(after instanceof FieldDoc)) {
- // TODO: if we fix type safety of TopFieldDocs we can
- // remove this
- throw new IllegalArgumentException("after must be a FieldDoc; got " + after);
- }
- return search(createNormalizedWeight(query), (FieldDoc) after, n, sort, true, false, false);
+ return searchAfter(after, query, null, n, sort, false, false);
}
/** Finds the top <code>n</code>
@@ -401,123 +436,54 @@ public class IndexSearcher {
* @throws BooleanQuery.TooManyClauses If a query would exceed
* {@link BooleanQuery#getMaxClauseCount()} clauses.
*/
- public TopDocs searchAfter(ScoreDoc after, Query query, Filter filter, int n, Sort sort,
- boolean doDocScores, boolean doMaxScore) throws IOException {
+ public TopFieldDocs searchAfter(ScoreDoc after, Query query, Filter filter, int numHits, Sort sort,
+ boolean doDocScores, boolean doMaxScore) throws IOException {
if (after != null && !(after instanceof FieldDoc)) {
// TODO: if we fix type safety of TopFieldDocs we can
// remove this
throw new IllegalArgumentException("after must be a FieldDoc; got " + after);
}
- return search(createNormalizedWeight(wrapFilter(query, filter)), (FieldDoc) after, n, sort, true,
- doDocScores, doMaxScore);
+ return searchAfter((FieldDoc) after, wrapFilter(query, filter), numHits, sort, doDocScores, doMaxScore);
}
- /** Expert: Low-level search implementation. Finds the top <code>n</code>
- * hits for <code>query</code>, applying <code>filter</code> if non-null.
- *
- * <p>Applications should usually call {@link IndexSearcher#search(Query,int)} or
- * {@link IndexSearcher#search(Query,Filter,int)} instead.
- * @throws BooleanQuery.TooManyClauses If a query would exceed
- * {@link BooleanQuery#getMaxClauseCount()} clauses.
- */
- protected TopDocs search(Weight weight, ScoreDoc after, int nDocs) throws IOException {
- int limit = reader.maxDoc();
- if (limit == 0) {
- limit = 1;
- }
+ private TopFieldDocs searchAfter(FieldDoc after, Query query, int numHits, Sort sort,
+ boolean doDocScores, boolean doMaxScore) throws IOException {
+ final int limit = Math.max(1, reader.maxDoc());
if (after != null && after.doc >= limit) {
throw new IllegalArgumentException("after.doc exceeds the number of documents in the reader: after.doc="
+ after.doc + " limit=" + limit);
}
- nDocs = Math.min(nDocs, limit);
-
+ numHits = Math.min(numHits, limit);
+
+ final boolean fillFields = true;
if (executor == null) {
- return search(leafContexts, weight, after, nDocs);
+ final TopFieldCollector collector = TopFieldCollector.create(sort, numHits, after, fillFields, doDocScores, doMaxScore);
+ search(query, collector);
+ return collector.topDocs();
} else {
- final List<Future<TopDocs>> topDocsFutures = new ArrayList<>(leafSlices.length);
- for (int i = 0; i < leafSlices.length; i++) { // search each leaf slice
- topDocsFutures.add(executor.submit(new SearcherCallableNoSort(this, leafSlices[i], weight, after, nDocs)));
- }
- final TopDocs[] topDocs = new TopDocs[leafSlices.length];
- for (int i = 0; i < leafSlices.length; i++) {
- try {
- topDocs[i] = topDocsFutures.get(i).get();
- } catch (InterruptedException e) {
- throw new ThreadInterruptedException(e);
- } catch (ExecutionException e) {
- throw new RuntimeException(e);
- }
+ final TopFieldCollector[] collectors = new TopFieldCollector[leafSlices.length];
+ boolean needsScores = false;
+ for (int i = 0; i < leafSlices.length; ++i) {
+ collectors[i] = TopFieldCollector.create(sort, numHits, after, fillFields, doDocScores, doMaxScore);
+ needsScores |= collectors[i].needsScores();
}
- return TopDocs.merge(null, nDocs, topDocs);
- }
- }
- /** Expert: Low-level search implementation. Finds the top <code>n</code>
- * hits for <code>query</code>.
- *
- * <p>Applications should usually call {@link IndexSearcher#search(Query,int)} or
- * {@link IndexSearcher#search(Query,Filter,int)} instead.
- * @throws BooleanQuery.TooManyClauses If a query would exceed
- * {@link BooleanQuery#getMaxClauseCount()} clauses.
- */
- protected TopDocs search(List<LeafReaderContext> leaves, Weight weight, ScoreDoc after, int nDocs) throws IOException {
- // single thread
- int limit = reader.maxDoc();
- if (limit == 0) {
- limit = 1;
- }
- nDocs = Math.min(nDocs, limit);
- TopScoreDocCollector collector = TopScoreDocCollector.create(nDocs, after);
- search(leaves, weight, collector);
- return collector.topDocs();
- }
-
- /** Expert: Low-level search implementation with arbitrary
- * sorting and control over whether hit scores and max
- * score should be computed. Finds
- * the top <code>n</code> hits for <code>query</code> and sorting the hits
- * by the criteria in <code>sort</code>.
- *
- * <p>Applications should usually call {@link
- * IndexSearcher#search(Query,Filter,int,Sort)} instead.
- *
- * @throws BooleanQuery.TooManyClauses If a query would exceed
- * {@link BooleanQuery#getMaxClauseCount()} clauses.
- */
- protected TopFieldDocs search(Weight weight,
- final int nDocs, Sort sort,
- boolean doDocScores, boolean doMaxScore) throws IOException {
- return search(weight, null, nDocs, sort, true, doDocScores, doMaxScore);
- }
-
- /**
- * Just like {@link #search(Weight, int, Sort, boolean, boolean)}, but you choose
- * whether or not the fields in the returned {@link FieldDoc} instances should
- * be set by specifying fillFields.
- */
- protected TopFieldDocs search(Weight weight, FieldDoc after, int nDocs,
- Sort sort, boolean fillFields,
- boolean doDocScores, boolean doMaxScore)
- throws IOException {
-
- if (sort == null) throw new NullPointerException("Sort must not be null");
-
- int limit = reader.maxDoc();
- if (limit == 0) {
- limit = 1;
- }
- nDocs = Math.min(nDocs, limit);
-
- if (executor == null) {
- // use all leaves here!
- return search(leafContexts, weight, after, nDocs, sort, fillFields, doDocScores, doMaxScore);
- } else {
+ final Weight weight = createNormalizedWeight(query, needsScores);
final List<Future<TopFieldDocs>> topDocsFutures = new ArrayList<>(leafSlices.length);
- for (int i = 0; i < leafSlices.length; i++) { // search each leaf slice
- topDocsFutures.add(executor.submit(new SearcherCallableWithSort(this, leafSlices[i], weight, after, nDocs, sort, doDocScores, doMaxScore)));
+ for (int i = 0; i < leafSlices.length; ++i) {
+ final LeafReaderContext[] leaves = leafSlices[i].leaves;
+ final TopFieldCollector collector = collectors[i];
+ topDocsFutures.add(executor.submit(new Callable<TopFieldDocs>() {
+ @Override
+ public TopFieldDocs call() throws Exception {
+ search(Arrays.asList(leaves), weight, collector);
+ return collector.topDocs();
+ }
+ }));
}
+
final TopFieldDocs[] topDocs = new TopFieldDocs[leafSlices.length];
- for (int i = 0; i < leafSlices.length; i++) {
+ for (int i = 0; i < topDocs.length; ++i) {
try {
topDocs[i] = topDocsFutures.get(i).get();
} catch (InterruptedException e) {
@@ -526,30 +492,9 @@ public class IndexSearcher {
throw new RuntimeException(e);
}
}
- return (TopFieldDocs) TopDocs.merge(sort, nDocs, topDocs);
- }
- }
-
-
- /**
- * Just like {@link #search(Weight, int, Sort, boolean, boolean)}, but you choose
- * whether or not the fields in the returned {@link FieldDoc} instances should
- * be set by specifying fillFields.
- */
- protected TopFieldDocs search(List<LeafReaderContext> leaves, Weight weight, FieldDoc after, int nDocs,
- Sort sort, boolean fillFields, boolean doDocScores, boolean doMaxScore) throws IOException {
- // single thread
- int limit = reader.maxDoc();
- if (limit == 0) {
- limit = 1;
- }
- nDocs = Math.min(nDocs, limit);
- TopFieldCollector collector = TopFieldCollector.create(sort, nDocs, after,
- fillFields, doDocScores,
- doMaxScore);
- search(leaves, weight, collector);
- return (TopFieldDocs) collector.topDocs();
+ return TopDocs.merge(sort, numHits, topDocs);
+ }
}
/**
@@ -586,7 +531,7 @@ public class IndexSearcher {
// continue with the following leaf
continue;
}
- BulkScorer scorer = weight.bulkScorer(ctx, ctx.reader().getLiveDocs(), collector.needsScores());
+ BulkScorer scorer = weight.bulkScorer(ctx, ctx.reader().getLiveDocs());
if (scorer != null) {
try {
scorer.score(leafCollector);
@@ -620,7 +565,7 @@ public class IndexSearcher {
* entire index.
*/
public Explanation explain(Query query, int doc) throws IOException {
- return explain(createNormalizedWeight(query), doc);
+ return explain(createNormalizedWeight(query, true), doc);
}
/** Expert: low-level implementation method
@@ -650,9 +595,9 @@ public class IndexSearcher {
* can then directly be used to get a {@link Scorer}.
* @lucene.internal
*/
- public Weight createNormalizedWeight(Query query) throws IOException {
+ public Weight createNormalizedWeight(Query query, boolean needsScores) throws IOException {
query = rewrite(query);
- Weight weight = query.createWeight(this);
+ Weight weight = query.createWeight(this, needsScores);
float v = weight.getValueForNormalization();
float norm = getSimilarity().queryNorm(v);
if (Float.isInfinite(norm) || Float.isNaN(norm)) {
@@ -672,68 +617,6 @@ public class IndexSearcher {
}
/**
- * A thread subclass for searching a single searchable
- */
- private static final class SearcherCallableNoSort implements Callable<TopDocs> {
-
- private final IndexSearcher searcher;
- private final Weight weight;
- private final ScoreDoc after;
- private final int nDocs;
- private final LeafSlice slice;
-
- public SearcherCallableNoSort(IndexSearcher searcher, LeafSlice slice, Weight weight,
- ScoreDoc after, int nDocs) {
- this.searcher = searcher;
- this.weight = weight;
- this.after = after;
- this.nDocs = nDocs;
- this.slice = slice;
- }
-
- @Override
- public TopDocs call() throws IOException {
- return searcher.search(Arrays.asList(slice.leaves), weight, after, nDocs);
- }
- }
-
-
- /**
- * A thread subclass for searching a single searchable
- */
- private static final class SearcherCallableWithSort implements Callable<TopFieldDocs> {
-
- private final IndexSearcher searcher;
- private final Weight weight;
- private final int nDocs;
- private final Sort sort;
- private final LeafSlice slice;
- private final FieldDoc after;
- private final boolean doDocScores;
- private final boolean doMaxScore;
-
- public SearcherCallableWithSort(IndexSearcher searcher, LeafSlice slice, Weight weight,
- FieldDoc after, int nDocs, Sort sort,
- boolean doDocScores, boolean doMaxScore) {
- this.searcher = searcher;
- this.weight = weight;
- this.nDocs = nDocs;
- this.sort = sort;
- this.slice = slice;
- this.after = after;
- this.doDocScores = doDocScores;
- this.doMaxScore = doMaxScore;
- }
-
- @Override
- public TopFieldDocs call() throws IOException {
- assert slice.leaves.length == 1;
- return searcher.search(Arrays.asList(slice.leaves),
- weight, after, nDocs, sort, true, doDocScores, doMaxScore);
- }
- }
-
- /**
* A class holding a subset of the {@link IndexSearcher}s leaf contexts to be
* executed within a single thread.
*
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MatchAllDocsQuery.java Fri Feb 6 16:20:37 2015
@@ -89,6 +89,7 @@ public class MatchAllDocsQuery extends Q
private float queryNorm;
public MatchAllDocsWeight(IndexSearcher searcher) {
+ super(MatchAllDocsQuery.this);
}
@Override
@@ -97,11 +98,6 @@ public class MatchAllDocsQuery extends Q
}
@Override
- public Query getQuery() {
- return MatchAllDocsQuery.this;
- }
-
- @Override
public float getValueForNormalization() {
queryWeight = getBoost();
return queryWeight * queryWeight;
@@ -114,7 +110,7 @@ public class MatchAllDocsQuery extends Q
}
@Override
- public Scorer scorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException {
+ public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
return new MatchAllScorer(context.reader(), acceptDocs, this, queryWeight);
}
@@ -133,7 +129,7 @@ public class MatchAllDocsQuery extends Q
}
@Override
- public Weight createWeight(IndexSearcher searcher) {
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores) {
return new MatchAllDocsWeight(searcher);
}
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java Fri Feb 6 16:20:37 2015
@@ -142,9 +142,12 @@ public class MultiPhraseQuery extends Qu
private final Similarity similarity;
private final Similarity.SimWeight stats;
private final Map<Term,TermContext> termContexts = new HashMap<>();
+ private final boolean needsScores;
- public MultiPhraseWeight(IndexSearcher searcher)
+ public MultiPhraseWeight(IndexSearcher searcher, boolean needsScores)
throws IOException {
+ super(MultiPhraseQuery.this);
+ this.needsScores = needsScores;
this.similarity = searcher.getSimilarity();
final IndexReaderContext context = searcher.getTopReaderContext();
@@ -166,9 +169,6 @@ public class MultiPhraseQuery extends Qu
}
@Override
- public Query getQuery() { return MultiPhraseQuery.this; }
-
- @Override
public float getValueForNormalization() {
return stats.getValueForNormalization();
}
@@ -179,7 +179,7 @@ public class MultiPhraseQuery extends Qu
}
@Override
- public Scorer scorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException {
+ public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
assert !termArrays.isEmpty();
final LeafReader reader = context.reader();
final Bits liveDocs = acceptDocs;
@@ -257,7 +257,7 @@ public class MultiPhraseQuery extends Qu
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
- Scorer scorer = scorer(context, context.reader().getLiveDocs(), true);
+ Scorer scorer = scorer(context, context.reader().getLiveDocs());
if (scorer != null) {
int newDoc = scorer.advance(doc);
if (newDoc == doc) {
@@ -297,8 +297,8 @@ public class MultiPhraseQuery extends Qu
}
@Override
- public Weight createWeight(IndexSearcher searcher) throws IOException {
- return new MultiPhraseWeight(searcher);
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
+ return new MultiPhraseWeight(searcher, needsScores);
}
/** Prints a user-readable version of this query. */
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java Fri Feb 6 16:20:37 2015
@@ -212,10 +212,13 @@ public class PhraseQuery extends Query {
private class PhraseWeight extends Weight {
private final Similarity similarity;
private final Similarity.SimWeight stats;
+ private final boolean needsScores;
private transient TermContext states[];
- public PhraseWeight(IndexSearcher searcher)
+ public PhraseWeight(IndexSearcher searcher, boolean needsScores)
throws IOException {
+ super(PhraseQuery.this);
+ this.needsScores = needsScores;
this.similarity = searcher.getSimilarity();
final IndexReaderContext context = searcher.getTopReaderContext();
states = new TermContext[terms.size()];
@@ -232,9 +235,6 @@ public class PhraseQuery extends Query {
public String toString() { return "weight(" + PhraseQuery.this + ")"; }
@Override
- public Query getQuery() { return PhraseQuery.this; }
-
- @Override
public float getValueForNormalization() {
return stats.getValueForNormalization();
}
@@ -245,7 +245,7 @@ public class PhraseQuery extends Query {
}
@Override
- public Scorer scorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException {
+ public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
assert !terms.isEmpty();
final LeafReader reader = context.reader();
final Bits liveDocs = acceptDocs;
@@ -298,7 +298,7 @@ public class PhraseQuery extends Query {
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
- Scorer scorer = scorer(context, context.reader().getLiveDocs(), true);
+ Scorer scorer = scorer(context, context.reader().getLiveDocs());
if (scorer != null) {
int newDoc = scorer.advance(doc);
if (newDoc == doc) {
@@ -319,8 +319,8 @@ public class PhraseQuery extends Query {
}
@Override
- public Weight createWeight(IndexSearcher searcher) throws IOException {
- return new PhraseWeight(searcher);
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
+ return new PhraseWeight(searcher, needsScores);
}
/**
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Query.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Query.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Query.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Query.java Fri Feb 6 16:20:37 2015
@@ -18,7 +18,6 @@ package org.apache.lucene.search;
*/
import java.io.IOException;
-
import java.util.Set;
import org.apache.lucene.index.IndexReader;
@@ -72,11 +71,13 @@ public abstract class Query implements C
/**
* Expert: Constructs an appropriate Weight implementation for this query.
- *
* <p>
* Only implemented by primitive queries, which re-write to themselves.
+ *
+ * @param needsScores True if document scores ({@link Scorer#score}) or match
+ * frequencies ({@link Scorer#freq}) are needed.
*/
- public Weight createWeight(IndexSearcher searcher) throws IOException {
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
throw new UnsupportedOperationException("Query " + this + " does not implement createWeight");
}
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java Fri Feb 6 16:20:37 2015
@@ -60,7 +60,7 @@ public abstract class QueryRescorer exte
List<LeafReaderContext> leaves = searcher.getIndexReader().leaves();
- Weight weight = searcher.createNormalizedWeight(query);
+ Weight weight = searcher.createNormalizedWeight(query, true);
// Now merge sort docIDs from hits, with reader's leaves:
int hitUpto = 0;
@@ -82,7 +82,7 @@ public abstract class QueryRescorer exte
if (readerContext != null) {
// We advanced to another segment:
docBase = readerContext.docBase;
- scorer = weight.scorer(readerContext, null, true);
+ scorer = weight.scorer(readerContext, null);
}
if(scorer != null) {
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java Fri Feb 6 16:20:37 2015
@@ -52,11 +52,11 @@ public class QueryWrapperFilter extends
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);
+ final Weight weight = new IndexSearcher(privateContext).createNormalizedWeight(query, false);
return new DocIdSet() {
@Override
public DocIdSetIterator iterator() throws IOException {
- return weight.scorer(privateContext, acceptDocs, false);
+ return weight.scorer(privateContext, acceptDocs);
}
@Override
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java Fri Feb 6 16:20:37 2015
@@ -46,9 +46,12 @@ public class TermQuery extends Query {
private final Similarity similarity;
private final Similarity.SimWeight stats;
private final TermContext termStates;
+ private final boolean needsScores;
- public TermWeight(IndexSearcher searcher, TermContext termStates)
+ public TermWeight(IndexSearcher searcher, boolean needsScores, TermContext termStates)
throws IOException {
+ super(TermQuery.this);
+ this.needsScores = needsScores;
assert termStates != null : "TermContext must not be null";
this.termStates = termStates;
this.similarity = searcher.getSimilarity();
@@ -62,9 +65,6 @@ public class TermQuery extends Query {
public String toString() { return "weight(" + TermQuery.this + ")"; }
@Override
- public Query getQuery() { return TermQuery.this; }
-
- @Override
public float getValueForNormalization() {
return stats.getValueForNormalization();
}
@@ -75,7 +75,7 @@ public class TermQuery extends Query {
}
@Override
- public Scorer scorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException {
+ public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
assert termStates.topReaderContext == ReaderUtil.getTopLevelContext(context) : "The top-reader used to create Weight (" + termStates.topReaderContext + ") is not the same as the current reader's top-reader (" + ReaderUtil.getTopLevelContext(context);
final TermsEnum termsEnum = getTermsEnum(context);
if (termsEnum == null) {
@@ -110,7 +110,7 @@ public class TermQuery extends Query {
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
- Scorer scorer = scorer(context, context.reader().getLiveDocs(), true);
+ Scorer scorer = scorer(context, context.reader().getLiveDocs());
if (scorer != null) {
int newDoc = scorer.advance(doc);
if (newDoc == doc) {
@@ -157,7 +157,7 @@ public class TermQuery extends Query {
public Term getTerm() { return term; }
@Override
- public Weight createWeight(IndexSearcher searcher) throws IOException {
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
final IndexReaderContext context = searcher.getTopReaderContext();
final TermContext termState;
if (perReaderTermState == null || perReaderTermState.topReaderContext != context) {
@@ -172,7 +172,7 @@ public class TermQuery extends Query {
if (docFreq != -1)
termState.setDocFreq(docFreq);
- return new TermWeight(searcher, termState);
+ return new TermWeight(searcher, needsScores, termState);
}
@Override
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TopDocs.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TopDocs.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TopDocs.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TopDocs.java Fri Feb 6 16:20:37 2015
@@ -158,7 +158,6 @@ public class TopDocs {
// Returns true if first is < second
@Override
- @SuppressWarnings({"unchecked","rawtypes"})
public boolean lessThan(ShardRef first, ShardRef second) {
assert first != second;
final FieldDoc firstFD = (FieldDoc) shardHits[first.shardIndex][first.hitIndex];
@@ -195,25 +194,48 @@ public class TopDocs {
}
/** Returns a new TopDocs, containing topN results across
- * the provided TopDocs, sorting by the specified {@link
+ * the provided TopDocs, sorting by score. Each {@link TopDocs}
+ * instance must be sorted.
+ * @lucene.experimental */
+ public static TopDocs merge(int topN, TopDocs[] shardHits) throws IOException {
+ return merge(0, topN, shardHits);
+ }
+
+ /**
+ * Same as {@link #merge(int, TopDocs[])} but also ignores the top
+ * {@code start} top docs. This is typically useful for pagination.
+ * @lucene.experimental
+ */
+ public static TopDocs merge(int start, int topN, TopDocs[] shardHits) throws IOException {
+ return mergeAux(null, start, topN, shardHits);
+ }
+
+ /** Returns a new TopFieldDocs, containing topN results across
+ * the provided TopFieldDocs, sorting by the specified {@link
* Sort}. Each of the TopDocs must have been sorted by
* the same Sort, and sort field values must have been
* filled (ie, <code>fillFields=true</code> must be
- * passed to {@link
- * TopFieldCollector#create}.
- *
- * <p>Pass sort=null to merge sort by score descending.
- *
+ * passed to {@link TopFieldCollector#create}).
* @lucene.experimental */
- public static TopDocs merge(Sort sort, int topN, TopDocs[] shardHits) throws IOException {
+ public static TopFieldDocs merge(Sort sort, int topN, TopFieldDocs[] shardHits) throws IOException {
return merge(sort, 0, topN, shardHits);
}
/**
- * Same as {@link #merge(Sort, int, TopDocs[])} but also slices the result at the same time based
- * on the provided start and size. The return TopDocs will always have a scoreDocs with length of at most size.
+ * Same as {@link #merge(Sort, int, TopFieldDocs[])} but also ignores the top
+ * {@code start} top docs. This is typically useful for pagination.
+ * @lucene.experimental
*/
- public static TopDocs merge(Sort sort, int start, int size, TopDocs[] shardHits) throws IOException {
+ public static TopFieldDocs merge(Sort sort, int start, int topN, TopFieldDocs[] shardHits) throws IOException {
+ if (sort == null) {
+ throw new IllegalArgumentException("sort must be non-null when merging field-docs");
+ }
+ return (TopFieldDocs) mergeAux(sort, start, topN, shardHits);
+ }
+
+ /** Auxiliary method used by the {@link #merge} impls. A sort value of null
+ * is used to indicate that docs should be sorted by score. */
+ private static TopDocs mergeAux(Sort sort, int start, int size, TopDocs[] shardHits) throws IOException {
final PriorityQueue<ShardRef> queue;
if (sort == null) {
queue = new ScoreMergeSortQueue(shardHits);
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TopFieldCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TopFieldCollector.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TopFieldCollector.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TopFieldCollector.java Fri Feb 6 16:20:37 2015
@@ -698,4 +698,8 @@ public abstract class TopFieldCollector
return new TopFieldDocs(totalHits, results, ((FieldValueHitQueue<Entry>) pq).getFields(), maxScore);
}
+ @Override
+ public TopFieldDocs topDocs() {
+ return (TopFieldDocs) super.topDocs();
+ }
}
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Weight.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Weight.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Weight.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Weight.java Fri Feb 6 16:20:37 2015
@@ -34,14 +34,14 @@ import org.apache.lucene.util.Bits;
* {@link org.apache.lucene.index.LeafReader} dependent state should reside in the {@link Scorer}.
* <p>
* Since {@link Weight} creates {@link Scorer} instances for a given
- * {@link org.apache.lucene.index.LeafReaderContext} ({@link #scorer(org.apache.lucene.index.LeafReaderContext, Bits, boolean)})
+ * {@link org.apache.lucene.index.LeafReaderContext} ({@link #scorer(org.apache.lucene.index.LeafReaderContext, Bits)})
* callers must maintain the relationship between the searcher's top-level
* {@link IndexReaderContext} and the context used to create a {@link Scorer}.
* <p>
* A <code>Weight</code> is used in the following way:
* <ol>
* <li>A <code>Weight</code> is constructed by a top-level query, given a
- * <code>IndexSearcher</code> ({@link Query#createWeight(IndexSearcher)}).
+ * <code>IndexSearcher</code> ({@link Query#createWeight(IndexSearcher, boolean)}).
* <li>The {@link #getValueForNormalization()} method is called on the
* <code>Weight</code> to compute the query normalization factor
* {@link Similarity#queryNorm(float)} of the query clauses contained in the
@@ -49,13 +49,22 @@ import org.apache.lucene.util.Bits;
* <li>The query normalization factor is passed to {@link #normalize(float, float)}. At
* this point the weighting is complete.
* <li>A <code>Scorer</code> is constructed by
- * {@link #scorer(org.apache.lucene.index.LeafReaderContext, Bits, boolean)}.
+ * {@link #scorer(org.apache.lucene.index.LeafReaderContext, Bits)}.
* </ol>
*
* @since 2.9
*/
public abstract class Weight {
+ protected final Query parentQuery;
+
+ /** Sole constructor, typically invoked by sub-classes.
+ * @param query the parent query
+ */
+ protected Weight(Query query) {
+ this.parentQuery = query;
+ }
+
/**
* An explanation of the score computation for the named document.
*
@@ -67,7 +76,9 @@ public abstract class Weight {
public abstract Explanation explain(LeafReaderContext context, int doc) throws IOException;
/** The query that this concerns. */
- public abstract Query getQuery();
+ public final Query getQuery() {
+ return parentQuery;
+ }
/** The value for normalization of contained query clauses (e.g. sum of squared weights). */
public abstract float getValueForNormalization() throws IOException;
@@ -87,13 +98,11 @@ public abstract class Weight {
* @param acceptDocs
* Bits that represent the allowable docs to match (typically deleted docs
* but possibly filtering other documents)
- * @param needsScores
- * True if document scores ({@link Scorer#score}) or match frequencies ({@link Scorer#freq}) are needed.
*
* @return a {@link Scorer} which scores documents in/out-of order.
* @throws IOException if there is a low-level I/O error
*/
- public abstract Scorer scorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException;
+ public abstract Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException;
/**
* Optional method, to return a {@link BulkScorer} to
@@ -108,16 +117,14 @@ public abstract class Weight {
* @param acceptDocs
* Bits that represent the allowable docs to match (typically deleted docs
* but possibly filtering other documents)
- * @param needsScores
- * True if document scores are needed.
*
* @return a {@link BulkScorer} which scores documents and
* passes them to a collector.
* @throws IOException if there is a low-level I/O error
*/
- public BulkScorer bulkScorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException {
+ public BulkScorer bulkScorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
- Scorer scorer = scorer(context, acceptDocs, needsScores);
+ Scorer scorer = scorer(context, acceptDocs);
if (scorer == null) {
// No docs match
return null;
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/package.html
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/package.html?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/package.html (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/package.html Fri Feb 6 16:20:37 2015
@@ -389,7 +389,7 @@ on the built-in available scoring models
{@link org.apache.lucene.search.Query Query} class has several methods that are important for
derived classes:
<ol>
- <li>{@link org.apache.lucene.search.Query#createWeight(IndexSearcher) createWeight(IndexSearcher searcher)} — A
+ <li>{@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 <a
@@ -398,7 +398,7 @@ on the built-in available scoring models
<li>{@link org.apache.lucene.search.Query#rewrite(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}, <span
- >and other queries that implement {@link org.apache.lucene.search.Query#createWeight(IndexSearcher) createWeight(IndexSearcher searcher)}</span></li>
+ >and other queries that implement {@link org.apache.lucene.search.Query#createWeight(IndexSearcher,boolean) createWeight(IndexSearcher searcher,boolean)}</span></li>
</ol>
</p>
<a name="weightClass"></a>
@@ -546,8 +546,8 @@ on the built-in available scoring models
<p>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)
- IndexSearcher.createNormalizedWeight(Query)},
+ {@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,
which is an internal collection of search results. The IndexSearcher creates
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java Fri Feb 6 16:20:37 2015
@@ -71,7 +71,7 @@ public class PayloadNearQuery extends Sp
}
@Override
- public Weight createWeight(IndexSearcher searcher) throws IOException {
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
return new PayloadNearSpanWeight(this, searcher);
}
@@ -148,14 +148,14 @@ public class PayloadNearQuery extends Sp
}
@Override
- public Scorer scorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException {
+ public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
return new PayloadNearSpanScorer(query.getSpans(context, acceptDocs, termContexts), this,
similarity, similarity.simScorer(stats, context));
}
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
- PayloadNearSpanScorer scorer = (PayloadNearSpanScorer) scorer(context, context.reader().getLiveDocs(), true);
+ PayloadNearSpanScorer scorer = (PayloadNearSpanScorer) scorer(context, context.reader().getLiveDocs());
if (scorer != null) {
int newDoc = scorer.advance(doc);
if (newDoc == doc) {
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java Fri Feb 6 16:20:37 2015
@@ -67,7 +67,7 @@ public class PayloadTermQuery extends Sp
}
@Override
- public Weight createWeight(IndexSearcher searcher) throws IOException {
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
return new PayloadTermWeight(this, searcher);
}
@@ -79,7 +79,7 @@ public class PayloadTermQuery extends Sp
}
@Override
- public Scorer scorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException {
+ public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
return new PayloadTermSpanScorer((TermSpans) query.getSpans(context, acceptDocs, termContexts),
this, similarity.simScorer(stats, context));
}
@@ -176,7 +176,7 @@ public class PayloadTermQuery extends Sp
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
- PayloadTermSpanScorer scorer = (PayloadTermSpanScorer) scorer(context, context.reader().getLiveDocs(), true);
+ PayloadTermSpanScorer scorer = (PayloadTermSpanScorer) scorer(context, context.reader().getLiveDocs());
if (scorer != null) {
int newDoc = scorer.advance(doc);
if (newDoc == doc) {
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java Fri Feb 6 16:20:37 2015
@@ -106,8 +106,8 @@ public class FieldMaskingSpanQuery exten
}
@Override
- public Weight createWeight(IndexSearcher searcher) throws IOException {
- return maskedQuery.createWeight(searcher);
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
+ return maskedQuery.createWeight(searcher, needsScores);
}
@Override
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanQuery.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanQuery.java Fri Feb 6 16:20:37 2015
@@ -42,7 +42,7 @@ public abstract class SpanQuery extends
public abstract String getField();
@Override
- public Weight createWeight(IndexSearcher searcher) throws IOException {
+ public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
return new SpanWeight(this, searcher);
}
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWeight.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWeight.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWeight.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWeight.java Fri Feb 6 16:20:37 2015
@@ -35,13 +35,14 @@ import java.util.TreeSet;
* Expert-only. Public for use by other weight implementations
*/
public class SpanWeight extends Weight {
- protected Similarity similarity;
- protected Map<Term,TermContext> termContexts;
- protected SpanQuery query;
+ protected final Similarity similarity;
+ protected final Map<Term,TermContext> termContexts;
+ protected final SpanQuery query;
protected Similarity.SimWeight stats;
public SpanWeight(SpanQuery query, IndexSearcher searcher)
throws IOException {
+ super(query);
this.similarity = searcher.getSimilarity();
this.query = query;
@@ -66,9 +67,6 @@ public class SpanWeight extends Weight {
}
@Override
- public Query getQuery() { return query; }
-
- @Override
public float getValueForNormalization() throws IOException {
return stats == null ? 1.0f : stats.getValueForNormalization();
}
@@ -81,7 +79,7 @@ public class SpanWeight extends Weight {
}
@Override
- public Scorer scorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) throws IOException {
+ public Scorer scorer(LeafReaderContext context, Bits acceptDocs) throws IOException {
if (stats == null) {
return null;
} else {
@@ -91,7 +89,7 @@ public class SpanWeight extends Weight {
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
- SpanScorer scorer = (SpanScorer) scorer(context, context.reader().getLiveDocs(), true);
+ SpanScorer scorer = (SpanScorer) scorer(context, context.reader().getLiveDocs());
if (scorer != null) {
int newDoc = scorer.advance(doc);
if (newDoc == doc) {
Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java Fri Feb 6 16:20:37 2015
@@ -266,13 +266,12 @@ final class JustCompileSearch {
static final class JustCompileWeight extends Weight {
- @Override
- public Explanation explain(LeafReaderContext context, int doc) {
- throw new UnsupportedOperationException(UNSUPPORTED_MSG);
+ protected JustCompileWeight() {
+ super(null);
}
@Override
- public Query getQuery() {
+ public Explanation explain(LeafReaderContext context, int doc) {
throw new UnsupportedOperationException(UNSUPPORTED_MSG);
}
@@ -287,7 +286,7 @@ final class JustCompileSearch {
}
@Override
- public Scorer scorer(LeafReaderContext context, Bits acceptDocs, boolean needsScores) {
+ public Scorer scorer(LeafReaderContext context, Bits acceptDocs) {
throw new UnsupportedOperationException(UNSUPPORTED_MSG);
}
Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java Fri Feb 6 16:20:37 2015
@@ -706,15 +706,15 @@ public class TestBooleanCoord extends Lu
/** 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);
- Scorer scorer = weight.scorer(reader.leaves().get(0), null, true);
+ 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());
assertEquals(expected, scorer.score(), 0.0001f);
// test bulk scorer
final AtomicBoolean seen = new AtomicBoolean(false);
- BulkScorer bulkScorer = weight.bulkScorer(reader.leaves().get(0), null, true);
+ BulkScorer bulkScorer = weight.bulkScorer(reader.leaves().get(0), null);
assertNotNull(bulkScorer);
bulkScorer.score(new LeafCollector() {
Scorer scorer;
Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanOr.java Fri Feb 6 16:20:37 2015
@@ -186,10 +186,10 @@ public class TestBooleanOr extends Lucen
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);
+ Weight w = s.createNormalizedWeight(bq, true);
assertEquals(1, s.getIndexReader().leaves().size());
- BulkScorer scorer = w.bulkScorer(s.getIndexReader().leaves().get(0), null, true);
+ BulkScorer scorer = w.bulkScorer(s.getIndexReader().leaves().get(0), null);
final FixedBitSet hits = new FixedBitSet(docCount);
final AtomicInteger end = new AtomicInteger();
Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java?rev=1657883&r1=1657882&r2=1657883&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java Fri Feb 6 16:20:37 2015
@@ -233,9 +233,9 @@ public class TestBooleanQuery extends Lu
q.add(new BooleanClause(new TermQuery(new Term("field", term)), BooleanClause.Occur.SHOULD));
}
- Weight weight = s.createNormalizedWeight(q);
+ Weight weight = s.createNormalizedWeight(q, true);
- Scorer scorer = weight.scorer(s.leafContexts.get(0), null, true);
+ Scorer scorer = weight.scorer(s.leafContexts.get(0), null);
// First pass: just use .nextDoc() to gather all hits
final List<ScoreDoc> hits = new ArrayList<>();
@@ -251,8 +251,8 @@ public class TestBooleanQuery extends Lu
// verify exact match:
for(int iter2=0;iter2<10;iter2++) {
- weight = s.createNormalizedWeight(q);
- scorer = weight.scorer(s.leafContexts.get(0), null, true);
+ weight = s.createNormalizedWeight(q, true);
+ scorer = weight.scorer(s.leafContexts.get(0), null);
if (VERBOSE) {
System.out.println(" iter2=" + iter2);