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

    Constructors
    Constructor
    Description
    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)
    constructor for non-concurrent search
    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)
    constructor for concurrent search
  • Method Summary

    Modifier and Type
    Method
    Description
    Add a Runnable that 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.
    void
     
    org.apache.lucene.search.CollectionStatistics
     
    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 the minDocsPerSlice parameter and the final number of IndexSearcher.LeafSlice will be equal or lower than the max number of slices.
    org.apache.lucene.search.Weight
    createWeight(org.apache.lucene.search.Query query, org.apache.lucene.search.ScoreMode scoreMode, float boost)
     
    org.apache.lucene.index.DirectoryReader
     
    boolean
     
    void
    Remove a Runnable that checks for query cancellation or timeout which is called while accessing documents in the DirectoryReader but also while collecting them.
    org.apache.lucene.search.Query
    rewrite(org.apache.lucene.search.Query original)
     
    void
    search(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>
    T
    search(org.apache.lucene.search.Query query, org.apache.lucene.search.CollectorManager<C,T> collectorManager)
     
    void
     
    void
     
    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.
    org.apache.lucene.search.TermStatistics
    termStatistics(org.apache.lucene.index.Term term, int docFreq, long totalTermFreq)
     
    void
     
    boolean
    If the search has timed out following Elasticsearch custom implementation

    Methods 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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

      public void setProfiler(QueryProfiler profiler)
    • addQueryCancellation

      public Runnable addQueryCancellation(Runnable action)
      Add a Runnable that 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

      public void removeQueryCancellation(Runnable action)
      Remove a Runnable that 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:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Releasable
    • hasCancellations

      public boolean hasCancellations()
    • setAggregatedDfs

      public void setAggregatedDfs(AggregatedDfs aggregatedDfs)
    • rewrite

      public org.apache.lucene.search.Query rewrite(org.apache.lucene.search.Query original) throws IOException
      Overrides:
      rewrite in class org.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:
      createWeight in class org.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:
      slices in class org.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 the minDocsPerSlice parameter and the final number of IndexSearcher.LeafSlice will 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:
      search in class org.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:
      search in class org.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:
      termStatistics in class org.apache.lucene.search.IndexSearcher
      Throws:
      IOException
    • collectionStatistics

      public org.apache.lucene.search.CollectionStatistics collectionStatistics(String field) throws IOException
      Overrides:
      collectionStatistics in class org.apache.lucene.search.IndexSearcher
      Throws:
      IOException
    • getDirectoryReader

      public org.apache.lucene.index.DirectoryReader getDirectoryReader()