mirror of https://github.com/apache/lucene.git
LUCENE-6838: Added getters for IndexSearcher's query cache and caching policy.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1708832 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
15016f17e8
commit
70a4825d96
|
@ -88,6 +88,9 @@ New Features
|
||||||
fast, very accurate query to find all indexed points within an
|
fast, very accurate query to find all indexed points within an
|
||||||
earth-surface shape (Karl Wright, Mike McCandless)
|
earth-surface shape (Karl Wright, Mike McCandless)
|
||||||
|
|
||||||
|
* LUCENE-6838: Added IndexSearcher#getQueryCache and #getQueryCachingPolicy.
|
||||||
|
(Adrien Grand)
|
||||||
|
|
||||||
API Changes
|
API Changes
|
||||||
|
|
||||||
* LUCENE-6590: Query.setBoost(), Query.getBoost() and Query.clone() are gone.
|
* LUCENE-6590: Query.setBoost(), Query.getBoost() and Query.clone() are gone.
|
||||||
|
|
|
@ -268,6 +268,17 @@ public class IndexSearcher {
|
||||||
this.queryCache = queryCache;
|
this.queryCache = queryCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the query cache of this {@link IndexSearcher}. This will be either
|
||||||
|
* the {@link #getDefaultQueryCache() default query cache} or the query cache
|
||||||
|
* that was last set through {@link #setQueryCache(QueryCache)}. A return
|
||||||
|
* value of {@code null} indicates that caching is disabled.
|
||||||
|
* @lucene.experimental
|
||||||
|
*/
|
||||||
|
public QueryCache getQueryCache() {
|
||||||
|
return queryCache;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the {@link QueryCachingPolicy} to use for query caching.
|
* Set the {@link QueryCachingPolicy} to use for query caching.
|
||||||
* This method should be called <b>before</b> starting using this
|
* This method should be called <b>before</b> starting using this
|
||||||
|
@ -279,6 +290,16 @@ public class IndexSearcher {
|
||||||
this.queryCachingPolicy = Objects.requireNonNull(queryCachingPolicy);
|
this.queryCachingPolicy = Objects.requireNonNull(queryCachingPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the query cache of this {@link IndexSearcher}. This will be either
|
||||||
|
* the {@link #getDefaultQueryCachingPolicy() default policy} or the policy
|
||||||
|
* that was last set through {@link #setQueryCachingPolicy(QueryCachingPolicy)}.
|
||||||
|
* @lucene.experimental
|
||||||
|
*/
|
||||||
|
public QueryCachingPolicy getQueryCachingPolicy() {
|
||||||
|
return queryCachingPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expert: Creates an array of leaf slices each holding a subset of the given leaves.
|
* Expert: Creates an array of leaf slices each holding a subset of the given leaves.
|
||||||
* Each {@link LeafSlice} is executed in a single thread. By default there
|
* Each {@link LeafSlice} is executed in a single thread. By default there
|
||||||
|
|
|
@ -30,6 +30,8 @@ import org.apache.lucene.document.Field.Store;
|
||||||
import org.apache.lucene.document.SortedDocValuesField;
|
import org.apache.lucene.document.SortedDocValuesField;
|
||||||
import org.apache.lucene.document.StringField;
|
import org.apache.lucene.document.StringField;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
|
import org.apache.lucene.index.LeafReaderContext;
|
||||||
|
import org.apache.lucene.index.MultiReader;
|
||||||
import org.apache.lucene.index.RandomIndexWriter;
|
import org.apache.lucene.index.RandomIndexWriter;
|
||||||
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;
|
||||||
|
@ -179,4 +181,46 @@ public class TestIndexSearcher extends LuceneTestCase {
|
||||||
dir.close();
|
dir.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testGetQueryCache() throws IOException {
|
||||||
|
IndexSearcher searcher = new IndexSearcher(new MultiReader());
|
||||||
|
assertEquals(IndexSearcher.getDefaultQueryCache(), searcher.getQueryCache());
|
||||||
|
QueryCache dummyCache = new QueryCache() {
|
||||||
|
@Override
|
||||||
|
public Weight doCache(Weight weight, QueryCachingPolicy policy) {
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
searcher.setQueryCache(dummyCache);
|
||||||
|
assertEquals(dummyCache, searcher.getQueryCache());
|
||||||
|
|
||||||
|
IndexSearcher.setDefaultQueryCache(dummyCache);
|
||||||
|
searcher = new IndexSearcher(new MultiReader());
|
||||||
|
assertEquals(dummyCache, searcher.getQueryCache());
|
||||||
|
|
||||||
|
searcher.setQueryCache(null);
|
||||||
|
assertNull(searcher.getQueryCache());
|
||||||
|
|
||||||
|
IndexSearcher.setDefaultQueryCache(null);
|
||||||
|
searcher = new IndexSearcher(new MultiReader());
|
||||||
|
assertNull(searcher.getQueryCache());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetQueryCachingPolicy() throws IOException {
|
||||||
|
IndexSearcher searcher = new IndexSearcher(new MultiReader());
|
||||||
|
assertEquals(IndexSearcher.getDefaultQueryCachingPolicy(), searcher.getQueryCachingPolicy());
|
||||||
|
QueryCachingPolicy dummyPolicy = new QueryCachingPolicy() {
|
||||||
|
@Override
|
||||||
|
public boolean shouldCache(Query query, LeafReaderContext context) throws IOException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onUse(Query query) {}
|
||||||
|
};
|
||||||
|
searcher.setQueryCachingPolicy(dummyPolicy);
|
||||||
|
assertEquals(dummyPolicy, searcher.getQueryCachingPolicy());
|
||||||
|
|
||||||
|
IndexSearcher.setDefaultQueryCachingPolicy(dummyPolicy);
|
||||||
|
searcher = new IndexSearcher(new MultiReader());
|
||||||
|
assertEquals(dummyPolicy, searcher.getQueryCachingPolicy());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue