Documentation of 'org.apache.lucene.search.IndexSearcher' Java class
IndexSearcher
org.apache.lucene.search

Class IndexSearcher

  • All Implemented Interfaces:
    java.rmi.Remote, Searchable


    public class IndexSearcher
    extends Searcher
    Implements search over a single IndexReader.

    Applications usually need only call the inherited Searcher.search(Query) or Searcher.search(Query,Filter) methods. For performance reasons it is recommended to open only one IndexSearcher and use it for all of your searches.

    Note that you can only access Hits from an IndexSearcher as long as it is not yet closed, otherwise an IOException will be thrown.

    • Constructor Detail

      • IndexSearcher

        public IndexSearcher(java.lang.String path)
                      throws CorruptIndexException,
                             java.io.IOException
        Creates a searcher searching the index in the named directory.
        Throws:
        CorruptIndexException - if the index is corrupt
        java.io.IOException - if there is a low-level IO error
      • IndexSearcher

        public IndexSearcher(Directory directory)
                      throws CorruptIndexException,
                             java.io.IOException
        Creates a searcher searching the index in the provided directory.
        Throws:
        CorruptIndexException - if the index is corrupt
        java.io.IOException - if there is a low-level IO error
      • IndexSearcher

        public IndexSearcher(IndexReader r)
        Creates a searcher searching the provided index.
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Note that the underlying IndexReader is not closed, if IndexSearcher was constructed with IndexSearcher(IndexReader r). If the IndexReader was supplied implicitly by specifying a directory, then the IndexReader gets closed.
        Specified by:
        close in interface Searchable
        Specified by:
        close in class Searcher
        Throws:
        java.io.IOException
      • docFreq

        public int docFreq(Term term)
                    throws java.io.IOException
        Description copied from interface: Searchable
        Expert: Returns the number of documents containing term. Called by search code to compute term weights.
        Specified by:
        docFreq in interface Searchable
        Specified by:
        docFreq in class Searcher
        Throws:
        java.io.IOException
        See Also:
        IndexReader.docFreq(Term)
      • maxDoc

        public int maxDoc()
                   throws java.io.IOException
        Description copied from interface: Searchable
        Expert: Returns one greater than the largest possible document number. Called by search code to compute term weights.
        Specified by:
        maxDoc in interface Searchable
        Specified by:
        maxDoc in class Searcher
        Throws:
        java.io.IOException
        See Also:
        IndexReader.maxDoc()
      • search

        public TopFieldDocs search(Weight weight,
                                   Filter filter,
                                   int nDocs,
                                   Sort sort)
                            throws java.io.IOException
        Description copied from interface: Searchable
        Expert: Low-level search implementation with arbitrary sorting. Finds the top n hits for query, applying filter if non-null, and sorting the hits by the criteria in sort.

        Applications should usually call Searcher.search(Query,Filter,Sort) instead.

        Specified by:
        search in interface Searchable
        Specified by:
        search in class Searcher
        Throws:
        java.io.IOException
      • search

        public void search(Weight weight,
                           Filter filter,
                           HitCollector results)
                    throws java.io.IOException
        Description copied from interface: Searchable
        Lower-level search API.

        HitCollector.collect(int,float) is called for every non-zero scoring document.
        HitCollector-based access to remote indexes is discouraged.

        Applications should only use this if they need all of the matching documents. The high-level search API (Searcher.search(Query)) is usually more efficient, as it skips non-high-scoring hits.

        Specified by:
        search in interface Searchable
        Specified by:
        search in class Searcher
        Parameters:
        weight - to match documents
        filter - if non-null, a bitset used to eliminate some documents
        results - to receive hits
        Throws:
        java.io.IOException
      • rewrite

        public Query rewrite(Query original)
                      throws java.io.IOException
        Description copied from interface: Searchable
        Expert: called to re-write queries into primitive queries.
        Specified by:
        rewrite in interface Searchable
        Specified by:
        rewrite in class Searcher
        Throws:
        java.io.IOException
      • explain

        public Explanation explain(Weight weight,
                                   int doc)
                            throws java.io.IOException
        Description copied from interface: Searchable
        Expert: low-level implementation method Returns an Explanation that describes how doc scored against weight.

        This is intended to be used in developing Similarity implementations, and, for good performance, should not be displayed with every hit. Computing an explanation is as expensive as executing the query over the entire index.

        Applications should call Searcher.explain(Query, int).

        Specified by:
        explain in interface Searchable
        Specified by:
        explain in class Searcher
        Throws:
        java.io.IOException

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.