org.apache.lucene.search

Class Searcher

public abstract class Searcher extends Object implements Searchable

An abstract base class for search implementations. Implements the main search methods.

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

Method Summary
abstract voidclose()
protected WeightcreateWeight(Query query)
creates a weight for query
abstract Documentdoc(int i)
abstract intdocFreq(Term term)
int[]docFreqs(Term[] terms)
Explanationexplain(Query query, int doc)
Returns an Explanation that describes how doc scored against query.
abstract Explanationexplain(Weight weight, int doc)
SimilaritygetSimilarity()
Expert: Return the Similarity implementation used by this Searcher.
abstract intmaxDoc()
abstract Queryrewrite(Query query)
Hitssearch(Query query)
Returns the documents matching query.
Hitssearch(Query query, Filter filter)
Returns the documents matching query and filter.
Hitssearch(Query query, Sort sort)
Returns documents matching query sorted by sort.
Hitssearch(Query query, Filter filter, Sort sort)
Returns documents matching query and filter, sorted by sort.
TopFieldDocssearch(Query query, Filter filter, int n, Sort sort)
Expert: Low-level search implementation with arbitrary sorting.
voidsearch(Query query, HitCollector results)
Lower-level search API.
voidsearch(Query query, Filter filter, HitCollector results)
Lower-level search API.
TopDocssearch(Query query, Filter filter, int n)
Expert: Low-level search implementation.
abstract voidsearch(Weight weight, Filter filter, HitCollector results)
abstract TopDocssearch(Weight weight, Filter filter, int n)
abstract TopFieldDocssearch(Weight weight, Filter filter, int n, Sort sort)
voidsetSimilarity(Similarity similarity)
Expert: Set the Similarity implementation used by this Searcher.

Method Detail

close

public abstract void close()

createWeight

protected Weight createWeight(Query query)
creates a weight for query

Returns: new weight

doc

public abstract Document doc(int i)

docFreq

public abstract int docFreq(Term term)

docFreqs

public int[] docFreqs(Term[] terms)

explain

public Explanation explain(Query query, int doc)
Returns an Explanation that describes how doc scored against query.

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.

explain

public abstract Explanation explain(Weight weight, int doc)

getSimilarity

public Similarity getSimilarity()
Expert: Return the Similarity implementation used by this Searcher.

This defaults to the current value of {@link Similarity#getDefault()}.

maxDoc

public abstract int maxDoc()

rewrite

public abstract Query rewrite(Query query)

search

public final Hits search(Query query)
Returns the documents matching query.

Throws: BooleanQuery.TooManyClauses

search

public Hits search(Query query, Filter filter)
Returns the documents matching query and filter.

Throws: BooleanQuery.TooManyClauses

search

public Hits search(Query query, Sort sort)
Returns documents matching query sorted by sort.

Throws: BooleanQuery.TooManyClauses

search

public Hits search(Query query, Filter filter, Sort sort)
Returns documents matching query and filter, sorted by sort.

Throws: BooleanQuery.TooManyClauses

search

public TopFieldDocs search(Query query, Filter filter, int n, Sort sort)
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 {@link Searcher#search(Query,Filter,Sort)} instead.

Throws: BooleanQuery.TooManyClauses

search

public void search(Query query, HitCollector results)
Lower-level search API.

{@link HitCollector#collect(int,float)} is called for every non-zero scoring document.

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

Note: The score passed to this method is a raw score. In other words, the score will not necessarily be a float whose value is between 0 and 1.

Throws: BooleanQuery.TooManyClauses

search

public void search(Query query, Filter filter, HitCollector results)
Lower-level search API.

{@link 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 ({@link Searcher#search(Query)}) is usually more efficient, as it skips non-high-scoring hits.

Parameters: query to match documents filter if non-null, a bitset used to eliminate some documents results to receive hits

Throws: BooleanQuery.TooManyClauses

search

public TopDocs search(Query query, Filter filter, int n)
Expert: Low-level search implementation. Finds the top n hits for query, applying filter if non-null.

Called by {@link Hits}.

Applications should usually call {@link Searcher#search(Query)} or {@link Searcher#search(Query,Filter)} instead.

Throws: BooleanQuery.TooManyClauses

search

public abstract void search(Weight weight, Filter filter, HitCollector results)

search

public abstract TopDocs search(Weight weight, Filter filter, int n)

search

public abstract TopFieldDocs search(Weight weight, Filter filter, int n, Sort sort)

setSimilarity

public void setSimilarity(Similarity similarity)
Expert: Set the Similarity implementation used by this Searcher.

See Also: setDefault

Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.