Class IndexSearcher
- java.lang.Object
-
- org.apache.lucene.search.Searcher
-
- org.apache.lucene.search.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)orSearcher.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 Summary
Constructors Constructor and Description IndexSearcher(Directory directory)Creates a searcher searching the index in the provided directory.IndexSearcher(IndexReader r)Creates a searcher searching the provided index.IndexSearcher(java.lang.String path)Creates a searcher searching the index in the named directory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclose()Note that the underlying IndexReader is not closed, if IndexSearcher was constructed with IndexSearcher(IndexReader r).Documentdoc(int i)Expert: Returns the stored fields of documenti.Documentdoc(int i, FieldSelector fieldSelector)Get theDocumentat thenth position.intdocFreq(Term term)Expert: Returns the number of documents containingterm.Explanationexplain(Weight weight, int doc)Expert: low-level implementation method Returns an Explanation that describes howdocscored againstweight.IndexReadergetIndexReader()Return theIndexReaderthis searches.intmaxDoc()Expert: Returns one greater than the largest possible document number.Queryrewrite(Query original)Expert: called to re-write queries into primitive queries.voidsearch(Weight weight, Filter filter, HitCollector results)Lower-level search API.TopDocssearch(Weight weight, Filter filter, int nDocs)Expert: Low-level search implementation.TopFieldDocssearch(Weight weight, Filter filter, int nDocs, Sort sort)Expert: Low-level search implementation with arbitrary sorting.
-
-
-
Constructor Detail
-
IndexSearcher
public IndexSearcher(java.lang.String path) throws CorruptIndexException, java.io.IOExceptionCreates a searcher searching the index in the named directory.- Throws:
CorruptIndexException- if the index is corruptjava.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 corruptjava.io.IOException- if there is a low-level IO error
-
IndexSearcher
public IndexSearcher(IndexReader r)
Creates a searcher searching the provided index.
-
-
Method Detail
-
getIndexReader
public IndexReader getIndexReader()
Return theIndexReaderthis searches.
-
close
public void close() throws java.io.IOExceptionNote 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:
closein interfaceSearchable- Specified by:
closein classSearcher- Throws:
java.io.IOException
-
docFreq
public int docFreq(Term term) throws java.io.IOException
Description copied from interface:SearchableExpert: Returns the number of documents containingterm. Called by search code to compute term weights.- Specified by:
docFreqin interfaceSearchable- Specified by:
docFreqin classSearcher- Throws:
java.io.IOException- See Also:
IndexReader.docFreq(Term)
-
doc
public Document doc(int i) throws CorruptIndexException, java.io.IOException
Description copied from interface:SearchableExpert: Returns the stored fields of documenti. Called byHitCollectorimplementations.- Specified by:
docin interfaceSearchable- Specified by:
docin classSearcher- Throws:
CorruptIndexException- if the index is corruptjava.io.IOException- if there is a low-level IO error- See Also:
IndexReader.document(int)
-
doc
public Document doc(int i, FieldSelector fieldSelector) throws CorruptIndexException, java.io.IOException
Description copied from interface:SearchableGet theDocumentat thenth position. TheFieldSelectormay be used to determine whatFields to load and how they should be loaded. NOTE: If the underlying Reader (more specifically, the underlyingFieldsReader) is closed before the lazyFieldis loaded an exception may be thrown. If you want the value of a lazyFieldto be available after closing you must explicitly load it or fetch the Document again with a new loader.- Parameters:
i- Get the document at thenth positionfieldSelector- TheFieldSelectorto use to determine what Fields should be loaded on the Document. May be null, in which case all Fields will be loaded.- Returns:
- The stored fields of the
Documentat the nth position - Throws:
CorruptIndexException- if the index is corruptjava.io.IOException- if there is a low-level IO error- See Also:
IndexReader.document(int, FieldSelector),Fieldable,FieldSelector,SetBasedFieldSelector,LoadFirstFieldSelector
-
maxDoc
public int maxDoc() throws java.io.IOExceptionDescription copied from interface:SearchableExpert: Returns one greater than the largest possible document number. Called by search code to compute term weights.- Specified by:
maxDocin interfaceSearchable- Specified by:
maxDocin classSearcher- Throws:
java.io.IOException- See Also:
IndexReader.maxDoc()
-
search
public TopDocs search(Weight weight, Filter filter, int nDocs) throws java.io.IOException
Description copied from interface:SearchableExpert: Low-level search implementation. Finds the topnhits forquery, applyingfilterif non-null.Called by
Hits.Applications should usually call
Searcher.search(Query)orSearcher.search(Query,Filter)instead.- Specified by:
searchin interfaceSearchable- Specified by:
searchin classSearcher- Throws:
java.io.IOException
-
search
public TopFieldDocs search(Weight weight, Filter filter, int nDocs, Sort sort) throws java.io.IOException
Description copied from interface:SearchableExpert: Low-level search implementation with arbitrary sorting. Finds the topnhits forquery, applyingfilterif non-null, and sorting the hits by the criteria insort.Applications should usually call
Searcher.search(Query,Filter,Sort)instead.- Specified by:
searchin interfaceSearchable- Specified by:
searchin classSearcher- Throws:
java.io.IOException
-
search
public void search(Weight weight, Filter filter, HitCollector results) throws java.io.IOException
Description copied from interface:SearchableLower-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:
searchin interfaceSearchable- Specified by:
searchin classSearcher- Parameters:
weight- to match documentsfilter- if non-null, a bitset used to eliminate some documentsresults- to receive hits- Throws:
java.io.IOException
-
rewrite
public Query rewrite(Query original) throws java.io.IOException
Description copied from interface:SearchableExpert: called to re-write queries into primitive queries.- Specified by:
rewritein interfaceSearchable- Specified by:
rewritein classSearcher- Throws:
java.io.IOException
-
explain
public Explanation explain(Weight weight, int doc) throws java.io.IOException
Description copied from interface:SearchableExpert: low-level implementation method Returns an Explanation that describes howdocscored againstweight.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:
explainin interfaceSearchable- Specified by:
explainin classSearcher- Throws:
java.io.IOException
-
-
DataMelt 3.0 © DataMelt by jWork.ORG