Module org.elasticsearch.server
Class ContextIndexSearcher
java.lang.Object
org.apache.lucene.search.IndexSearcher
org.elasticsearch.search.internal.ContextIndexSearcher
- All Implemented Interfaces:
Closeable,AutoCloseable,Releasable
public class ContextIndexSearcher
extends org.apache.lucene.search.IndexSearcher
implements Releasable
Context-aware extension of
IndexSearcher.-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.search.IndexSearcher
org.apache.lucene.search.IndexSearcher.LeafSlice, org.apache.lucene.search.IndexSearcher.TooManyClauses, org.apache.lucene.search.IndexSearcher.TooManyNestedClauses -
Field Summary
Fields inherited from class org.apache.lucene.search.IndexSearcher
leafContexts, readerContext -
Constructor Summary
ConstructorsConstructorDescriptionContextIndexSearcher(org.apache.lucene.index.IndexReader reader, org.apache.lucene.search.similarities.Similarity similarity, org.apache.lucene.search.QueryCache queryCache, org.apache.lucene.search.QueryCachingPolicy queryCachingPolicy, boolean wrapWithExitableDirectoryReader) constructor for non-concurrent searchContextIndexSearcher(org.apache.lucene.index.IndexReader reader, org.apache.lucene.search.similarities.Similarity similarity, org.apache.lucene.search.QueryCache queryCache, org.apache.lucene.search.QueryCachingPolicy queryCachingPolicy, boolean wrapWithExitableDirectoryReader, Executor executor, int maximumNumberOfSlices, int minimumDocsPerSlice) constructor for concurrent search -
Method Summary
Modifier and TypeMethodDescriptionaddQueryCancellation(Runnable action) Add aRunnablethat will be run on a regular basis while accessing documents in the DirectoryReader but also while collecting them and check for query cancellation or timeout.voidclose()org.apache.lucene.search.CollectionStatisticscollectionStatistics(String field) static org.apache.lucene.search.IndexSearcher.LeafSlice[]computeSlices(List<org.apache.lucene.index.LeafReaderContext> leaves, int maxSliceNum, int minDocsPerSlice) Each computed slice contains at least 10% of the total data in the leaves with a minimum given by theminDocsPerSliceparameter and the final number ofIndexSearcher.LeafSlicewill be equal or lower than the max number of slices.org.apache.lucene.search.WeightcreateWeight(org.apache.lucene.search.Query query, org.apache.lucene.search.ScoreMode scoreMode, float boost) org.apache.lucene.index.DirectoryReaderbooleanvoidremoveQueryCancellation(Runnable action) Remove aRunnablethat checks for query cancellation or timeout which is called while accessing documents in the DirectoryReader but also while collecting them.org.apache.lucene.search.Queryrewrite(org.apache.lucene.search.Query original) voidsearch(List<org.apache.lucene.index.LeafReaderContext> leaves, org.apache.lucene.search.Weight weight, org.apache.lucene.search.Collector collector) <C extends org.apache.lucene.search.Collector,T>
Tsearch(org.apache.lucene.search.Query query, org.apache.lucene.search.CollectorManager<C, T> collectorManager) voidsetAggregatedDfs(AggregatedDfs aggregatedDfs) voidsetProfiler(QueryProfiler profiler) protected org.apache.lucene.search.IndexSearcher.LeafSlice[]Overwrite superclass to force one slice per segment for knn search.org.apache.lucene.search.TermStatisticstermStatistics(org.apache.lucene.index.Term term, int docFreq, long totalTermFreq) voidbooleanIf the search has timed out following Elasticsearch custom implementationMethods inherited from class org.apache.lucene.search.IndexSearcher
count, doc, doc, doc, explain, explain, getDefaultQueryCache, getDefaultQueryCachingPolicy, getDefaultSimilarity, getExecutor, getIndexReader, getLeafContexts, getMaxClauseCount, getQueryCache, getQueryCachingPolicy, getSimilarity, getSlices, getTopReaderContext, search, search, search, search, searchAfter, searchAfter, searchAfter, setDefaultQueryCache, setDefaultQueryCachingPolicy, setMaxClauseCount, setQueryCache, setQueryCachingPolicy, setSimilarity, setTimeout, slices, storedFields, timedOut, toString
-
Constructor Details
-
ContextIndexSearcher
public ContextIndexSearcher(org.apache.lucene.index.IndexReader reader, org.apache.lucene.search.similarities.Similarity similarity, org.apache.lucene.search.QueryCache queryCache, org.apache.lucene.search.QueryCachingPolicy queryCachingPolicy, boolean wrapWithExitableDirectoryReader) throws IOException constructor for non-concurrent search- Throws:
IOException
-
ContextIndexSearcher
public ContextIndexSearcher(org.apache.lucene.index.IndexReader reader, org.apache.lucene.search.similarities.Similarity similarity, org.apache.lucene.search.QueryCache queryCache, org.apache.lucene.search.QueryCachingPolicy queryCachingPolicy, boolean wrapWithExitableDirectoryReader, Executor executor, int maximumNumberOfSlices, int minimumDocsPerSlice) throws IOException constructor for concurrent search- Throws:
IOException
-
-
Method Details
-
setProfiler
-
addQueryCancellation
Add aRunnablethat will be run on a regular basis while accessing documents in the DirectoryReader but also while collecting them and check for query cancellation or timeout. -
removeQueryCancellation
Remove aRunnablethat checks for query cancellation or timeout which is called while accessing documents in the DirectoryReader but also while collecting them. -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceReleasable
-
hasCancellations
public boolean hasCancellations() -
setAggregatedDfs
-
rewrite
public org.apache.lucene.search.Query rewrite(org.apache.lucene.search.Query original) throws IOException - Overrides:
rewritein classorg.apache.lucene.search.IndexSearcher- Throws:
IOException
-
createWeight
public org.apache.lucene.search.Weight createWeight(org.apache.lucene.search.Query query, org.apache.lucene.search.ScoreMode scoreMode, float boost) throws IOException - Overrides:
createWeightin classorg.apache.lucene.search.IndexSearcher- Throws:
IOException
-
slices
protected org.apache.lucene.search.IndexSearcher.LeafSlice[] slices(List<org.apache.lucene.index.LeafReaderContext> leaves) Overwrite superclass to force one slice per segment for knn search. This is only needed temporarily by knn query rewrite, for the main search collection we forked the search method and inject our own slicing logic until this is available in Lucene itself- Overrides:
slicesin classorg.apache.lucene.search.IndexSearcher
-
computeSlices
public static org.apache.lucene.search.IndexSearcher.LeafSlice[] computeSlices(List<org.apache.lucene.index.LeafReaderContext> leaves, int maxSliceNum, int minDocsPerSlice) Each computed slice contains at least 10% of the total data in the leaves with a minimum given by theminDocsPerSliceparameter and the final number ofIndexSearcher.LeafSlicewill be equal or lower than the max number of slices. -
search
public <C extends org.apache.lucene.search.Collector,T> T search(org.apache.lucene.search.Query query, org.apache.lucene.search.CollectorManager<C, T> collectorManager) throws IOException- Overrides:
searchin classorg.apache.lucene.search.IndexSearcher- Throws:
IOException
-
search
public void search(List<org.apache.lucene.index.LeafReaderContext> leaves, org.apache.lucene.search.Weight weight, org.apache.lucene.search.Collector collector) throws IOException - Overrides:
searchin classorg.apache.lucene.search.IndexSearcher- Throws:
IOException
-
timeExceeded
public boolean timeExceeded()If the search has timed out following Elasticsearch custom implementation -
throwTimeExceededException
public void throwTimeExceededException() -
termStatistics
public org.apache.lucene.search.TermStatistics termStatistics(org.apache.lucene.index.Term term, int docFreq, long totalTermFreq) throws IOException - Overrides:
termStatisticsin classorg.apache.lucene.search.IndexSearcher- Throws:
IOException
-
collectionStatistics
public org.apache.lucene.search.CollectionStatistics collectionStatistics(String field) throws IOException - Overrides:
collectionStatisticsin classorg.apache.lucene.search.IndexSearcher- Throws:
IOException
-
getDirectoryReader
public org.apache.lucene.index.DirectoryReader getDirectoryReader()
-