Searcher.search(Query, int)
, Searcher.search(Query, Filter, int)
and Searcher.search(Query, Filter, int, Sort)
:TopDocs topDocs = searcher.search(query, numHits); ScoreDoc[] hits = 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 java.lang.Object
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).
Modifier and Type | Method and Description |
---|---|
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.
|
java.util.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.
|
public final int length()
public final Document doc(int n) throws CorruptIndexException, java.io.IOException
Documents are cached, so that repeated requests for the same element may return the same Document object.
CorruptIndexException
- if the index is corruptjava.io.IOException
- if there is a low-level IO errorpublic final float score(int n) throws java.io.IOException
java.io.IOException
public final int id(int n) throws java.io.IOException
java.io.IOException
public java.util.Iterator iterator()
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
.
Copyright © 2000-2019 Apache Software Foundation. All Rights Reserved.