SearcherFactory (Lucene 10.5.0 core API)
Description: declaration: package: org.apache.lucene.search, class: SearcherFactory

Package org.apache.lucene.search

# Class SearcherFactory

java.lang.Object
org.apache.lucene.search.SearcherFactory

public class SearcherFactory extends Object
Factory class used by `SearcherManager` to create new IndexSearchers. The default implementation just creates an IndexSearcher with no custom behavior:

       public IndexSearcher newSearcher(IndexReader r) throws IOException {
         return new IndexSearcher(r);
       }

You can pass your own factory instead if you want custom behavior, such as:

- Setting a custom scoring model: `IndexSearcher.setSimilarity(Similarity)`
- Parallel per-segment search: `IndexSearcher(IndexReader, Executor)`
- Return custom subclasses of IndexSearcher (for example that implement distributed scoring)
- Run queries to warm your IndexSearcher before it is used. Note: when using near-realtime search you may want to also `IndexWriterConfig.setMergedSegmentWarmer(IndexWriter.IndexReaderWarmer)` to warm newly merged segments in the background, outside of the reopen path.

WARNING: This API is experimental and might change in incompatible ways in the next release.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SearcherFactory()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `IndexSearcher`
  `newSearcher(IndexReader reader, IndexReader previousReader)`
  Returns a new IndexSearcher over the given reader.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### SearcherFactory

    public SearcherFactory()

- ## Method Details

  - ### newSearcher

    public IndexSearcher newSearcher(IndexReader reader, IndexReader previousReader) throws IOException
    Returns a new IndexSearcher over the given reader.
    Parameters:
      `reader` - the reader to create a new searcher for
      `previousReader` - the reader previously used to create a new searcher. This can be `null` if unknown or if the given reader is the initially opened reader. If this reader is non-null it can be used to find newly opened segments compared to the new reader to warm the searcher up before returning.
    Throws:
      `IOException`