Hits (Lucene 2.4.1 API)
Keywords: org.apache.lucene.search.Hits class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.lucene.search
Class Hits

    java.lang.Object
      org.apache.lucene.search.Hits

Deprecated. Hits will be removed in Lucene 3.0.

Instead e. g. `TopDocCollector` and `TopDocs` can be used:

       TopDocCollector collector = new TopDocCollector(hitsPerPage);
       searcher.search(query, collector);
       ScoreDoc[] hits = collector.topDocs().scoreDocs;
       for (int i = 0; i < hits.length; i++) {
         int docId = hits[i].doc;
         Document d = searcher.doc(docId);
         // do something with current hit
         ...

    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`.

Note: Deleting matching documents concurrently with traversing the hits, might, when deleting hits that were not yet retrieved, decrease `length()`. In such case, `ConcurrentModificationException` is thrown when accessing hit `n` ≥ current_`length()` (but `n` < `length()`_at_start).

Method Summary
`Document` | `doc(int n)` Deprecated. Returns the stored fields of the nth document in this set.
`int` | `id(int n)` Deprecated. Returns the id for the nth document in this set.
`Iterator` | `iterator()` Deprecated. Returns a `HitIterator` to navigate the Hits.
`int` | `length()` Deprecated. Returns the total number of hits available in this set.
`float` | `score(int n)` Deprecated. Returns the score for the nth document in this set.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### length

    public final int length()

  Deprecated.
  Returns the total number of hits available in this set.

### doc

    public final Document doc(int n)
                       throws CorruptIndexException,
                              IOException

  Deprecated.
  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

### score

    public final float score(int n)
                      throws IOException

  Deprecated.
  Returns the score for the nth document in this set.

  Throws:
    `IOException`

### id

    public final int id(int n)
                 throws IOException

  Deprecated.
  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.

  Throws:
    `IOException`

### iterator

    public Iterator iterator()

  Deprecated.
  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`.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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