LUCENE-8042: Add SegmentCachable interface

This commit is contained in:
Alan Woodward 2017-11-07 09:53:38 +00:00
parent 281e84b988
commit 276e317e94
107 changed files with 613 additions and 343 deletions

View File

@ -21,7 +21,6 @@ import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PointValues; import org.apache.lucene.index.PointValues;
@ -359,9 +358,10 @@ abstract class RangeFieldQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
}; };
} }

View File

@ -94,6 +94,12 @@ abstract class SortedNumericDocValuesRangeQuery extends Query {
@Override @Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException { public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
return new ConstantScoreWeight(this, boost) { return new ConstantScoreWeight(this, boost) {
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return DocValues.isCacheable(ctx, field);
}
@Override @Override
public Scorer scorer(LeafReaderContext context) throws IOException { public Scorer scorer(LeafReaderContext context) throws IOException {
SortedNumericDocValues values = getValues(context.reader(), field); SortedNumericDocValues values = getValues(context.reader(), field);
@ -139,10 +145,6 @@ abstract class SortedNumericDocValuesRangeQuery extends Query {
return new ConstantScoreScorer(this, score(), iterator); return new ConstantScoreScorer(this, score(), iterator);
} }
@Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) {
return getDocValuesCacheHelper(field, context);
}
}; };
} }

View File

@ -183,9 +183,10 @@ abstract class SortedSetDocValuesRangeQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return getDocValuesCacheHelper(field, context); return DocValues.isCacheable(ctx, field);
} }
}; };
} }

View File

@ -437,4 +437,16 @@ public final class DocValues {
} }
return dv; 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;
}
} }

View File

@ -26,7 +26,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanClause.Occur;
@ -301,8 +300,12 @@ final class BooleanWeight extends Weight {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return getCacheHelper(context, weights); for (Weight w : weights) {
if (w.isCacheable(ctx) == false)
return false;
}
return true;
} }
@Override @Override

View File

@ -168,8 +168,8 @@ public final class ConstantScoreQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return innerWeight.getCacheHelper(context); return innerWeight.isCacheable(ctx);
} }
}; };

View File

@ -138,8 +138,12 @@ public final class DisjunctionMaxQuery extends Query implements Iterable<Query>
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return getCacheHelper(context, weights); for (Weight w : weights) {
if (w.isCacheable(ctx) == false)
return false;
}
return true;
} }
/** Explain the score we computed for doc */ /** Explain the score we computed for doc */

View File

@ -20,10 +20,10 @@ package org.apache.lucene.search;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.DocValuesType; import org.apache.lucene.index.DocValuesType;
import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
@ -100,9 +100,10 @@ public final class DocValuesFieldExistsQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return getDocValuesCacheHelper(field, context); return DocValues.isCacheable(ctx, field);
} }
}; };
} }
} }

View File

@ -160,9 +160,10 @@ public final class DocValuesRewriteMethod extends MultiTermQuery.RewriteMethod {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return getDocValuesCacheHelper(query.field, context); return DocValues.isCacheable(ctx, query.field);
} }
}; };
} }
} }

View File

@ -41,7 +41,7 @@ import org.apache.lucene.index.NumericDocValues;
* {@link #fromScorer(Scorer)} and passing the resulting DoubleValues to {@link #getValues(LeafReaderContext, DoubleValues)}. * {@link #fromScorer(Scorer)} and passing the resulting DoubleValues to {@link #getValues(LeafReaderContext, DoubleValues)}.
* The scores can then be accessed using the {@link #SCORES} DoubleValuesSource. * 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 * Returns a {@link DoubleValues} instance for the passed-in LeafReaderContext and scores
@ -104,22 +104,27 @@ public abstract class DoubleValuesSource {
} }
@Override @Override
public LongValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException { public LongValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException {
DoubleValues in = inner.getValues(ctx, scores); DoubleValues in = inner.getValues(ctx, scores);
return new LongValues() { return new LongValues() {
@Override @Override
public long longValue() throws IOException { public long longValue() throws IOException {
return (long) in.doubleValue(); return (long) in.doubleValue();
} }
@Override @Override
public boolean advanceExact(int doc) throws IOException { public boolean advanceExact(int doc) throws IOException {
return in.advanceExact(doc); return in.advanceExact(doc);
} }
}; };
} }
@Override @Override
public boolean isCacheable(LeafReaderContext ctx) {
return inner.isCacheable(ctx);
}
@Override
public boolean needsScores() { public boolean needsScores() {
return inner.needsScores(); return inner.needsScores();
} }
@ -200,6 +205,11 @@ public abstract class DoubleValuesSource {
return true; return true;
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return false;
}
@Override @Override
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) { public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) {
return scoreExplanation; return scoreExplanation;
@ -256,6 +266,11 @@ public abstract class DoubleValuesSource {
return false; return false;
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return true;
}
@Override @Override
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) { public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) {
return Explanation.match((float) value, "constant(" + value + ")"); return Explanation.match((float) value, "constant(" + value + ")");
@ -348,6 +363,11 @@ public abstract class DoubleValuesSource {
return false; return false;
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return DocValues.isCacheable(ctx, field);
}
@Override @Override
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
DoubleValues values = getValues(ctx, null); DoubleValues values = getValues(ctx, null);

View File

@ -19,7 +19,6 @@ package org.apache.lucene.search;
import java.io.IOException; import java.io.IOException;
import java.util.Set; import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
@ -57,8 +56,8 @@ public abstract class FilterWeight extends Weight {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return in.getCacheHelper(context); return in.isCacheable(ctx);
} }
@Override @Override

View File

@ -171,11 +171,12 @@ public final class IndexOrDocValuesQuery extends Query {
} }
@Override @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 // Both index and dv query should return the same values, so we can use
// the index query's cachehelper here // the index query's cachehelper here
return indexWeight.getCacheHelper(context); return indexWeight.isCacheable(ctx);
} }
}; };
} }

View File

@ -722,8 +722,7 @@ public class LRUQueryCache implements QueryCache, Accountable {
policy.onUse(getQuery()); policy.onUse(getQuery());
} }
final IndexReader.CacheHelper cacheHelper = in.getCacheHelper(context); if (in.isCacheable(context) == false) {
if (cacheHelper == null) {
// this segment is not suitable for caching // this segment is not suitable for caching
return in.scorerSupplier(context); return in.scorerSupplier(context);
} }
@ -739,6 +738,11 @@ public class LRUQueryCache implements QueryCache, Accountable {
return in.scorerSupplier(context); 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; DocIdSet docIdSet;
try { try {
docIdSet = get(in.getQuery(), context, cacheHelper); docIdSet = get(in.getQuery(), context, cacheHelper);
@ -788,8 +792,8 @@ public class LRUQueryCache implements QueryCache, Accountable {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return in.getCacheHelper(context); return in.isCacheable(ctx);
} }
@Override @Override
@ -798,8 +802,7 @@ public class LRUQueryCache implements QueryCache, Accountable {
policy.onUse(getQuery()); policy.onUse(getQuery());
} }
final IndexReader.CacheHelper cacheHelper = in.getCacheHelper(context); if (in.isCacheable(context) == false) {
if (cacheHelper == null) {
// this segment is not suitable for caching // this segment is not suitable for caching
return in.bulkScorer(context); return in.bulkScorer(context);
} }
@ -815,6 +818,11 @@ public class LRUQueryCache implements QueryCache, Accountable {
return in.bulkScorer(context); 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; DocIdSet docIdSet;
try { try {
docIdSet = get(in.getQuery(), context, cacheHelper); docIdSet = get(in.getQuery(), context, cacheHelper);

View File

@ -37,7 +37,7 @@ import org.apache.lucene.index.NumericDocValues;
* use {@link DoubleValuesSource#fromFloatField(String)} or {@link DoubleValuesSource#fromDoubleField(String)} * use {@link DoubleValuesSource#fromFloatField(String)} or {@link DoubleValuesSource#fromDoubleField(String)}
* and then call {@link DoubleValuesSource#toLongValuesSource()}. * 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 * 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 @Override
public boolean needsScores() { public boolean needsScores() {
return false; return false;
@ -170,6 +175,11 @@ public abstract class LongValuesSource {
return toLongValues(values); return toLongValues(values);
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return DocValues.isCacheable(ctx, field);
}
@Override @Override
public boolean needsScores() { public boolean needsScores() {
return false; return false;

View File

@ -19,7 +19,6 @@ package org.apache.lucene.search;
import java.io.IOException; import java.io.IOException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.util.Bits; import org.apache.lucene.util.Bits;
@ -42,8 +41,8 @@ public final class MatchAllDocsQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
@Override @Override

View File

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

View File

@ -292,8 +292,8 @@ public class MultiPhraseQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
@Override @Override

View File

@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
@ -214,9 +213,10 @@ final class MultiTermQueryConstantScoreWrapper<Q extends MultiTermQuery> extends
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
}; };
} }
} }

View File

@ -23,7 +23,6 @@ import java.util.Objects;
import org.apache.lucene.document.StringField; import org.apache.lucene.document.StringField;
import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
@ -78,8 +77,8 @@ public final class NormsFieldExistsQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
}; };
} }

View File

@ -443,8 +443,8 @@ public class PhraseQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
// only called from assert // only called from assert

View File

@ -22,15 +22,15 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.apache.lucene.document.IntPoint; import org.apache.lucene.document.IntPoint;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext; 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.IntersectVisitor;
import org.apache.lucene.index.PointValues.Relation; 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;
import org.apache.lucene.index.PrefixCodedTerms.TermIterator;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder; import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.BytesRefIterator; import org.apache.lucene.util.BytesRefIterator;
@ -153,9 +153,10 @@ public abstract class PointInSetQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
}; };
} }

View File

@ -20,13 +20,12 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; 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;
import org.apache.lucene.index.PointValues.IntersectVisitor; import org.apache.lucene.index.PointValues.IntersectVisitor;
import org.apache.lucene.index.PointValues.Relation; 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.BitSetIterator;
import org.apache.lucene.util.DocIdSetBuilder; import org.apache.lucene.util.DocIdSetBuilder;
import org.apache.lucene.util.FixedBitSet; import org.apache.lucene.util.FixedBitSet;
@ -324,9 +323,10 @@ public abstract class PointRangeQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
}; };
} }

View File

@ -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);
}

View File

@ -215,9 +215,10 @@ public final class SynonymQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
} }
static class SynonymScorer extends DisjunctionScorer { static class SynonymScorer extends DisjunctionScorer {

View File

@ -317,9 +317,10 @@ public class TermInSetQuery extends Query implements Accountable {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
}; };
} }
} }

View File

@ -21,7 +21,6 @@ import java.io.IOException;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexReaderContext; import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
@ -101,8 +100,8 @@ public class TermQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
/** /**

View File

@ -18,11 +18,8 @@ package org.apache.lucene.search;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.Set; 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.IndexReaderContext;
import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
@ -53,7 +50,7 @@ import org.apache.lucene.util.Bits;
* *
* @since 2.9 * @since 2.9
*/ */
public abstract class Weight { public abstract class Weight implements SegmentCacheable {
protected final Query parentQuery; protected final Query parentQuery;
@ -105,55 +102,6 @@ public abstract class Weight {
*/ */
public abstract Scorer scorer(LeafReaderContext context) throws IOException; 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. * Optional method.
* Get a {@link ScorerSupplier}, which allows to know the cost of the {@link Scorer} * Get a {@link ScorerSupplier}, which allows to know the cost of the {@link Scorer}

View File

@ -19,10 +19,8 @@ package org.apache.lucene.search.spans;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map; import java.util.Map;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext; import org.apache.lucene.index.TermContext;
@ -119,8 +117,9 @@ public final class SpanContainingQuery extends SpanContainQuery {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return getCacheHelper(context, Arrays.asList(bigWeight, littleWeight)); return bigWeight.isCacheable(ctx) && littleWeight.isCacheable(ctx);
} }
} }
} }

View File

@ -33,6 +33,7 @@ import org.apache.lucene.index.TermContext;
import org.apache.lucene.index.Terms; import org.apache.lucene.index.Terms;
import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query; 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 /** Matches spans which are near one another. One can specify <i>slop</i>, the
* maximum number of intervening unmatched positions, as well as whether * maximum number of intervening unmatched positions, as well as whether
@ -231,9 +232,14 @@ public class SpanNearQuery extends SpanQuery implements Cloneable {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return getCacheHelper(context, subWeights); for (Weight w : subWeights) {
if (w.isCacheable(ctx) == false)
return false;
}
return true;
} }
} }
@Override @Override
@ -326,9 +332,10 @@ public class SpanNearQuery extends SpanQuery implements Cloneable {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
} }
@Override @Override

View File

@ -18,7 +18,6 @@ package org.apache.lucene.search.spans;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
@ -194,9 +193,10 @@ public final class SpanNotQuery extends SpanQuery {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return getCacheHelper(context, Arrays.asList(includeWeight, excludeWeight)); return includeWeight.isCacheable(ctx) && excludeWeight.isCacheable(ctx);
} }
} }
@Override @Override

View File

@ -34,6 +34,7 @@ import org.apache.lucene.search.DisjunctionDISIApproximation;
import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.apache.lucene.search.TwoPhaseIterator; import org.apache.lucene.search.TwoPhaseIterator;
import org.apache.lucene.search.Weight;
/** Matches the union of its clauses. /** Matches the union of its clauses.
@ -139,8 +140,12 @@ public final class SpanOrQuery extends SpanQuery {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return getCacheHelper(context, subWeights); for (Weight w : subWeights) {
if (w.isCacheable(ctx) == false)
return false;
}
return true;
} }
@Override @Override

View File

@ -87,8 +87,8 @@ public abstract class SpanPositionCheckQuery extends SpanQuery implements Clonea
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return matchWeight.getCacheHelper(context); return matchWeight.isCacheable(ctx);
} }
@Override @Override

View File

@ -23,7 +23,6 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexReaderContext; import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.PostingsEnum;
@ -93,8 +92,8 @@ public class SpanTermQuery extends SpanQuery {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
@Override @Override

View File

@ -19,10 +19,8 @@ package org.apache.lucene.search.spans;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map; import java.util.Map;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext; import org.apache.lucene.index.TermContext;
@ -120,9 +118,10 @@ public final class SpanWithinQuery extends SpanContainQuery {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return getCacheHelper(context, Arrays.asList(littleWeight, bigWeight)); return littleWeight.isCacheable(ctx) && bigWeight.isCacheable(ctx);
} }
} }
} }

View File

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

View File

@ -95,8 +95,8 @@ public class TestBooleanScorer extends LuceneTestCase {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; return false;
} }
@Override @Override

View File

@ -43,6 +43,7 @@ import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.StringField; import org.apache.lucene.document.StringField;
import org.apache.lucene.document.TextField; import org.apache.lucene.document.TextField;
import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.FilterDirectoryReader; import org.apache.lucene.index.FilterDirectoryReader;
import org.apache.lucene.index.FilterLeafReader; import org.apache.lucene.index.FilterLeafReader;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
@ -362,8 +363,8 @@ public class TestLRUQueryCache extends LuceneTestCase {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
}; };
} }
@ -956,8 +957,8 @@ public class TestLRUQueryCache extends LuceneTestCase {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
}; };
} }
@ -1310,8 +1311,8 @@ public class TestLRUQueryCache extends LuceneTestCase {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; return false;
} }
}; };
} }
@ -1377,8 +1378,8 @@ public class TestLRUQueryCache extends LuceneTestCase {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
@Override @Override
@ -1478,8 +1479,8 @@ public class TestLRUQueryCache extends LuceneTestCase {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return getDocValuesCacheHelper(field, context); return DocValues.isCacheable(ctx, field);
} }
}; };

View File

@ -488,8 +488,8 @@ public class TestQueryRescorer extends LuceneTestCase {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; return false;
} }
@Override @Override

View File

@ -157,8 +157,8 @@ public class TestScorerPerf extends LuceneTestCase {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; return false;
} }
}; };
} }

View File

@ -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();
}
}

View File

@ -251,8 +251,8 @@ public class TestSortRandom extends LuceneTestCase {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; return false;
} }
}; };
} }

View File

@ -126,8 +126,8 @@ public class TestUsageTrackingFilterCachingPolicy extends LuceneTestCase {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
}; };
} }

View File

@ -139,6 +139,15 @@ final class ExpressionValueSource extends DoubleValuesSource {
return needsScores; return needsScores;
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
for (DoubleValuesSource v : variables) {
if (v.isCacheable(ctx) == false)
return false;
}
return true;
}
@Override @Override
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
Explanation[] explanations = new Explanation[variables.length]; Explanation[] explanations = new Explanation[variables.length];

View File

@ -17,10 +17,8 @@
package org.apache.lucene.facet; package org.apache.lucene.facet;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
@ -104,11 +102,14 @@ class DrillSidewaysQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
List<Weight> weights = new ArrayList<>(); if (baseWeight.isCacheable(ctx) == false)
weights.add(baseWeight); return false;
weights.addAll(Arrays.asList(drillDowns)); for (Weight w : drillDowns) {
return getCacheHelper(context, weights); if (w.isCacheable(ctx) == false)
return false;
}
return true;
} }
@Override @Override

View File

@ -173,9 +173,10 @@ public final class DoubleRange extends Range {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; // TODO delegate to LongValuesSource? return valueSource.isCacheable(ctx);
} }
}; };
} }

View File

@ -165,9 +165,10 @@ public final class LongRange extends Range {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; // TODO delegate to LongValuesSource? return valueSource.isCacheable(ctx);
} }
}; };
} }

View File

@ -741,8 +741,8 @@ public class TestDrillSideways extends FacetTestCase {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; return false;
} }
}; };

View File

@ -756,6 +756,11 @@ public class TestRangeFacetCounts extends FacetTestCase {
return false; return false;
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return false;
}
@Override @Override
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
return Explanation.match(docId + 1, ""); return Explanation.match(docId + 1, "");

View File

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

View File

@ -196,9 +196,10 @@ public class ParentChildrenBlockJoinQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; // TODO delegate to BitSetProducer? return false; // TODO delegate to BitSetProducer?
} }
}; };
} }
} }

View File

@ -29,7 +29,6 @@ import org.apache.lucene.document.FloatPoint;
import org.apache.lucene.document.IntPoint; import org.apache.lucene.document.IntPoint;
import org.apache.lucene.document.LongPoint; import org.apache.lucene.document.LongPoint;
import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PointValues; import org.apache.lucene.index.PointValues;
@ -189,9 +188,10 @@ abstract class PointInSetIncludingScoreQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
}; };
} }

View File

@ -21,7 +21,6 @@ import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
@ -142,8 +141,8 @@ class TermsIncludingScoreQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
}; };

View File

@ -66,25 +66,7 @@ import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
import org.apache.lucene.index.Terms; import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum; import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.*;
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.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BitSet; import org.apache.lucene.util.BitSet;
import org.apache.lucene.util.BitSetIterator; import org.apache.lucene.util.BitSetIterator;
@ -564,9 +546,10 @@ public class TestJoinUtil extends LuceneTestCase {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; return false;
} }
}; };
} }

View File

@ -17,14 +17,20 @@
package org.apache.lucene.queries; package org.apache.lucene.queries;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term; 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. * 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 @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return getCacheHelper(context, Arrays.asList(matchWeight, contextWeight)); return matchWeight.isCacheable(ctx) && contextWeight.isCacheable(ctx);
} }
}; };
} }

View File

@ -17,11 +17,9 @@
package org.apache.lucene.queries; package org.apache.lucene.queries;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
@ -210,11 +208,14 @@ public class CustomScoreQuery extends Query implements Cloneable {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
List<Weight> weights = new ArrayList<>(); if (subQueryWeight.isCacheable(ctx) == false)
weights.add(subQueryWeight); return false;
weights.addAll(Arrays.asList(valSrcWeights)); for (Weight w : valSrcWeights) {
return getCacheHelper(context, weights); if (w.isCacheable(ctx) == false)
return false;
}
return true;
} }
@Override @Override

View File

@ -89,8 +89,8 @@ public final class BoostedQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; return false;
} }
@Override @Override

View File

@ -21,7 +21,6 @@ import java.io.IOException;
import java.util.Objects; import java.util.Objects;
import java.util.function.DoublePredicate; import java.util.function.DoublePredicate;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.ConstantScoreScorer; import org.apache.lucene.search.ConstantScoreScorer;
import org.apache.lucene.search.ConstantScoreWeight; import org.apache.lucene.search.ConstantScoreWeight;
@ -83,9 +82,10 @@ public final class FunctionMatchQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; // TODO delegate to DoubleValuesSource? return source.isCacheable(ctx);
} }
}; };
} }

View File

@ -75,8 +75,8 @@ public class FunctionQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; return false;
} }
@Override @Override

View File

@ -21,7 +21,6 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
import org.apache.lucene.search.Explanation; import org.apache.lucene.search.Explanation;
@ -156,8 +155,8 @@ public class FunctionRangeQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; return false;
} }
} }
} }

View File

@ -139,8 +139,9 @@ public final class FunctionScoreQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; // TODO delegate to DoubleValuesSource return valueSource.isCacheable(ctx);
} }
} }
} }

View File

@ -157,6 +157,11 @@ public abstract class ValueSource {
}; };
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return false;
}
@Override @Override
public boolean needsScores() { public boolean needsScores() {
return false; return false;
@ -228,6 +233,11 @@ public abstract class ValueSource {
return true; // be on the safe side return true; // be on the safe side
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return false;
}
@Override @Override
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
Map context = new HashMap<>(); Map context = new HashMap<>();

View File

@ -155,8 +155,8 @@ public class PayloadScoreQuery extends SpanQuery {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return innerWeight.getCacheHelper(context); return innerWeight.isCacheable(ctx);
} }
@Override @Override

View File

@ -131,9 +131,10 @@ public class SpanPayloadCheckQuery extends SpanQuery {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return matchWeight.getCacheHelper(context); return matchWeight.isCacheable(ctx);
} }
} }
private class PayloadChecker implements SpanCollector { private class PayloadChecker implements SpanCollector {

View File

@ -139,6 +139,11 @@ public class TestFunctionScoreQuery extends FunctionTestSetup {
return in.needsScores(); return in.needsScores();
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return in.isCacheable(ctx);
}
@Override @Override
public int hashCode() { public int hashCode() {
return 0; return 0;
@ -179,6 +184,11 @@ public class TestFunctionScoreQuery extends FunctionTestSetup {
return true; return true;
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return in.isCacheable(ctx);
}
@Override @Override
public int hashCode() { public int hashCode() {
return 0; return 0;

View File

@ -20,7 +20,7 @@ import java.io.IOException;
import org.apache.lucene.geo.GeoEncodingUtils; import org.apache.lucene.geo.GeoEncodingUtils;
import org.apache.lucene.geo.GeoUtils; 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.LeafReaderContext;
import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.search.ConstantScoreScorer; import org.apache.lucene.search.ConstantScoreScorer;
@ -142,9 +142,10 @@ final class LatLonDocValuesBoxQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return getDocValuesCacheHelper(field, context); return DocValues.isCacheable(ctx, field);
} }
}; };
} }

View File

@ -20,7 +20,7 @@ import java.io.IOException;
import org.apache.lucene.geo.GeoEncodingUtils; import org.apache.lucene.geo.GeoEncodingUtils;
import org.apache.lucene.geo.GeoUtils; 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.LeafReaderContext;
import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.search.ConstantScoreScorer; import org.apache.lucene.search.ConstantScoreScorer;
@ -129,9 +129,10 @@ final class LatLonDocValuesDistanceQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return getDocValuesCacheHelper(field, context); return DocValues.isCacheable(ctx, field);
} }
}; };
} }

View File

@ -22,7 +22,6 @@ import org.apache.lucene.geo.GeoEncodingUtils;
import org.apache.lucene.geo.GeoUtils; import org.apache.lucene.geo.GeoUtils;
import org.apache.lucene.geo.Rectangle; import org.apache.lucene.geo.Rectangle;
import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PointValues; import org.apache.lucene.index.PointValues;
@ -119,8 +118,8 @@ final class LatLonPointDistanceQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
@Override @Override

View File

@ -19,8 +19,14 @@ package org.apache.lucene.document;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; 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.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.IntersectVisitor;
import org.apache.lucene.index.PointValues.Relation; import org.apache.lucene.index.PointValues.Relation;
import org.apache.lucene.search.ConstantScoreScorer; 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.Query;
import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Weight; 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.DocIdSetBuilder;
import org.apache.lucene.util.NumericUtils; import org.apache.lucene.util.NumericUtils;
import org.apache.lucene.util.StringHelper; 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.decodeLatitude;
import static org.apache.lucene.geo.GeoEncodingUtils.decodeLongitude; import static org.apache.lucene.geo.GeoEncodingUtils.decodeLongitude;
@ -162,8 +161,8 @@ final class LatLonPointInPolygonQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
}; };
} }

View File

@ -177,9 +177,10 @@ public final class CoveringQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; // TODO delegate to LongValuesSource? return minimumNumberMatch.isCacheable(ctx);
} }
} }
} }

View File

@ -26,7 +26,6 @@ import java.util.Set;
import org.apache.lucene.document.NumericDocValuesField; import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.SortedNumericDocValuesField; import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.index.DocValues; import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedNumericDocValues;
@ -124,9 +123,10 @@ public class DocValuesNumbersQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return getDocValuesCacheHelper(field, context); return true;
} }
}; };
} }
} }

View File

@ -205,9 +205,10 @@ public class DocValuesTermsQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return getDocValuesCacheHelper(field, context); return DocValues.isCacheable(ctx, field);
} }
}; };
} }

View File

@ -404,8 +404,8 @@ public class TermAutomatonQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
@Override @Override

View File

@ -652,8 +652,8 @@ public class TestTermAutomatonQuery extends LuceneTestCase {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; return false;
} }
}; };
} }

View File

@ -20,11 +20,12 @@ package org.apache.lucene.spatial;
import java.io.IOException; import java.io.IOException;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.SegmentCacheable;
/** /**
* Produces {@link ShapeValues} per-segment * 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 * Get a {@link ShapeValues} instance for the given leaf reader context

View File

@ -110,6 +110,11 @@ public abstract class BBoxSimilarityValueSource extends DoubleValuesSource {
return Explanation.noMatch(this.toString()); return Explanation.noMatch(this.toString());
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return bboxValueSource.isCacheable(ctx);
}
@Override @Override
public boolean needsScores() { public boolean needsScores() {
return false; return false;

View File

@ -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 @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@ -98,9 +98,10 @@ public class CompositeVerifyQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; // TODO delegate to PredicateValueSource? return predicateValueSource.isCacheable(ctx);
} }
}; };
} }
} }

View File

@ -18,7 +18,6 @@ package org.apache.lucene.spatial.composite;
import java.io.IOException; import java.io.IOException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.ConstantScoreScorer; import org.apache.lucene.search.ConstantScoreScorer;
import org.apache.lucene.search.ConstantScoreWeight; import org.apache.lucene.search.ConstantScoreWeight;
@ -136,9 +135,10 @@ public class IntersectsRPTVerifyQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; // TODO delegate to PredicateValueSource? return predicateValueSource.isCacheable(ctx);
} }
}; };
} }

View File

@ -18,7 +18,6 @@ package org.apache.lucene.spatial.prefix;
import java.io.IOException; import java.io.IOException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PostingsEnum; import org.apache.lucene.index.PostingsEnum;
@ -93,8 +92,8 @@ public abstract class AbstractPrefixTreeQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
}; };
} }

View File

@ -27,7 +27,6 @@ import org.apache.lucene.document.BinaryDocValuesField;
import org.apache.lucene.document.Field; import org.apache.lucene.document.Field;
import org.apache.lucene.index.BinaryDocValues; import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.DocValues; import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.ConstantScoreScorer; import org.apache.lucene.search.ConstantScoreScorer;
import org.apache.lucene.search.ConstantScoreWeight; import org.apache.lucene.search.ConstantScoreWeight;
@ -144,9 +143,10 @@ public class SerializedDVStrategy extends SpatialStrategy {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; // TODO delegate to PredicateValueSource 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 @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@ -78,6 +78,11 @@ public class CachingDoubleValueSource extends DoubleValuesSource {
return false; return false;
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return source.isCacheable(ctx);
}
@Override @Override
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
return source.explain(ctx, docId, scoreExplanation); return source.explain(ctx, docId, scoreExplanation);

View File

@ -80,6 +80,11 @@ public class DistanceToShapeValueSource extends DoubleValuesSource {
return false; return false;
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return shapeValueSource.isCacheable(ctx);
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@ -68,6 +68,11 @@ public class ReciprocalDoubleValuesSource extends DoubleValuesSource {
return input.needsScores(); return input.needsScores();
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return input.isCacheable(ctx);
}
@Override @Override
public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException { public Explanation explain(LeafReaderContext ctx, int docId, Explanation scoreExplanation) throws IOException {
Explanation expl = input.explain(ctx, docId, scoreExplanation); Explanation expl = input.explain(ctx, docId, scoreExplanation);

View File

@ -72,6 +72,11 @@ public class ShapeAreaValueSource extends DoubleValuesSource {
return false; return false;
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return shapeValueSource.isCacheable(ctx);
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@ -89,6 +89,11 @@ public class ShapeFieldCacheDistanceValueSource extends DoubleValuesSource {
return false; return false;
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return true;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@ -20,6 +20,7 @@ import java.io.IOException;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.SegmentCacheable;
import org.apache.lucene.search.TwoPhaseIterator; import org.apache.lucene.search.TwoPhaseIterator;
import org.apache.lucene.spatial.ShapeValues; import org.apache.lucene.spatial.ShapeValues;
import org.apache.lucene.spatial.ShapeValuesSource; import org.apache.lucene.spatial.ShapeValuesSource;
@ -37,7 +38,7 @@ import org.locationtech.spatial4j.shape.Shape;
* *
* @lucene.experimental * @lucene.experimental
*/ */
public class ShapeValuesPredicate { public class ShapeValuesPredicate implements SegmentCacheable {
private final ShapeValuesSource shapeValuesource;//the left hand side private final ShapeValuesSource shapeValuesource;//the left hand side
private final SpatialOperation op; private final SpatialOperation op;
private final Shape queryShape;//the right hand side (constant) private final Shape queryShape;//the right hand side (constant)
@ -96,4 +97,9 @@ public class ShapeValuesPredicate {
result = 31 * result + queryShape.hashCode(); result = 31 * result + queryShape.hashCode();
return result; return result;
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return shapeValuesource.isCacheable(ctx);
}
} }

View File

@ -92,6 +92,11 @@ public class DistanceValueSource extends DoubleValuesSource {
return false; return false;
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return DocValues.isCacheable(ctx, strategy.getFieldNameX(), strategy.getFieldNameY());
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@ -290,9 +290,10 @@ public class PointVectorStrategy extends SpatialStrategy {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; // TODO delegate to DoubleValuesSource? return distanceSource.isCacheable(ctx);
} }
}; };
} }

View File

@ -18,20 +18,19 @@ package org.apache.lucene.spatial3d;
import java.io.IOException; 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.LeafReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.PointValues;
import org.apache.lucene.search.ConstantScoreScorer; import org.apache.lucene.search.ConstantScoreScorer;
import org.apache.lucene.search.ConstantScoreWeight; import org.apache.lucene.search.ConstantScoreWeight;
import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Weight; 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; import org.apache.lucene.util.DocIdSetBuilder;
/** Finds all previously indexed points that fall within the specified polygon. /** Finds all previously indexed points that fall within the specified polygon.
@ -106,9 +105,10 @@ final class PointInGeo3DShapeQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
}; };
} }

View File

@ -19,7 +19,6 @@ package org.apache.lucene.search.suggest.document;
import java.io.IOException; import java.io.IOException;
import java.util.Set; import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
@ -134,8 +133,8 @@ public class CompletionWeight extends Weight {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
@Override @Override

View File

@ -167,6 +167,11 @@ public class DocumentValueSourceDictionaryTest extends LuceneTestCase {
}; };
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return false;
}
@Override @Override
public boolean needsScores() { public boolean needsScores() {
return false; return false;

View File

@ -20,7 +20,6 @@ import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext; import org.apache.lucene.index.TermContext;
@ -74,8 +73,8 @@ public class AssertingSpanWeight extends SpanWeight {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return in.getCacheHelper(context); return in.isCacheable(ctx);
} }
@Override @Override

View File

@ -31,7 +31,6 @@ import java.util.concurrent.FutureTask;
import java.util.concurrent.RunnableFuture; import java.util.concurrent.RunnableFuture;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
import org.apache.lucene.search.DisiPriorityQueue; import org.apache.lucene.search.DisiPriorityQueue;
@ -481,8 +480,8 @@ public class LTRScoringQuery extends Query {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; return false;
} }
public class ModelScorer extends Scorer { public class ModelScorer extends Scorer {

View File

@ -21,7 +21,6 @@ import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.DocIdSetIterator;
@ -230,8 +229,8 @@ public abstract class Feature extends Query {
throws IOException; throws IOException;
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; return false;
} }
@Override @Override

View File

@ -18,6 +18,7 @@ package org.apache.solr.legacy;
import java.io.IOException; import java.io.IOException;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.DoubleValues; import org.apache.lucene.search.DoubleValues;
import org.apache.lucene.search.DoubleValuesSource; 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 @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@ -18,6 +18,7 @@ package org.apache.solr.legacy;
import java.io.IOException; import java.io.IOException;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.DoubleValues; import org.apache.lucene.search.DoubleValues;
import org.apache.lucene.search.DoubleValuesSource; import org.apache.lucene.search.DoubleValuesSource;
@ -87,6 +88,11 @@ public class DistanceValueSource extends DoubleValuesSource {
return false; return false;
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return DocValues.isCacheable(ctx, strategy.getFieldNameX(), strategy.getFieldNameY());
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@ -488,9 +488,10 @@ public final class SolrRangeQuery extends ExtendedQueryBase implements DocSetPro
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return context.reader().getCoreCacheHelper(); return true;
} }
} }
} }

View File

@ -23,6 +23,7 @@ import java.util.Objects;
import org.apache.lucene.document.Field; import org.apache.lucene.document.Field;
import org.apache.lucene.document.LatLonDocValuesField; import org.apache.lucene.document.LatLonDocValuesField;
import org.apache.lucene.document.LatLonPoint; import org.apache.lucene.document.LatLonPoint;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.search.DoubleValues; import org.apache.lucene.search.DoubleValues;
@ -247,6 +248,11 @@ public class LatLonPointSpatialField extends AbstractSpatialFieldType implements
return false; return false;
} }
@Override
public boolean isCacheable(LeafReaderContext ctx) {
return DocValues.isCacheable(ctx, fieldName);
}
@Override @Override
public String toString() { public String toString() {
return "distSort(" + fieldName + ", " + queryPoint + ", mult:" + multiplier + ")"; return "distSort(" + fieldName + ", " + queryPoint + ", mult:" + multiplier + ")";

View File

@ -333,8 +333,8 @@ class SpatialDistanceQuery extends ExtendedQueryBase implements PostFilter {
} }
@Override @Override
public IndexReader.CacheHelper getCacheHelper(LeafReaderContext context) { public boolean isCacheable(LeafReaderContext ctx) {
return null; return false;
} }
@Override @Override

View File

@ -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 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