FileDocCategorySizeDatePackage
Searcher.javaAPI DocApache Lucene 2.1.07184Wed Feb 14 10:46:40 GMT 2007org.apache.lucene.search

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.

Fields Summary
private Similarity
similarity
The Similarity implementation used by this searcher.
Constructors Summary
Methods Summary
public abstract voidclose()

protected org.apache.lucene.search.WeightcreateWeight(org.apache.lucene.search.Query query)
creates a weight for query

return
new weight

      return query.weight(this);
  
public abstract org.apache.lucene.document.Documentdoc(int i)

public abstract intdocFreq(org.apache.lucene.index.Term term)

public int[]docFreqs(org.apache.lucene.index.Term[] terms)

    int[] result = new int[terms.length];
    for (int i = 0; i < terms.length; i++) {
      result[i] = docFreq(terms[i]);
    }
    return result;
  
public abstract org.apache.lucene.search.Explanationexplain(org.apache.lucene.search.Weight weight, int doc)

public org.apache.lucene.search.Explanationexplain(org.apache.lucene.search.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.

    return explain(createWeight(query), doc);
  
public org.apache.lucene.search.SimilaritygetSimilarity()
Expert: Return the Similarity implementation used by this Searcher.

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

    return this.similarity;
  
public abstract intmaxDoc()

public abstract org.apache.lucene.search.Queryrewrite(org.apache.lucene.search.Query query)

public final org.apache.lucene.search.Hitssearch(org.apache.lucene.search.Query query)
Returns the documents matching query.

throws
BooleanQuery.TooManyClauses

    return search(query, (Filter)null);
  
public abstract voidsearch(org.apache.lucene.search.Weight weight, org.apache.lucene.search.Filter filter, org.apache.lucene.search.HitCollector results)

public abstract org.apache.lucene.search.TopDocssearch(org.apache.lucene.search.Weight weight, org.apache.lucene.search.Filter filter, int n)

public org.apache.lucene.search.Hitssearch(org.apache.lucene.search.Query query, org.apache.lucene.search.Filter filter)
Returns the documents matching query and filter.

throws
BooleanQuery.TooManyClauses

    return new Hits(this, query, filter);
  
public abstract org.apache.lucene.search.TopFieldDocssearch(org.apache.lucene.search.Weight weight, org.apache.lucene.search.Filter filter, int n, org.apache.lucene.search.Sort sort)

public org.apache.lucene.search.Hitssearch(org.apache.lucene.search.Query query, org.apache.lucene.search.Sort sort)
Returns documents matching query sorted by sort.

throws
BooleanQuery.TooManyClauses

    return new Hits(this, query, null, sort);
  
public org.apache.lucene.search.Hitssearch(org.apache.lucene.search.Query query, org.apache.lucene.search.Filter filter, org.apache.lucene.search.Sort sort)
Returns documents matching query and filter, sorted by sort.

throws
BooleanQuery.TooManyClauses

    return new Hits(this, query, filter, sort);
  
public org.apache.lucene.search.TopFieldDocssearch(org.apache.lucene.search.Query query, org.apache.lucene.search.Filter filter, int n, org.apache.lucene.search.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

    return search(createWeight(query), filter, n, sort);
  
public voidsearch(org.apache.lucene.search.Query query, org.apache.lucene.search.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(query, (Filter)null, results);
  
public voidsearch(org.apache.lucene.search.Query query, org.apache.lucene.search.Filter filter, org.apache.lucene.search.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.

param
query to match documents
param
filter if non-null, a bitset used to eliminate some documents
param
results to receive hits
throws
BooleanQuery.TooManyClauses

    search(createWeight(query), filter, results);
  
public org.apache.lucene.search.TopDocssearch(org.apache.lucene.search.Query query, org.apache.lucene.search.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

    return search(createWeight(query), filter, n);
  
public voidsetSimilarity(org.apache.lucene.search.Similarity similarity)
Expert: Set the Similarity implementation used by this Searcher.

see
Similarity#setDefault(Similarity)


                
      
    this.similarity = similarity;