mirror of https://github.com/apache/lucene.git
LUCENE-8042: Add SegmentCachable interface
This commit is contained in:
parent
281e84b988
commit
276e317e94
|
@ -21,7 +21,6 @@ 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;
|
||||
|
@ -359,9 +358,10 @@ abstract class RangeFieldQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -94,6 +94,12 @@ abstract class SortedNumericDocValuesRangeQuery extends Query {
|
|||
@Override
|
||||
public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
|
||||
return new ConstantScoreWeight(this, boost) {
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx, field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Scorer scorer(LeafReaderContext context) throws IOException {
|
||||
SortedNumericDocValues values = getValues(context.reader(), field);
|
||||
|
@ -139,10 +145,6 @@ abstract class SortedNumericDocValuesRangeQuery extends Query {
|
|||
return new ConstantScoreScorer(this, score(), iterator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getDocValuesCacheHelper(field, context);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -183,9 +183,10 @@ abstract class SortedSetDocValuesRangeQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getDocValuesCacheHelper(field, context);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx, field);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -437,4 +437,16 @@ public final class DocValues {
|
|||
}
|
||||
return dv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the specified docvalues fields have not been updated
|
||||
*/
|
||||
public static boolean isCacheable(LeafReaderContext ctx, String... fields) {
|
||||
for (String field : fields) {
|
||||
FieldInfo fi = ctx.reader().getFieldInfos().fieldInfo(field);
|
||||
if (fi != null && fi.getDocValuesGen() > -1)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ 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;
|
||||
|
@ -301,8 +300,12 @@ final class BooleanWeight extends Weight {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getCacheHelper(context, weights);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
for (Weight w : weights) {
|
||||
if (w.isCacheable(ctx) == false)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -168,8 +168,8 @@ public final class ConstantScoreQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return innerWeight.getCacheHelper(context);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return innerWeight.isCacheable(ctx);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -138,8 +138,12 @@ public final class DisjunctionMaxQuery extends Query implements Iterable<Query>
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getCacheHelper(context, weights);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
for (Weight w : weights) {
|
||||
if (w.isCacheable(ctx) == false)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Explain the score we computed for doc */
|
||||
|
|
|
@ -20,10 +20,10 @@ package org.apache.lucene.search;
|
|||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.lucene.index.DocValues;
|
||||
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;
|
||||
|
||||
|
@ -100,9 +100,10 @@ public final class DocValuesFieldExistsQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getDocValuesCacheHelper(field, context);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx, field);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,9 +160,10 @@ public final class DocValuesRewriteMethod extends MultiTermQuery.RewriteMethod {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getDocValuesCacheHelper(query.field, context);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx, query.field);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ import org.apache.lucene.index.NumericDocValues;
|
|||
* {@link #fromScorer(Scorer)} and passing the resulting DoubleValues to {@link #getValues(LeafReaderContext, DoubleValues)}.
|
||||
* The scores can then be accessed using the {@link #SCORES} DoubleValuesSource.
|
||||
*/
|
||||
public abstract class DoubleValuesSource {
|
||||
public abstract class DoubleValuesSource implements SegmentCacheable {
|
||||
|
||||
/**
|
||||
* Returns a {@link DoubleValues} instance for the passed-in LeafReaderContext and scores
|
||||
|
@ -104,22 +104,27 @@ public abstract class DoubleValuesSource {
|
|||
}
|
||||
|
||||
@Override
|
||||
public LongValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException {
|
||||
DoubleValues in = inner.getValues(ctx, scores);
|
||||
return new LongValues() {
|
||||
@Override
|
||||
public long longValue() throws IOException {
|
||||
return (long) in.doubleValue();
|
||||
}
|
||||
public LongValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException {
|
||||
DoubleValues in = inner.getValues(ctx, scores);
|
||||
return new LongValues() {
|
||||
@Override
|
||||
public long longValue() throws IOException {
|
||||
return (long) in.doubleValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean advanceExact(int doc) throws IOException {
|
||||
return in.advanceExact(doc);
|
||||
}
|
||||
};
|
||||
}
|
||||
@Override
|
||||
public boolean advanceExact(int doc) throws IOException {
|
||||
return in.advanceExact(doc);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return inner.isCacheable(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsScores() {
|
||||
return inner.needsScores();
|
||||
}
|
||||
|
@ -200,6 +205,11 @@ public abstract class DoubleValuesSource {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) {
|
||||
return scoreExplanation;
|
||||
|
@ -256,6 +266,11 @@ public abstract class DoubleValuesSource {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) {
|
||||
return Explanation.match((float) value, "constant(" + value + ")");
|
||||
|
@ -348,6 +363,11 @@ public abstract class DoubleValuesSource {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx, field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
|
||||
DoubleValues values = getValues(ctx, null);
|
||||
|
|
|
@ -19,7 +19,6 @@ 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;
|
||||
|
||||
|
@ -57,8 +56,8 @@ public abstract class FilterWeight extends Weight {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return in.getCacheHelper(context);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return in.isCacheable(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -171,11 +171,12 @@ public final class IndexOrDocValuesQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
// Both index and dv query should return the same values, so we can use
|
||||
// the index query's cachehelper here
|
||||
return indexWeight.getCacheHelper(context);
|
||||
return indexWeight.isCacheable(ctx);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -722,8 +722,7 @@ public class LRUQueryCache implements QueryCache, Accountable {
|
|||
policy.onUse(getQuery());
|
||||
}
|
||||
|
||||
final IndexReader.CacheHelper cacheHelper = in.getCacheHelper(context);
|
||||
if (cacheHelper == null) {
|
||||
if (in.isCacheable(context) == false) {
|
||||
// this segment is not suitable for caching
|
||||
return in.scorerSupplier(context);
|
||||
}
|
||||
|
@ -739,6 +738,11 @@ public class LRUQueryCache implements QueryCache, Accountable {
|
|||
return in.scorerSupplier(context);
|
||||
}
|
||||
|
||||
final IndexReader.CacheHelper cacheHelper = context.reader().getCoreCacheHelper();
|
||||
if (cacheHelper == null) {
|
||||
// this reader has no cache helper
|
||||
return in.scorerSupplier(context);
|
||||
}
|
||||
DocIdSet docIdSet;
|
||||
try {
|
||||
docIdSet = get(in.getQuery(), context, cacheHelper);
|
||||
|
@ -788,8 +792,8 @@ public class LRUQueryCache implements QueryCache, Accountable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return in.getCacheHelper(context);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return in.isCacheable(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -798,8 +802,7 @@ public class LRUQueryCache implements QueryCache, Accountable {
|
|||
policy.onUse(getQuery());
|
||||
}
|
||||
|
||||
final IndexReader.CacheHelper cacheHelper = in.getCacheHelper(context);
|
||||
if (cacheHelper == null) {
|
||||
if (in.isCacheable(context) == false) {
|
||||
// this segment is not suitable for caching
|
||||
return in.bulkScorer(context);
|
||||
}
|
||||
|
@ -815,6 +818,11 @@ public class LRUQueryCache implements QueryCache, Accountable {
|
|||
return in.bulkScorer(context);
|
||||
}
|
||||
|
||||
final IndexReader.CacheHelper cacheHelper = context.reader().getCoreCacheHelper();
|
||||
if (cacheHelper == null) {
|
||||
// this reader has no cacheHelper
|
||||
return in.bulkScorer(context);
|
||||
}
|
||||
DocIdSet docIdSet;
|
||||
try {
|
||||
docIdSet = get(in.getQuery(), context, cacheHelper);
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.apache.lucene.index.NumericDocValues;
|
|||
* use {@link DoubleValuesSource#fromFloatField(String)} or {@link DoubleValuesSource#fromDoubleField(String)}
|
||||
* and then call {@link DoubleValuesSource#toLongValuesSource()}.
|
||||
*/
|
||||
public abstract class LongValuesSource {
|
||||
public abstract class LongValuesSource implements SegmentCacheable {
|
||||
|
||||
/**
|
||||
* Returns a {@link LongValues} instance for the passed-in LeafReaderContext and scores
|
||||
|
@ -113,6 +113,11 @@ public abstract class LongValuesSource {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsScores() {
|
||||
return false;
|
||||
|
@ -170,6 +175,11 @@ public abstract class LongValuesSource {
|
|||
return toLongValues(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx, field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsScores() {
|
||||
return false;
|
||||
|
|
|
@ -19,7 +19,6 @@ 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;
|
||||
|
||||
|
@ -42,8 +41,8 @@ public final class MatchAllDocsQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,7 +20,6 @@ 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;
|
||||
|
||||
|
@ -60,10 +59,9 @@ public class MatchNoDocsQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -292,8 +292,8 @@ public class MultiPhraseQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,7 +22,6 @@ 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;
|
||||
|
@ -214,9 +213,10 @@ final class MultiTermQueryConstantScoreWrapper<Q extends MultiTermQuery> extends
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ 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;
|
||||
|
||||
|
@ -78,8 +77,8 @@ public final class NormsFieldExistsQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -443,8 +443,8 @@ public class PhraseQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// only called from assert
|
||||
|
|
|
@ -22,15 +22,15 @@ import java.util.Arrays;
|
|||
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;
|
||||
import org.apache.lucene.index.PointValues.IntersectVisitor;
|
||||
import org.apache.lucene.index.PointValues.Relation;
|
||||
import org.apache.lucene.index.PointValues;
|
||||
import org.apache.lucene.index.PrefixCodedTerms.TermIterator;
|
||||
import org.apache.lucene.index.PrefixCodedTerms;
|
||||
import org.apache.lucene.index.PrefixCodedTerms.TermIterator;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.BytesRefBuilder;
|
||||
import org.apache.lucene.util.BytesRefIterator;
|
||||
|
@ -153,9 +153,10 @@ public abstract class PointInSetQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -20,13 +20,12 @@ import java.io.IOException;
|
|||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.document.IntPoint;
|
||||
import org.apache.lucene.index.LeafReader;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.index.PointValues;
|
||||
import org.apache.lucene.index.PointValues.IntersectVisitor;
|
||||
import org.apache.lucene.index.PointValues.Relation;
|
||||
import org.apache.lucene.document.IntPoint; // javadocs
|
||||
import org.apache.lucene.index.LeafReader;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.util.BitSetIterator;
|
||||
import org.apache.lucene.util.DocIdSetBuilder;
|
||||
import org.apache.lucene.util.FixedBitSet;
|
||||
|
@ -324,9 +323,10 @@ public abstract class PointRangeQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.lucene.search;
|
||||
|
||||
import org.apache.lucene.index.DocValues;
|
||||
import org.apache.lucene.index.LeafReader;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
|
||||
/**
|
||||
* Interface defining whether or not an object can be cached against a {@link LeafReader}
|
||||
*
|
||||
* Objects that depend only on segment-immutable structures such as Points or postings lists
|
||||
* can just return {@code true} from {@link #isCacheable(LeafReaderContext)}
|
||||
*
|
||||
* Objects that depend on doc values should return {@link DocValues#isCacheable(LeafReaderContext, String...)}, which
|
||||
* will check to see if the doc values fields have been updated. Updated doc values fields are not suitable
|
||||
* for cacheing.
|
||||
*
|
||||
* Objects that are not segment-immutable, such as those that rely on global statistics or scores,
|
||||
* should return {@code false}
|
||||
*/
|
||||
public interface SegmentCacheable {
|
||||
|
||||
/**
|
||||
* @return {@code true} if the object can be cached against a given leaf
|
||||
*/
|
||||
boolean isCacheable(LeafReaderContext ctx);
|
||||
|
||||
}
|
|
@ -215,9 +215,10 @@ public final class SynonymQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class SynonymScorer extends DisjunctionScorer {
|
||||
|
|
|
@ -317,9 +317,10 @@ public class TermInSetQuery extends Query implements Accountable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ 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;
|
||||
|
@ -101,8 +100,8 @@ public class TermQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,11 +18,8 @@ package org.apache.lucene.search;
|
|||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
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;
|
||||
|
@ -53,7 +50,7 @@ import org.apache.lucene.util.Bits;
|
|||
*
|
||||
* @since 2.9
|
||||
*/
|
||||
public abstract class Weight {
|
||||
public abstract class Weight implements SegmentCacheable {
|
||||
|
||||
protected final Query parentQuery;
|
||||
|
||||
|
@ -105,55 +102,6 @@ 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, List<? extends Weight> weights) {
|
||||
if (weights.size() == 0)
|
||||
return null;
|
||||
IndexReader.CacheHelper helper = weights.get(0).getCacheHelper(context);
|
||||
if (helper == null)
|
||||
return null;
|
||||
for (int i = 1; i < weights.size(); i++) {
|
||||
IndexReader.CacheHelper nextHelper = weights.get(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}
|
||||
|
|
|
@ -19,10 +19,8 @@ package org.apache.lucene.search.spans;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
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;
|
||||
|
@ -119,8 +117,9 @@ public final class SpanContainingQuery extends SpanContainQuery {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getCacheHelper(context, Arrays.asList(bigWeight, littleWeight));
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return bigWeight.isCacheable(ctx) && littleWeight.isCacheable(ctx);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
@ -231,9 +232,14 @@ public class SpanNearQuery extends SpanQuery implements Cloneable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getCacheHelper(context, subWeights);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
for (Weight w : subWeights) {
|
||||
if (w.isCacheable(ctx) == false)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -326,9 +332,10 @@ public class SpanNearQuery extends SpanQuery implements Cloneable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.apache.lucene.search.spans;
|
|||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
@ -194,9 +193,10 @@ public final class SpanNotQuery extends SpanQuery {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getCacheHelper(context, Arrays.asList(includeWeight, excludeWeight));
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return includeWeight.isCacheable(ctx) && excludeWeight.isCacheable(ctx);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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.
|
||||
|
@ -139,8 +140,12 @@ public final class SpanOrQuery extends SpanQuery {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getCacheHelper(context, subWeights);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
for (Weight w : subWeights) {
|
||||
if (w.isCacheable(ctx) == false)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -87,8 +87,8 @@ public abstract class SpanPositionCheckQuery extends SpanQuery implements Clonea
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return matchWeight.getCacheHelper(context);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return matchWeight.isCacheable(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,7 +23,6 @@ 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;
|
||||
|
@ -93,8 +92,8 @@ public class SpanTermQuery extends SpanQuery {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,10 +19,8 @@ package org.apache.lucene.search.spans;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
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;
|
||||
|
@ -120,9 +118,10 @@ public final class SpanWithinQuery extends SpanContainQuery {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getCacheHelper(context, Arrays.asList(littleWeight, bigWeight));
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return littleWeight.isCacheable(ctx) && bigWeight.isCacheable(ctx);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -21,7 +21,6 @@ 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;
|
||||
|
@ -264,8 +263,8 @@ final class JustCompileSearch {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null;
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
throw new UnsupportedOperationException(UNSUPPORTED_MSG);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -95,8 +95,8 @@ public class TestBooleanScorer extends LuceneTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null;
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -43,6 +43,7 @@ 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.DocValues;
|
||||
import org.apache.lucene.index.FilterDirectoryReader;
|
||||
import org.apache.lucene.index.FilterLeafReader;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
|
@ -362,8 +363,8 @@ public class TestLRUQueryCache extends LuceneTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -956,8 +957,8 @@ public class TestLRUQueryCache extends LuceneTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1310,8 +1311,8 @@ public class TestLRUQueryCache extends LuceneTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null;
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1377,8 +1378,8 @@ public class TestLRUQueryCache extends LuceneTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1478,8 +1479,8 @@ public class TestLRUQueryCache extends LuceneTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getDocValuesCacheHelper(field, context);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx, field);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -488,8 +488,8 @@ public class TestQueryRescorer extends LuceneTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null;
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -157,8 +157,8 @@ public class TestScorerPerf extends LuceneTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null;
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.lucene.search;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.NumericDocValuesField;
|
||||
import org.apache.lucene.index.DirectoryReader;
|
||||
import org.apache.lucene.index.DocValues;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.index.NoMergePolicy;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
|
||||
public class TestSegmentCacheables extends LuceneTestCase {
|
||||
|
||||
private static boolean isCacheable(LeafReaderContext ctx, SegmentCacheable... ss) {
|
||||
for (SegmentCacheable s : ss) {
|
||||
if (s.isCacheable(ctx) == false)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void testMultipleDocValuesDelegates() throws IOException {
|
||||
|
||||
SegmentCacheable seg = (ctx) -> true;
|
||||
SegmentCacheable non = (ctx) -> false;
|
||||
SegmentCacheable dv1 = (ctx) -> DocValues.isCacheable(ctx, "field1");
|
||||
SegmentCacheable dv2 = (ctx) -> DocValues.isCacheable(ctx, "field2");
|
||||
SegmentCacheable dv3 = (ctx) -> DocValues.isCacheable(ctx, "field3");
|
||||
SegmentCacheable dv34 = (ctx) -> DocValues.isCacheable(ctx, "field3", "field4");
|
||||
SegmentCacheable dv12 = (ctx) -> DocValues.isCacheable(ctx, "field1", "field2");
|
||||
|
||||
SegmentCacheable seg_dv1 = (ctx) -> isCacheable(ctx, seg, dv1);
|
||||
SegmentCacheable dv2_dv34 = (ctx) -> isCacheable(ctx, dv2, dv34);
|
||||
SegmentCacheable dv2_non = (ctx) -> isCacheable(ctx, dv2, non);
|
||||
|
||||
SegmentCacheable seg_dv1_dv2_dv34 = (ctx) -> isCacheable(ctx, seg_dv1, dv2_dv34);
|
||||
|
||||
SegmentCacheable dv1_dv3 = (ctx) -> isCacheable(ctx, dv1, dv3);
|
||||
SegmentCacheable dv12_dv1_dv3 = (ctx) -> isCacheable(ctx, dv12, dv1_dv3);
|
||||
|
||||
|
||||
Directory dir = newDirectory();
|
||||
IndexWriterConfig iwc = newIndexWriterConfig().setMergePolicy(NoMergePolicy.INSTANCE);
|
||||
IndexWriter w = new IndexWriter(dir, iwc);
|
||||
Document doc = new Document();
|
||||
doc.add(new NumericDocValuesField("field3", 1));
|
||||
doc.add(newTextField("text", "text", Field.Store.NO));
|
||||
w.addDocument(doc);
|
||||
w.commit();
|
||||
DirectoryReader reader = DirectoryReader.open(w);
|
||||
|
||||
LeafReaderContext ctx = reader.leaves().get(0);
|
||||
|
||||
assertTrue(seg_dv1.isCacheable(ctx));
|
||||
assertTrue(dv2_dv34.isCacheable(ctx));
|
||||
assertTrue(seg_dv1_dv2_dv34.isCacheable(ctx));
|
||||
assertFalse(dv2_non.isCacheable(ctx));
|
||||
|
||||
w.updateNumericDocValue(new Term("text", "text"), "field3", 2l);
|
||||
w.commit();
|
||||
reader.close();
|
||||
reader = DirectoryReader.open(dir);
|
||||
|
||||
// after field3 is updated, all composites referring to it should be uncacheable
|
||||
|
||||
ctx = reader.leaves().get(0);
|
||||
assertTrue(seg_dv1.isCacheable(ctx));
|
||||
assertFalse(dv34.isCacheable(ctx));
|
||||
assertFalse(dv2_dv34.isCacheable(ctx));
|
||||
assertFalse(dv1_dv3.isCacheable(ctx));
|
||||
assertFalse(seg_dv1_dv2_dv34.isCacheable(ctx));
|
||||
assertFalse(dv12_dv1_dv3.isCacheable(ctx));
|
||||
|
||||
reader.close();
|
||||
w.close();
|
||||
dir.close();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -251,8 +251,8 @@ public class TestSortRandom extends LuceneTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null;
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -126,8 +126,8 @@ public class TestUsageTrackingFilterCachingPolicy extends LuceneTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -139,6 +139,15 @@ final class ExpressionValueSource extends DoubleValuesSource {
|
|||
return needsScores;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
for (DoubleValuesSource v : variables) {
|
||||
if (v.isCacheable(ctx) == false)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
|
||||
Explanation[] explanations = new Explanation[variables.length];
|
||||
|
|
|
@ -17,10 +17,8 @@
|
|||
package org.apache.lucene.facet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -104,11 +102,14 @@ class DrillSidewaysQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
List<Weight> weights = new ArrayList<>();
|
||||
weights.add(baseWeight);
|
||||
weights.addAll(Arrays.asList(drillDowns));
|
||||
return getCacheHelper(context, weights);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
if (baseWeight.isCacheable(ctx) == false)
|
||||
return false;
|
||||
for (Weight w : drillDowns) {
|
||||
if (w.isCacheable(ctx) == false)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -173,9 +173,10 @@ public final class DoubleRange extends Range {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null; // TODO delegate to LongValuesSource?
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return valueSource.isCacheable(ctx);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -165,9 +165,10 @@ public final class LongRange extends Range {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null; // TODO delegate to LongValuesSource?
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return valueSource.isCacheable(ctx);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -741,8 +741,8 @@ public class TestDrillSideways extends FacetTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null;
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -756,6 +756,11 @@ public class TestRangeFacetCounts extends FacetTestCase {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
|
||||
return Explanation.match(docId + 1, "");
|
||||
|
|
|
@ -20,7 +20,6 @@ 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;
|
||||
|
@ -156,8 +155,8 @@ final class GlobalOrdinalsQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getDocValuesCacheHelper(joinField, context);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx, joinField);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -196,9 +196,10 @@ public class ParentChildrenBlockJoinQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null; // TODO delegate to BitSetProducer?
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false; // TODO delegate to BitSetProducer?
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ 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;
|
||||
|
@ -189,9 +188,10 @@ abstract class PointInSetIncludingScoreQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ 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;
|
||||
|
@ -142,8 +141,8 @@ class TermsIncludingScoreQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -66,25 +66,7 @@ import org.apache.lucene.index.SortedSetDocValues;
|
|||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.index.Terms;
|
||||
import org.apache.lucene.index.TermsEnum;
|
||||
import org.apache.lucene.search.BooleanClause;
|
||||
import org.apache.lucene.search.BooleanQuery;
|
||||
import org.apache.lucene.search.DocIdSetIterator;
|
||||
import org.apache.lucene.search.DocValuesFieldExistsQuery;
|
||||
import org.apache.lucene.search.Explanation;
|
||||
import org.apache.lucene.search.FilterScorer;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.lucene.search.MatchNoDocsQuery;
|
||||
import org.apache.lucene.search.MultiCollector;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.ScoreDoc;
|
||||
import org.apache.lucene.search.Scorer;
|
||||
import org.apache.lucene.search.SimpleCollector;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
import org.apache.lucene.search.TopDocs;
|
||||
import org.apache.lucene.search.TopScoreDocCollector;
|
||||
import org.apache.lucene.search.TotalHitCountCollector;
|
||||
import org.apache.lucene.search.Weight;
|
||||
import org.apache.lucene.search.*;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.util.BitSet;
|
||||
import org.apache.lucene.util.BitSetIterator;
|
||||
|
@ -564,9 +546,10 @@ public class TestJoinUtil extends LuceneTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null;
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -17,14 +17,20 @@
|
|||
package org.apache.lucene.queries;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
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.*;
|
||||
import org.apache.lucene.search.DocIdSetIterator;
|
||||
import org.apache.lucene.search.Explanation;
|
||||
import org.apache.lucene.search.FilterScorer;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.Scorer;
|
||||
import org.apache.lucene.search.TwoPhaseIterator;
|
||||
import org.apache.lucene.search.Weight;
|
||||
|
||||
/**
|
||||
* The BoostingQuery class can be used to effectively demote results that match a given query.
|
||||
|
@ -124,9 +130,10 @@ public class BoostingQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getCacheHelper(context, Arrays.asList(matchWeight, contextWeight));
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return matchWeight.isCacheable(ctx) && contextWeight.isCacheable(ctx);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -17,11 +17,9 @@
|
|||
package org.apache.lucene.queries;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
|
@ -210,11 +208,14 @@ public class CustomScoreQuery extends Query implements Cloneable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
List<Weight> weights = new ArrayList<>();
|
||||
weights.add(subQueryWeight);
|
||||
weights.addAll(Arrays.asList(valSrcWeights));
|
||||
return getCacheHelper(context, weights);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
if (subQueryWeight.isCacheable(ctx) == false)
|
||||
return false;
|
||||
for (Weight w : valSrcWeights) {
|
||||
if (w.isCacheable(ctx) == false)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -89,8 +89,8 @@ public final class BoostedQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null;
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,7 +21,6 @@ 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;
|
||||
|
@ -83,9 +82,10 @@ public final class FunctionMatchQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null; // TODO delegate to DoubleValuesSource?
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return source.isCacheable(ctx);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -75,8 +75,8 @@ public class FunctionQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null;
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,7 +21,6 @@ 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;
|
||||
|
@ -156,8 +155,8 @@ public class FunctionRangeQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null;
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,8 +139,9 @@ public final class FunctionScoreQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null; // TODO delegate to DoubleValuesSource
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return valueSource.isCacheable(ctx);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -157,6 +157,11 @@ public abstract class ValueSource {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsScores() {
|
||||
return false;
|
||||
|
@ -228,6 +233,11 @@ public abstract class ValueSource {
|
|||
return true; // be on the safe side
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
|
||||
Map context = new HashMap<>();
|
||||
|
|
|
@ -155,8 +155,8 @@ public class PayloadScoreQuery extends SpanQuery {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return innerWeight.getCacheHelper(context);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return innerWeight.isCacheable(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -131,9 +131,10 @@ public class SpanPayloadCheckQuery extends SpanQuery {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return matchWeight.getCacheHelper(context);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return matchWeight.isCacheable(ctx);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class PayloadChecker implements SpanCollector {
|
||||
|
|
|
@ -139,6 +139,11 @@ public class TestFunctionScoreQuery extends FunctionTestSetup {
|
|||
return in.needsScores();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return in.isCacheable(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 0;
|
||||
|
@ -179,6 +184,11 @@ public class TestFunctionScoreQuery extends FunctionTestSetup {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return in.isCacheable(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 0;
|
||||
|
|
|
@ -20,7 +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.DocValues;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.index.SortedNumericDocValues;
|
||||
import org.apache.lucene.search.ConstantScoreScorer;
|
||||
|
@ -142,9 +142,10 @@ final class LatLonDocValuesBoxQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getDocValuesCacheHelper(field, context);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx, field);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +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.DocValues;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.index.SortedNumericDocValues;
|
||||
import org.apache.lucene.search.ConstantScoreScorer;
|
||||
|
@ -129,9 +129,10 @@ final class LatLonDocValuesDistanceQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getDocValuesCacheHelper(field, context);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx, field);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ 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;
|
||||
|
@ -119,8 +118,8 @@ final class LatLonPointDistanceQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,8 +19,14 @@ package org.apache.lucene.document;
|
|||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.lucene.geo.GeoEncodingUtils;
|
||||
import org.apache.lucene.geo.Polygon;
|
||||
import org.apache.lucene.geo.Polygon2D;
|
||||
import org.apache.lucene.geo.Rectangle;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.FieldInfo;
|
||||
import org.apache.lucene.index.LeafReader;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.index.PointValues;
|
||||
import org.apache.lucene.index.PointValues.IntersectVisitor;
|
||||
import org.apache.lucene.index.PointValues.Relation;
|
||||
import org.apache.lucene.search.ConstantScoreScorer;
|
||||
|
@ -29,16 +35,9 @@ import org.apache.lucene.search.IndexSearcher;
|
|||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.Scorer;
|
||||
import org.apache.lucene.search.Weight;
|
||||
import org.apache.lucene.index.PointValues;
|
||||
import org.apache.lucene.index.FieldInfo;
|
||||
import org.apache.lucene.index.LeafReader;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.util.DocIdSetBuilder;
|
||||
import org.apache.lucene.util.NumericUtils;
|
||||
import org.apache.lucene.util.StringHelper;
|
||||
import org.apache.lucene.geo.GeoEncodingUtils;
|
||||
import org.apache.lucene.geo.Polygon;
|
||||
import org.apache.lucene.geo.Polygon2D;
|
||||
|
||||
import static org.apache.lucene.geo.GeoEncodingUtils.decodeLatitude;
|
||||
import static org.apache.lucene.geo.GeoEncodingUtils.decodeLongitude;
|
||||
|
@ -162,8 +161,8 @@ final class LatLonPointInPolygonQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -177,9 +177,10 @@ public final class CoveringQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null; // TODO delegate to LongValuesSource?
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return minimumNumberMatch.isCacheable(ctx);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ 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;
|
||||
|
||||
|
@ -124,9 +123,10 @@ public class DocValuesNumbersQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getDocValuesCacheHelper(field, context);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -205,9 +205,10 @@ public class DocValuesTermsQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return getDocValuesCacheHelper(field, context);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx, field);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -404,8 +404,8 @@ public class TermAutomatonQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -652,8 +652,8 @@ public class TestTermAutomatonQuery extends LuceneTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null;
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -20,11 +20,12 @@ package org.apache.lucene.spatial;
|
|||
import java.io.IOException;
|
||||
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.search.SegmentCacheable;
|
||||
|
||||
/**
|
||||
* Produces {@link ShapeValues} per-segment
|
||||
*/
|
||||
public abstract class ShapeValuesSource {
|
||||
public abstract class ShapeValuesSource implements SegmentCacheable {
|
||||
|
||||
/**
|
||||
* Get a {@link ShapeValues} instance for the given leaf reader context
|
||||
|
|
|
@ -110,6 +110,11 @@ public abstract class BBoxSimilarityValueSource extends DoubleValuesSource {
|
|||
return Explanation.noMatch(this.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return bboxValueSource.isCacheable(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsScores() {
|
||||
return false;
|
||||
|
|
|
@ -76,6 +76,12 @@ class BBoxValueSource extends ShapeValuesSource {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx,
|
||||
strategy.field_minX, strategy.field_minY, strategy.field_maxX, strategy.field_maxY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
@ -98,9 +98,10 @@ public class CompositeVerifyQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null; // TODO delegate to PredicateValueSource?
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return predicateValueSource.isCacheable(ctx);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ 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;
|
||||
|
@ -136,9 +135,10 @@ public class IntersectsRPTVerifyQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null; // TODO delegate to PredicateValueSource?
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return predicateValueSource.isCacheable(ctx);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ 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;
|
||||
|
@ -93,8 +92,8 @@ public abstract class AbstractPrefixTreeQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ 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;
|
||||
|
@ -144,9 +143,10 @@ public class SerializedDVStrategy extends SpatialStrategy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null; // TODO delegate to PredicateValueSource
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return predicateValueSource.isCacheable(ctx);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -204,6 +204,11 @@ public class SerializedDVStrategy extends SpatialStrategy {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx, fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
@ -78,6 +78,11 @@ public class CachingDoubleValueSource extends DoubleValuesSource {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return source.isCacheable(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
|
||||
return source.explain(ctx, docId, scoreExplanation);
|
||||
|
|
|
@ -80,6 +80,11 @@ public class DistanceToShapeValueSource extends DoubleValuesSource {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return shapeValueSource.isCacheable(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
@ -68,6 +68,11 @@ public class ReciprocalDoubleValuesSource extends DoubleValuesSource {
|
|||
return input.needsScores();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return input.isCacheable(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
|
||||
Explanation expl = input.explain(ctx, docId, scoreExplanation);
|
||||
|
|
|
@ -72,6 +72,11 @@ public class ShapeAreaValueSource extends DoubleValuesSource {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return shapeValueSource.isCacheable(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
@ -89,6 +89,11 @@ public class ShapeFieldCacheDistanceValueSource extends DoubleValuesSource {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.io.IOException;
|
|||
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.search.DocIdSetIterator;
|
||||
import org.apache.lucene.search.SegmentCacheable;
|
||||
import org.apache.lucene.search.TwoPhaseIterator;
|
||||
import org.apache.lucene.spatial.ShapeValues;
|
||||
import org.apache.lucene.spatial.ShapeValuesSource;
|
||||
|
@ -37,7 +38,7 @@ import org.locationtech.spatial4j.shape.Shape;
|
|||
*
|
||||
* @lucene.experimental
|
||||
*/
|
||||
public class ShapeValuesPredicate {
|
||||
public class ShapeValuesPredicate implements SegmentCacheable {
|
||||
private final ShapeValuesSource shapeValuesource;//the left hand side
|
||||
private final SpatialOperation op;
|
||||
private final Shape queryShape;//the right hand side (constant)
|
||||
|
@ -96,4 +97,9 @@ public class ShapeValuesPredicate {
|
|||
result = 31 * result + queryShape.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return shapeValuesource.isCacheable(ctx);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,6 +92,11 @@ public class DistanceValueSource extends DoubleValuesSource {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx, strategy.getFieldNameX(), strategy.getFieldNameY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
@ -290,9 +290,10 @@ public class PointVectorStrategy extends SpatialStrategy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null; // TODO delegate to DoubleValuesSource?
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return distanceSource.isCacheable(ctx);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -18,20 +18,19 @@ 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;
|
||||
import org.apache.lucene.spatial3d.geom.XYZBounds;
|
||||
import org.apache.lucene.index.PointValues;
|
||||
import org.apache.lucene.index.LeafReader;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.index.PointValues;
|
||||
import org.apache.lucene.search.ConstantScoreScorer;
|
||||
import org.apache.lucene.search.ConstantScoreWeight;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.Scorer;
|
||||
import org.apache.lucene.search.Weight;
|
||||
import org.apache.lucene.spatial3d.geom.BasePlanetObject;
|
||||
import org.apache.lucene.spatial3d.geom.GeoShape;
|
||||
import org.apache.lucene.spatial3d.geom.PlanetModel;
|
||||
import org.apache.lucene.spatial3d.geom.XYZBounds;
|
||||
import org.apache.lucene.util.DocIdSetBuilder;
|
||||
|
||||
/** Finds all previously indexed points that fall within the specified polygon.
|
||||
|
@ -106,9 +105,10 @@ final class PointInGeo3DShapeQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ 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;
|
||||
|
@ -134,8 +133,8 @@ public class CompletionWeight extends Weight {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -167,6 +167,11 @@ public class DocumentValueSourceDictionaryTest extends LuceneTestCase {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsScores() {
|
||||
return false;
|
||||
|
|
|
@ -20,7 +20,6 @@ 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;
|
||||
|
@ -74,8 +73,8 @@ public class AssertingSpanWeight extends SpanWeight {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return in.getCacheHelper(context);
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return in.isCacheable(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,7 +31,6 @@ 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;
|
||||
|
@ -481,8 +480,8 @@ public class LTRScoringQuery extends Query {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null;
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public class ModelScorer extends Scorer {
|
||||
|
|
|
@ -21,7 +21,6 @@ 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;
|
||||
|
@ -230,8 +229,8 @@ public abstract class Feature extends Query {
|
|||
throws IOException;
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null;
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.solr.legacy;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.lucene.index.DocValues;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.search.DoubleValues;
|
||||
import org.apache.lucene.search.DoubleValuesSource;
|
||||
|
@ -72,6 +73,12 @@ class BBoxValueSource extends ShapeValuesSource {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx,
|
||||
strategy.field_maxX, strategy.field_maxY, strategy.field_minX, strategy.field_minY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.solr.legacy;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.lucene.index.DocValues;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.search.DoubleValues;
|
||||
import org.apache.lucene.search.DoubleValuesSource;
|
||||
|
@ -87,6 +88,11 @@ public class DistanceValueSource extends DoubleValuesSource {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx, strategy.getFieldNameX(), strategy.getFieldNameY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
@ -488,9 +488,10 @@ public final class SolrRangeQuery extends ExtendedQueryBase implements DocSetPro
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return context.reader().getCoreCacheHelper();
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Objects;
|
|||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.LatLonDocValuesField;
|
||||
import org.apache.lucene.document.LatLonPoint;
|
||||
import org.apache.lucene.index.DocValues;
|
||||
import org.apache.lucene.index.LeafReaderContext;
|
||||
import org.apache.lucene.queries.function.ValueSource;
|
||||
import org.apache.lucene.search.DoubleValues;
|
||||
|
@ -247,6 +248,11 @@ public class LatLonPointSpatialField extends AbstractSpatialFieldType implements
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return DocValues.isCacheable(ctx, fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "distSort(" + fieldName + ", " + queryPoint + ", mult:" + multiplier + ")";
|
||||
|
|
|
@ -333,8 +333,8 @@ class SpatialDistanceQuery extends ExtendedQueryBase implements PostFilter {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
|
||||
return null;
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -187,6 +187,11 @@ public class RptWithGeometrySpatialField extends AbstractSpatialFieldType<Compos
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCacheable(LeafReaderContext ctx) {
|
||||
return targetValueSource.isCacheable(ctx);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final String CACHE_KEY_PREFIX = "perSegSpatialFieldCache_";//then field name
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue