LUCENE-8017: Add Weight.getCacheHelper()

This commit is contained in:
Alan Woodward 2017-11-03 10:35:42 +00:00
parent ca5f9b3457
commit a886a001a4
87 changed files with 734 additions and 49 deletions

View File

@ -33,6 +33,11 @@ Improvements
======================= Lucene 7.2.0 =======================
API Changes
* LUCENE-8017: Weight now exposes a getCacheHelper() method to help query caches
determine whether or not a query can be cached. (Alan Woodward)
Bug Fixes
* LUCENE-7991: KNearestNeighborDocumentClassifier.knnSearch no longer applies

View File

@ -21,6 +21,7 @@ import java.util.Arrays;
import java.util.Objects;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PointValues;
@ -356,6 +357,11 @@ abstract class RangeFieldQuery extends Query {
}
return scorerSupplier.get(Long.MAX_VALUE);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}

View File

@ -138,6 +138,11 @@ abstract class SortedNumericDocValuesRangeQuery extends Query {
}
return new ConstantScoreScorer(this, score(), iterator);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getDocValuesCacheHelper(field, context);
}
};
}

View File

@ -181,6 +181,11 @@ abstract class SortedSetDocValuesRangeQuery extends Query {
}
return new ConstantScoreScorer(this, score(), iterator);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getDocValuesCacheHelper(field, context);
}
};
}

View File

@ -26,6 +26,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause.Occur;
@ -299,6 +300,11 @@ final class BooleanWeight extends Weight {
return scorerSupplier.get(Long.MAX_VALUE);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getCacheHelper(context, weights.toArray(new Weight[0]));
}
@Override
public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException {
int minShouldMatch = query.getMinimumNumberShouldMatch();

View File

@ -167,6 +167,11 @@ public final class ConstantScoreQuery extends Query {
return scorerSupplier.get(Long.MAX_VALUE);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return innerWeight.getCacheHelper(context);
}
};
} else {
return innerWeight;

View File

@ -137,6 +137,11 @@ public final class DisjunctionMaxQuery extends Query implements Iterable<Query>
}
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getCacheHelper(context, weights.toArray(new Weight[0]));
}
/** Explain the score we computed for doc */
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {

View File

@ -23,6 +23,7 @@ import java.util.Objects;
import org.apache.lucene.index.DocValuesType;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
@ -97,6 +98,11 @@ public final class DocValuesFieldExistsQuery extends Query {
return new ConstantScoreScorer(this, score(), iterator);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getDocValuesCacheHelper(field, context);
}
};
}
}

View File

@ -158,6 +158,11 @@ public final class DocValuesRewriteMethod extends MultiTermQuery.RewriteMethod {
}
});
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getDocValuesCacheHelper(query.field, context);
}
};
}
}

View File

@ -19,6 +19,7 @@ package org.apache.lucene.search;
import java.io.IOException;
import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
@ -55,6 +56,11 @@ public abstract class FilterWeight extends Weight {
this.in = weight;
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return in.getCacheHelper(context);
}
@Override
public void extractTerms(Set<Term> terms) {
in.extractTerms(terms);

View File

@ -169,6 +169,13 @@ public final class IndexOrDocValuesQuery extends Query {
}
return scorerSupplier.get(Long.MAX_VALUE);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
// Both index and dv query should return the same values, so we can use
// the index query's cachehelper here
return indexWeight.getCacheHelper(context);
}
};
}

View File

@ -722,8 +722,7 @@ public class LRUQueryCache implements QueryCache, Accountable {
policy.onUse(getQuery());
}
// TODO: should it be pluggable, eg. for queries that run on doc values?
final IndexReader.CacheHelper cacheHelper = context.reader().getCoreCacheHelper();
final IndexReader.CacheHelper cacheHelper = in.getCacheHelper(context);
if (cacheHelper == null) {
// this segment is not suitable for caching
return in.scorerSupplier(context);
@ -788,14 +787,18 @@ public class LRUQueryCache implements QueryCache, Accountable {
return scorerSupplier.get(Long.MAX_VALUE);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return in.getCacheHelper(context);
}
@Override
public BulkScorer bulkScorer(LeafReaderContext context) throws IOException {
if (used.compareAndSet(false, true)) {
policy.onUse(getQuery());
}
// TODO: should it be pluggable, eg. for queries that run on doc values?
final IndexReader.CacheHelper cacheHelper = context.reader().getCoreCacheHelper();
final IndexReader.CacheHelper cacheHelper = in.getCacheHelper(context);
if (cacheHelper == null) {
// this segment is not suitable for caching
return in.bulkScorer(context);

View File

@ -19,6 +19,7 @@ package org.apache.lucene.search;
import java.io.IOException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.util.Bits;
@ -39,6 +40,12 @@ public final class MatchAllDocsQuery extends Query {
public Scorer scorer(LeafReaderContext context) throws IOException {
return new ConstantScoreScorer(this, score(), DocIdSetIterator.all(context.reader().maxDoc()));
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
@Override
public BulkScorer bulkScorer(LeafReaderContext context) throws IOException {
final float score = score();

View File

@ -20,6 +20,7 @@ package org.apache.lucene.search;
import java.io.IOException;
import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
@ -58,6 +59,11 @@ public class MatchNoDocsQuery extends Query {
return null;
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}

View File

@ -291,6 +291,11 @@ public class MultiPhraseQuery extends Query {
}
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
Scorer scorer = scorer(context);

View File

@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.Term;
@ -211,6 +212,11 @@ final class MultiTermQueryConstantScoreWrapper<Q extends MultiTermQuery> extends
return scorer(weightOrBitSet.set);
}
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}
}

View File

@ -23,6 +23,7 @@ import java.util.Objects;
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
@ -75,6 +76,11 @@ public final class NormsFieldExistsQuery extends Query {
DocIdSetIterator iterator = reader.getNormValues(field);
return new ConstantScoreScorer(this, score(), iterator);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}
}

View File

@ -441,7 +441,12 @@ public class PhraseQuery extends Query {
needsScores, totalMatchCost);
}
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
// only called from assert
private boolean termNotInReader(LeafReader reader, Term term) throws IOException {
return reader.docFreq(term) == 0;

View File

@ -23,6 +23,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.apache.lucene.document.IntPoint;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PointValues.IntersectVisitor;
@ -150,6 +151,11 @@ public abstract class PointInSetQuery extends Query {
return new ConstantScoreScorer(this, score(), result.build().iterator());
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.PointValues;
import org.apache.lucene.index.PointValues.IntersectVisitor;
import org.apache.lucene.index.PointValues.Relation;
@ -321,6 +322,11 @@ public abstract class PointRangeQuery extends Query {
}
return scorerSupplier.get(Long.MAX_VALUE);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}

View File

@ -213,6 +213,11 @@ public final class SynonymQuery extends Query {
return new SynonymScorer(simScorer, this, subScorers);
}
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
}
static class SynonymScorer extends DisjunctionScorer {

View File

@ -315,6 +315,11 @@ public class TermInSetQuery extends Query implements Accountable {
return scorer(weightOrBitSet.set);
}
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}
}

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import java.util.Objects;
import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
@ -99,6 +100,11 @@ public class TermQuery extends Query {
return new TermScorer(this, docs, similarity.simScorer(stats, context));
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
/**
* Returns a {@link TermsEnum} positioned at this weights Term or null if
* the term does not exist in the given context

View File

@ -20,6 +20,8 @@ package org.apache.lucene.search;
import java.io.IOException;
import java.util.Set;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
@ -102,6 +104,55 @@ public abstract class Weight {
*/
public abstract Scorer scorer(LeafReaderContext context) throws IOException;
/**
* Returns an {@link org.apache.lucene.index.IndexReader.CacheHelper} to cache this query against
*
* Weights that rely only on Terms or Points can return {@code context.reader().getCoreCacheHelper()}.
* Weights that use DocValues should call {@link #getDocValuesCacheHelper(String, LeafReaderContext)}
* Weights that should not be cached at all should return {@code null}
*
* @param context the {@link LeafReaderContext} to cache against
* @return an {@link org.apache.lucene.index.IndexReader.CacheHelper} indicating the cache level
*/
public abstract IndexReader.CacheHelper getCacheHelper(LeafReaderContext context);
/**
* Given a collection of Weights, return an {@link org.apache.lucene.index.IndexReader.CacheHelper} that will satisfy
* the requirements of them all.
* @param context the {@link LeafReaderContext} to cache against
* @param weights an array of {@link Weight} to be cached
* @return an {@link org.apache.lucene.index.IndexReader.CacheHelper} indicating the cache level
*/
protected static IndexReader.CacheHelper getCacheHelper(LeafReaderContext context, Weight... weights) {
if (weights.length == 0)
return null;
IndexReader.CacheHelper helper = weights[0].getCacheHelper(context);
if (helper == null)
return null;
for (int i = 1; i < weights.length; i++) {
IndexReader.CacheHelper nextHelper = weights[i].getCacheHelper(context);
if (nextHelper == null || nextHelper != helper)
return null;
}
return helper;
}
/**
* Returns an {@link org.apache.lucene.index.IndexReader.CacheHelper} for a Weight using doc values
*
* This will return the core reader for
*
* @param field the docvalues field
* @param ctx the {@link LeafReaderContext} to cache against
* @return an {@link org.apache.lucene.index.IndexReader.CacheHelper} indicating the cache level
*/
public static IndexReader.CacheHelper getDocValuesCacheHelper(String field, LeafReaderContext ctx) {
FieldInfo fi = ctx.reader().getFieldInfos().fieldInfo(field);
if (fi == null || fi.getDocValuesGen() == -1)
return ctx.reader().getCoreCacheHelper();
return null;
}
/**
* Optional method.
* Get a {@link ScorerSupplier}, which allows to know the cost of the {@link Scorer}

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext;
@ -115,5 +116,10 @@ public final class SpanContainingQuery extends SpanContainQuery {
}
};
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getCacheHelper(context, bigWeight, littleWeight);
}
}
}

View File

@ -33,6 +33,7 @@ import org.apache.lucene.index.TermContext;
import org.apache.lucene.index.Terms;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Weight;
/** Matches spans which are near one another. One can specify <i>slop</i>, the
* maximum number of intervening unmatched positions, as well as whether
@ -229,6 +230,11 @@ public class SpanNearQuery extends SpanQuery implements Cloneable {
w.extractTerms(terms);
}
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getCacheHelper(context, subWeights.toArray(new Weight[0]));
}
}
@Override
@ -319,6 +325,11 @@ public class SpanNearQuery extends SpanQuery implements Cloneable {
public void extractTerms(Set<Term> terms) {
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
}
@Override

View File

@ -191,6 +191,11 @@ public final class SpanNotQuery extends SpanQuery {
public void extractTerms(Set<Term> terms) {
includeWeight.extractTerms(terms);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getCacheHelper(context, includeWeight, excludeWeight);
}
}
@Override

View File

@ -34,6 +34,7 @@ import org.apache.lucene.search.DisjunctionDISIApproximation;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TwoPhaseIterator;
import org.apache.lucene.search.Weight;
/** Matches the union of its clauses.
@ -138,6 +139,11 @@ public final class SpanOrQuery extends SpanQuery {
}
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getCacheHelper(context, subWeights.toArray(new Weight[0]));
}
@Override
public void extractTermContexts(Map<Term, TermContext> contexts) {
for (SpanWeight w : subWeights) {

View File

@ -86,6 +86,11 @@ public abstract class SpanPositionCheckQuery extends SpanQuery implements Clonea
matchWeight.extractTerms(terms);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return matchWeight.getCacheHelper(context);
}
@Override
public void extractTermContexts(Map<Term, TermContext> contexts) {
matchWeight.extractTermContexts(contexts);

View File

@ -23,6 +23,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PostingsEnum;
@ -91,6 +92,11 @@ public class SpanTermQuery extends SpanQuery {
terms.add(term);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
@Override
public void extractTermContexts(Map<Term, TermContext> contexts) {
contexts.put(term, termContext);

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext;
@ -116,6 +117,11 @@ public final class SpanWithinQuery extends SpanContainQuery {
}
};
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getCacheHelper(context, littleWeight, bigWeight);
}
}
}

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import java.util.Set;
import org.apache.lucene.index.FieldInvertState;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.similarities.Similarity;
@ -262,6 +263,11 @@ final class JustCompileSearch {
throw new UnsupportedOperationException(UNSUPPORTED_MSG);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null;
}
}
}

View File

@ -94,6 +94,11 @@ public class TestBooleanScorer extends LuceneTestCase {
throw new UnsupportedOperationException();
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null;
}
@Override
public BulkScorer bulkScorer(LeafReaderContext context) {
return new BulkScorer() {

View File

@ -29,6 +29,7 @@ import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@ -36,15 +37,16 @@ import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.StringField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.FilterDirectoryReader;
import org.apache.lucene.index.FilterLeafReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
@ -358,6 +360,11 @@ public class TestLRUQueryCache extends LuceneTestCase {
public Scorer scorer(LeafReaderContext context) throws IOException {
return null;
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}
@ -947,6 +954,11 @@ public class TestLRUQueryCache extends LuceneTestCase {
public Scorer scorer(LeafReaderContext context) throws IOException {
return null;
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}
@ -1276,6 +1288,78 @@ public class TestLRUQueryCache extends LuceneTestCase {
dir.close();
}
// A query that returns null from Weight.getCacheHelper
private static class NoCacheQuery extends Query {
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
return new Weight(this) {
@Override
public void extractTerms(Set<Term> terms) {
}
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
return null;
}
@Override
public Scorer scorer(LeafReaderContext context) throws IOException {
return null;
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null;
}
};
}
@Override
public String toString(String field) {
return "NoCacheQuery";
}
@Override
public boolean equals(Object obj) {
return sameClassAs(obj);
}
@Override
public int hashCode() {
return 0;
}
}
public void testQueryNotSuitedForCaching() throws IOException {
Directory dir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig().setMergePolicy(NoMergePolicy.INSTANCE);
RandomIndexWriter w = new RandomIndexWriter(random(), dir, iwc);
w.addDocument(new Document());
DirectoryReader reader = w.getReader();
IndexSearcher searcher = newSearcher(reader);
searcher.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
LRUQueryCache cache = new LRUQueryCache(2, 10000, context -> true);
searcher.setQueryCache(cache);
assertEquals(0, searcher.count(new NoCacheQuery()));
assertEquals(0, cache.getCacheCount());
// BooleanQuery wrapping an uncacheable query should also not be cached
BooleanQuery bq = new BooleanQuery.Builder()
.add(new NoCacheQuery(), Occur.MUST)
.add(new TermQuery(new Term("field", "term")), Occur.MUST).build();
assertEquals(0, searcher.count(bq));
assertEquals(0, cache.getCacheCount());
reader.close();
w.close();
dir.close();
}
private static class DummyQuery2 extends Query {
private final AtomicBoolean scorerCreated;
@ -1291,6 +1375,12 @@ public class TestLRUQueryCache extends LuceneTestCase {
public Scorer scorer(LeafReaderContext context) throws IOException {
return scorerSupplier(context).get(Long.MAX_VALUE);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
@Override
public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException {
final Weight weight = this;
@ -1351,4 +1441,110 @@ public class TestLRUQueryCache extends LuceneTestCase {
w.close();
dir.close();
}
static class DVCacheQuery extends Query {
final String field;
AtomicInteger scorerCreatedCount = new AtomicInteger(0);
DVCacheQuery(String field) {
this.field = field;
}
@Override
public String toString(String field) {
return "DVCacheQuery";
}
@Override
public boolean equals(Object obj) {
return sameClassAs(obj);
}
@Override
public int hashCode() {
return 0;
}
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
return new ConstantScoreWeight(this, 1) {
@Override
public Scorer scorer(LeafReaderContext context) throws IOException {
scorerCreatedCount.incrementAndGet();
return new ConstantScoreScorer(this, 1, DocIdSetIterator.all(context.reader().maxDoc()));
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getDocValuesCacheHelper(field, context);
}
};
}
}
public void testDocValuesUpdatesDontBreakCache() throws IOException {
Directory dir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig().setMergePolicy(NoMergePolicy.INSTANCE);
//RandomIndexWriter w = new RandomIndexWriter(random(), dir, iwc);
IndexWriter w = new IndexWriter(dir, iwc);
w.addDocument(new Document());
w.commit();
DirectoryReader reader = DirectoryReader.open(w);
IndexSearcher searcher = newSearcher(reader);
searcher.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
LRUQueryCache cache = new LRUQueryCache(1, 1000, context -> true);
searcher.setQueryCache(cache);
DVCacheQuery query = new DVCacheQuery("field");
assertEquals(1, searcher.count(query));
assertEquals(1, query.scorerCreatedCount.get());
assertEquals(1, searcher.count(query));
assertEquals(1, query.scorerCreatedCount.get()); // should be cached
Document doc = new Document();
doc.add(new NumericDocValuesField("field", 1));
doc.add(newTextField("text", "text", Store.NO));
w.addDocument(doc);
reader.close();
reader = DirectoryReader.open(w);
searcher = newSearcher(reader);
searcher.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
searcher.setQueryCache(cache);
assertEquals(2, searcher.count(query));
assertEquals(2, query.scorerCreatedCount.get()); // first segment cached
reader.close();
reader = DirectoryReader.open(w);
searcher = newSearcher(reader);
searcher.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
searcher.setQueryCache(cache);
assertEquals(2, searcher.count(query));
assertEquals(2, query.scorerCreatedCount.get()); // both segments cached
w.updateNumericDocValue(new Term("text", "text"), "field", 2l);
reader.close();
reader = DirectoryReader.open(w);
searcher = newSearcher(reader);
searcher.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
searcher.setQueryCache(cache);
assertEquals(2, searcher.count(query));
assertEquals(3, query.scorerCreatedCount.get()); // second segment no longer cached due to DV update
assertEquals(2, searcher.count(query));
assertEquals(4, query.scorerCreatedCount.get()); // still no caching
reader.close();
w.close();
dir.close();
}
}

View File

@ -18,7 +18,6 @@ package org.apache.lucene.search;
import java.io.IOException;
import java.util.Set;
import java.util.Objects;
import org.apache.lucene.document.Document;
@ -103,17 +102,7 @@ public class TestNeedsScores extends LuceneTestCase {
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
final Weight w = in.createWeight(searcher, needsScores, boost);
return new Weight(AssertNeedsScores.this) {
@Override
public void extractTerms(Set<Term> terms) {
w.extractTerms(terms);
}
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
return w.explain(context, doc);
}
return new FilterWeight(w) {
@Override
public Scorer scorer(LeafReaderContext context) throws IOException {
assertEquals("query=" + in, value, needsScores);

View File

@ -487,6 +487,11 @@ public class TestQueryRescorer extends LuceneTestCase {
};
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null;
}
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
return null;

View File

@ -155,6 +155,11 @@ public class TestScorerPerf extends LuceneTestCase {
public Scorer scorer(LeafReaderContext context) throws IOException {
return new ConstantScoreScorer(this, score(), new BitSetIterator(docs, docs.approximateCardinality()));
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null;
}
};
}

View File

@ -249,6 +249,11 @@ public class TestSortRandom extends LuceneTestCase {
return new ConstantScoreScorer(this, score(), new BitSetIterator(bits, bits.approximateCardinality()));
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null;
}
};
}

View File

@ -124,6 +124,11 @@ public class TestUsageTrackingFilterCachingPolicy extends LuceneTestCase {
public Scorer scorer(LeafReaderContext context) throws IOException {
return new ConstantScoreScorer(this, score(), DocIdSetIterator.all(1));
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}

View File

@ -101,6 +101,14 @@ class DrillSidewaysQuery extends Query {
throw new UnsupportedOperationException();
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
Weight[] weights = new Weight[drillDowns.length + 1];
weights[0] = baseWeight;
System.arraycopy(drillDowns, 0, weights, 1, drillDowns.length);
return getCacheHelper(context, weights);
}
@Override
public BulkScorer bulkScorer(LeafReaderContext context) throws IOException {
Scorer baseScorer = baseWeight.scorer(context);

View File

@ -171,6 +171,11 @@ public final class DoubleRange extends Range {
};
return new ConstantScoreScorer(this, score(), twoPhase);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null; // TODO delegate to LongValuesSource?
}
};
}

View File

@ -163,6 +163,11 @@ public final class LongRange extends Range {
};
return new ConstantScoreScorer(this, score(), twoPhase);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null; // TODO delegate to LongValuesSource?
}
};
}

View File

@ -16,6 +16,16 @@
*/
package org.apache.lucene.facet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
@ -58,16 +68,6 @@ import org.apache.lucene.util.InPlaceMergeSorter;
import org.apache.lucene.util.InfoStream;
import org.apache.lucene.util.TestUtil;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class TestDrillSideways extends FacetTestCase {
protected DrillSideways getNewDrillSideways(IndexSearcher searcher, FacetsConfig config,
@ -740,6 +740,11 @@ public class TestDrillSideways extends FacetTestCase {
});
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null;
}
};
}

View File

@ -20,7 +20,6 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.lucene.document.Document;
@ -29,8 +28,8 @@ import org.apache.lucene.document.DoublePoint;
import org.apache.lucene.document.LongPoint;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.facet.DrillDownQuery;
import org.apache.lucene.facet.DrillSideways.DrillSidewaysResult;
import org.apache.lucene.facet.DrillSideways;
import org.apache.lucene.facet.DrillSideways.DrillSidewaysResult;
import org.apache.lucene.facet.FacetField;
import org.apache.lucene.facet.FacetResult;
import org.apache.lucene.facet.FacetTestCase;
@ -46,10 +45,10 @@ import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.DoubleValues;
import org.apache.lucene.search.DoubleValuesSource;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.FilterWeight;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.LongValuesSource;
import org.apache.lucene.search.MatchAllDocsQuery;
@ -717,24 +716,12 @@ public class TestRangeFacetCounts extends FacetTestCase {
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
final Weight in = this.in.createWeight(searcher, needsScores, boost);
return new Weight(in.getQuery()) {
@Override
public void extractTerms(Set<Term> terms) {
in.extractTerms(terms);
}
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
return in.explain(context, doc);
}
return new FilterWeight(in) {
@Override
public Scorer scorer(LeafReaderContext context) throws IOException {
used.set(true);
return in.scorer(context);
}
};
}

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.Set;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.OrdinalMap;
import org.apache.lucene.index.SortedDocValues;
@ -154,6 +155,11 @@ final class GlobalOrdinalsQuery extends Query {
}
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getDocValuesCacheHelper(joinField, context);
}
}
final static class OrdinalMapScorer extends BaseGlobalOrdinalScorer {

View File

@ -194,6 +194,11 @@ public class ParentChildrenBlockJoinQuery extends Query {
}
};
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null; // TODO delegate to BitSetProducer?
}
};
}
}

View File

@ -29,6 +29,7 @@ import org.apache.lucene.document.FloatPoint;
import org.apache.lucene.document.IntPoint;
import org.apache.lucene.document.LongPoint;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PointValues;
@ -186,6 +187,11 @@ abstract class PointInSetIncludingScoreQuery extends Query {
};
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}

View File

@ -21,6 +21,7 @@ import java.util.Locale;
import java.util.Objects;
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;
@ -140,6 +141,11 @@ class TermsIncludingScoreQuery extends Query {
}
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}

View File

@ -562,6 +562,11 @@ public class TestJoinUtil extends LuceneTestCase {
}
};
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null;
}
};
}

View File

@ -121,6 +121,11 @@ public class BoostingQuery extends Query {
}
};
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getCacheHelper(context, matchWeight, contextWeight);
}
};
}

View File

@ -207,6 +207,14 @@ public class CustomScoreQuery extends Query implements Cloneable {
return new CustomScorer(CustomScoreQuery.this.getCustomScoreProvider(context), this, queryWeight, subQueryScorer, valSrcScorers);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
Weight[] weights = new Weight[valSrcWeights.length + 1];
weights[0] = subQueryWeight;
System.arraycopy(valSrcWeights, 0, weights, 1, valSrcWeights.length);
return getCacheHelper(context, weights);
}
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
Explanation explain = doExplain(context, doc);

View File

@ -88,6 +88,11 @@ public final class BoostedQuery extends Query {
return new BoostedQuery.CustomScorer(context, this, subQueryScorer, boostVal);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null;
}
@Override
public Explanation explain(LeafReaderContext readerContext, int doc) throws IOException {
Explanation subQueryExpl = qWeight.explain(readerContext,doc);

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import java.util.Objects;
import java.util.function.DoublePredicate;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.ConstantScoreScorer;
import org.apache.lucene.search.ConstantScoreWeight;
@ -80,6 +81,11 @@ public final class FunctionMatchQuery extends Query {
};
return new ConstantScoreScorer(this, score(), twoPhase);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null; // TODO delegate to DoubleValuesSource?
}
};
}

View File

@ -74,6 +74,11 @@ public class FunctionQuery extends Query {
return new AllScorer(context, this, boost);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null;
}
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
return ((AllScorer)scorer(context)).explain(doc);

View File

@ -21,6 +21,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Explanation;
@ -153,5 +154,10 @@ public class FunctionRangeQuery extends Query {
// getRangeScorer takes String args and parses them. Weird.
return functionValues.getRangeScorer(context, lowerVal, upperVal, includeLower, includeUpper);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null;
}
}
}

View File

@ -137,5 +137,10 @@ public final class FunctionScoreQuery extends Query {
}
};
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null; // TODO delegate to DoubleValuesSource
}
}
}

View File

@ -161,6 +161,11 @@ public class PayloadScoreQuery extends SpanQuery {
return new PayloadSpanScorer(this, payloadSpans, docScorer);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return innerWeight.getCacheHelper(context);
}
@Override
public void extractTerms(Set<Term> terms) {
innerWeight.extractTerms(terms);

View File

@ -129,6 +129,11 @@ public class SpanPayloadCheckQuery extends SpanQuery {
final Similarity.SimScorer docScorer = getSimScorer(context);
return new SpanScorer(this, spans, docScorer);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return matchWeight.getCacheHelper(context);
}
}
private class PayloadChecker implements SpanCollector {

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import org.apache.lucene.geo.GeoEncodingUtils;
import org.apache.lucene.geo.GeoUtils;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.search.ConstantScoreScorer;
@ -139,6 +140,11 @@ final class LatLonDocValuesBoxQuery extends Query {
};
return new ConstantScoreScorer(this, boost, iterator);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getDocValuesCacheHelper(field, context);
}
};
}

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import org.apache.lucene.geo.GeoEncodingUtils;
import org.apache.lucene.geo.GeoUtils;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.search.ConstantScoreScorer;
@ -126,6 +127,11 @@ final class LatLonDocValuesDistanceQuery extends Query {
};
return new ConstantScoreScorer(this, boost, iterator);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getDocValuesCacheHelper(field, context);
}
};
}

View File

@ -22,6 +22,7 @@ import org.apache.lucene.geo.GeoEncodingUtils;
import org.apache.lucene.geo.GeoUtils;
import org.apache.lucene.geo.Rectangle;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PointValues;
@ -117,6 +118,11 @@ final class LatLonPointDistanceQuery extends Query {
return scorerSupplier.get(Long.MAX_VALUE);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
@Override
public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException {
LeafReader reader = context.reader();

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.Arrays;
import org.apache.lucene.geo.Rectangle;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.PointValues.IntersectVisitor;
import org.apache.lucene.index.PointValues.Relation;
import org.apache.lucene.search.ConstantScoreScorer;
@ -159,6 +160,11 @@ final class LatLonPointInPolygonQuery extends Query {
return new ConstantScoreScorer(this, score(), result.build().iterator());
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}

View File

@ -175,6 +175,11 @@ public final class CoveringQuery extends Query {
}
return new CoveringScorer(this, scorers, minimumNumberMatch.getValues(context, null), context.reader().maxDoc());
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null; // TODO delegate to LongValuesSource?
}
}
}

View File

@ -26,6 +26,7 @@ import java.util.Set;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.SortedNumericDocValues;
@ -121,6 +122,11 @@ public class DocValuesNumbersQuery extends Query {
}
});
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getDocValuesCacheHelper(field, context);
}
};
}
}

View File

@ -203,6 +203,11 @@ public class DocValuesTermsQuery extends Query {
});
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getDocValuesCacheHelper(field, context);
}
};
}

View File

@ -402,7 +402,12 @@ public class TermAutomatonQuery extends Query {
return null;
}
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
// TODO

View File

@ -650,6 +650,11 @@ public class TestTermAutomatonQuery extends LuceneTestCase {
}
return new ConstantScoreScorer(this, score(), new BitSetIterator(bits, bits.approximateCardinality()));
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null;
}
};
}

View File

@ -96,6 +96,11 @@ public class CompositeVerifyQuery extends Query {
final TwoPhaseIterator predFuncValues = predicateValueSource.iterator(context, indexQueryScorer.iterator());
return new ConstantScoreScorer(this, score(), predFuncValues);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null; // TODO delegate to PredicateValueSource?
}
};
}
}

View File

@ -18,6 +18,7 @@ package org.apache.lucene.spatial.composite;
import java.io.IOException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.ConstantScoreScorer;
import org.apache.lucene.search.ConstantScoreWeight;
@ -133,6 +134,11 @@ public class IntersectsRPTVerifyQuery extends Query {
return new ConstantScoreScorer(this, score(), twoPhaseIterator);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null; // TODO delegate to PredicateValueSource?
}
};
}

View File

@ -18,6 +18,7 @@ package org.apache.lucene.spatial.prefix;
import java.io.IOException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PostingsEnum;
@ -90,6 +91,11 @@ public abstract class AbstractPrefixTreeQuery extends Query {
}
return new ConstantScoreScorer(this, score(), disi);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}

View File

@ -27,6 +27,7 @@ import org.apache.lucene.document.BinaryDocValuesField;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.ConstantScoreScorer;
import org.apache.lucene.search.ConstantScoreWeight;
@ -141,6 +142,11 @@ public class SerializedDVStrategy extends SpatialStrategy {
TwoPhaseIterator it = predicateValueSource.iterator(context, approximation);
return new ConstantScoreScorer(this, score(), it);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null; // TODO delegate to PredicateValueSource
}
};
}

View File

@ -288,6 +288,11 @@ public class PointVectorStrategy extends SpatialStrategy {
};
return new ConstantScoreScorer(this, score(), twoPhase);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null; // TODO delegate to DoubleValuesSource?
}
};
}

View File

@ -18,6 +18,7 @@ package org.apache.lucene.spatial3d;
import java.io.IOException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.spatial3d.geom.BasePlanetObject;
import org.apache.lucene.spatial3d.geom.GeoShape;
import org.apache.lucene.spatial3d.geom.PlanetModel;
@ -103,6 +104,11 @@ final class PointInGeo3DShapeQuery extends Query {
return new ConstantScoreScorer(this, score(), result.build().iterator());
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}

View File

@ -19,6 +19,7 @@ package org.apache.lucene.search.suggest.document;
import java.io.IOException;
import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
@ -132,6 +133,11 @@ public class CompletionWeight extends Weight {
throw new UnsupportedOperationException();
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
@Override
public void extractTerms(Set<Term> terms) {
// no-op

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.Map;
import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext;
@ -72,6 +73,11 @@ public class AssertingSpanWeight extends SpanWeight {
return in.scorer(context);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return in.getCacheHelper(context);
}
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
return in.explain(context, doc);

View File

@ -31,6 +31,7 @@ import java.util.concurrent.FutureTask;
import java.util.concurrent.RunnableFuture;
import java.util.concurrent.Semaphore;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.DisiPriorityQueue;
@ -479,6 +480,11 @@ public class LTRScoringQuery extends Query {
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null;
}
public class ModelScorer extends Scorer {
final private DocInfo docInfo;
final private Scorer featureTraversalScorer;

View File

@ -21,6 +21,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.DocIdSetIterator;
@ -228,6 +229,11 @@ public abstract class Feature extends Query {
public abstract FeatureScorer scorer(LeafReaderContext context)
throws IOException;
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null;
}
@Override
public Explanation explain(LeafReaderContext context, int doc)
throws IOException {

View File

@ -140,9 +140,6 @@ public class ValueFeature extends Feature {
}
}
}

View File

@ -486,6 +486,11 @@ public final class SolrRangeQuery extends ExtendedQueryBase implements DocSetPro
return scorer(weightOrBitSet.set);
}
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
}
}

View File

@ -332,6 +332,11 @@ class SpatialDistanceQuery extends ExtendedQueryBase implements PostFilter {
return new SpatialScorer(context, this, score());
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null;
}
@Override
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
return ((SpatialScorer)scorer(context)).explain(super.explain(context, doc), doc);

View File

@ -19,6 +19,7 @@ package org.apache.solr.search;
import java.io.IOException;
import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.ConstantScoreScorer;
@ -135,6 +136,11 @@ public abstract class Filter extends Query {
return new ConstantScoreScorer(this, 0f, iterator);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getReaderCacheHelper();
}
};
}
}

View File

@ -330,6 +330,11 @@ public class GraphTermsQParserPlugin extends QParserPlugin {
return scorer(weightOrBitSet.set);
}
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}
@ -624,6 +629,11 @@ abstract class PointSetQuery extends Query implements DocSetProducer {
}
return new ConstantScoreScorer(this, score(), readerSetIterator);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}

View File

@ -282,6 +282,11 @@ class JoinQuery extends Query {
return new ConstantScoreScorer(this, score(), readerSetIterator);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return null;
}
// most of these statistics are only used for the enum method
int fromSetSize; // number of docs in the fromSet (that match the from query)

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.Map;
import java.util.Objects;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.search.ConstantScoreScorer;
@ -104,6 +105,11 @@ public class SolrConstantScoreQuery extends Query implements ExtendedQuery {
return new ConstantScoreScorer(this, score(), iterator);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
}
@Override

View File

@ -23,6 +23,7 @@ import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
@ -275,7 +276,12 @@ public class GraphQuery extends Query {
// create a scrorer on the result set, if results from right query are empty, use empty iterator.
return new GraphScorer(this, readerSet == null ? DocIdSetIterator.empty() : readerSet.iterator(), 1);
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
@Override
public void extractTerms(Set<Term> terms) {
// NoOp for now , not used.. / supported

View File

@ -83,6 +83,11 @@ final class DeleteByQueryWrapper extends Query {
public Scorer scorer(LeafReaderContext context) throws IOException {
return inner.scorer(privateContext.getIndexReader().leaves().get(0));
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return inner.getCacheHelper(context);
}
};
}

View File

@ -288,6 +288,11 @@ public class TestFieldCacheSortRandom extends LuceneTestCase {
return new ConstantScoreScorer(this, score(), new BitSetIterator(bits, bits.approximateCardinality()));
}
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return context.reader().getCoreCacheHelper();
}
};
}