IndexSearcher

open class IndexSearcher(context: IndexReaderContext, executor: Executor? = null)

Implements search over a single IndexReader.

Applications usually need only call the inherited .search method. For performance reasons, if your index is unchanging, you should share a single IndexSearcher instance across multiple searches instead of creating a new one per-search. If your index has changed and you wish to see the changes reflected in searching, you should use DirectoryReader.openIfChanged to obtain a new reader and then create a new IndexSearcher from that. Also, for low-latency turnaround it's best to use a near-real-time reader (DirectoryReader.open). Once you have a new IndexReader, it's relatively cheap to create a new IndexSearcher from it.

NOTE: The .search and .searchAfter methods are configured to only count top hits accurately up to 1,000 and may return a lower bound of the hit count if the hit count is greater than or equal to 1,000. On queries that match lots of documents, counting the number of hits may take much longer than computing the top hits so this trade-off allows to get some minimal information about the hit count without slowing down search too much. The TopDocs.scoreDocs array is always accurate however. If this behavior doesn't suit your needs, you should create collectorManagers manually with either [ ] or TopFieldCollectorManager and call .search.

NOTE: [ ] instances are completely thread safe, meaning multiple threads can call any of its methods, concurrently. If your application requires external synchronization, you should not synchronize on the IndexSearcher instance; use your own (non-Lucene) objects instead.

Constructors

Link copied to clipboard
constructor(context: IndexReaderContext, executor: Executor? = null)
constructor(r: IndexReader, executor: Executor? = null)

Creates a searcher searching the provided index.

Types

Link copied to clipboard
object Companion
Link copied to clipboard

Holds information about a specific leaf context and the corresponding range of doc ids to search within. Used to optionally search across partitions of the same segment concurrently.

Link copied to clipboard

A class holding a subset of the IndexSearchers leaf contexts to be executed within a single thread. A leaf slice holds references to one or more LeafReaderContextPartition instances. Each partition targets a specific doc id range of a LeafReaderContext.

Link copied to clipboard
open class TooManyClauses(msg: String = "maxClauseCount is set to ") : RuntimeException

Thrown when an attempt is made to add more than .getMaxClauseCount clauses. This typically happens if a PrefixQuery, FuzzyQuery, WildcardQuery, or TermRangeQuery is expanded to many terms during search.

Link copied to clipboard

Thrown when a client attempts to execute a Query that has more than .getMaxClauseCount total clauses cumulatively in all of its children.

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The Similarity implementation used by this searcher.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard

Returns CollectionStatistics for a field, or null if the field does not exist (has no indexed terms)

Link copied to clipboard
open fun count(query: Query): Int

Count how many documents match the given query. May be faster than counting number of hits by collecting all matches, as the number of hits is retrieved from the index statistics when possible.

Link copied to clipboard
open fun createWeight(query: Query, scoreMode: ScoreMode, boost: Float): Weight

Creates a Weight for the given query, potentially adding caching if possible and configured.

Link copied to clipboard
fun explain(query: Query, doc: Int): Explanation

Returns an Explanation that describes how doc scored against query.

Link copied to clipboard

Returns the TaskExecutor that this searcher relies on to execute concurrent operations

Link copied to clipboard
open fun rewrite(original: Query): Query

Expert: called to re-write queries into primitive queries.

Link copied to clipboard
open fun search(query: Query, n: Int): TopDocs

Finds the top n hits for query.

open fun search(query: Query, collector: Collector)

Lower-level search API.

open fun <C : Collector, T> search(query: Query, collectorManager: CollectorManager<C, T>): T

Lower-level search API. Search all leaves using the given CollectorManager. In contrast to .search, this method will use the searcher's Executor in order to parallelize execution of the collection on the configured .getSlices.

open fun search(query: Query, n: Int, sort: Sort): TopFieldDocs

Search implementation with arbitrary sorting.

fun search(query: Query, n: Int, sort: Sort, doDocScores: Boolean): TopFieldDocs

Search implementation with arbitrary sorting, plus control over whether hit scores and max score should be computed. Finds the top n hits for query, and sorting the hits by the criteria in sort. If doDocScores is true then the score of each hit will be computed and returned. If doMaxScore is true then the maximum score over all collected hits will be computed.

Link copied to clipboard
open fun searchAfter(after: ScoreDoc?, query: Query, numHits: Int): TopDocs
fun searchAfter(after: ScoreDoc?, query: Query, n: Int, sort: Sort): TopDocs

Finds the top n hits for query where all results are after a previous result (after).

fun searchAfter(after: ScoreDoc?, query: Query, numHits: Int, sort: Sort, doDocScores: Boolean): TopFieldDocs

Finds the top n hits for query where all results are after a previous result (after), allowing control over whether hit scores and max score should be computed.

Link copied to clipboard

Returns a StoredFields reader for the stored fields of this index.

Link copied to clipboard
open fun termStatistics(term: Term, docFreq: Int, totalTermFreq: Long): TermStatistics

Returns TermStatistics for a term.

Link copied to clipboard

Returns true if any search hit the .setTimeout.

Link copied to clipboard
open override fun toString(): String