org.apache.lucene.search

Class Hits

public final class Hits extends Object

A ranked list of documents, used to hold search results.

Caution: Iterate only over the hits needed. Iterating over all hits is generally not desirable and may be the source of performance issues. If you need to iterate over many or all hits, consider using the search method that takes a HitCollector.

Method Summary
Documentdoc(int n)
Returns the stored fields of the nth document in this set.
intid(int n)
Returns the id for the nth document in this set.
Iteratoriterator()
Returns a HitIterator to navigate the Hits.
intlength()
Returns the total number of hits available in this set.
floatscore(int n)
Returns the score for the nth document in this set.

Method Detail

doc

public final Document doc(int n)
Returns the stored fields of the nth document in this set.

Documents are cached, so that repeated requests for the same element may return the same Document object.

Throws: CorruptIndexException if the index is corrupt IOException if there is a low-level IO error

id

public final int id(int n)
Returns the id for the nth document in this set. Note that ids may change when the index changes, so you cannot rely on the id to be stable.

iterator

public Iterator iterator()
Returns a HitIterator to navigate the Hits. Each item returned from Iterator#next() is a Hit.

Caution: Iterate only over the hits needed. Iterating over all hits is generally not desirable and may be the source of performance issues. If you need to iterate over many or all hits, consider using a search method that takes a HitCollector.

length

public final int length()
Returns the total number of hits available in this set.

score

public final float score(int n)
Returns the score for the nth document in this set.
Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.