public final class Hits extends Object
Caution: Iterate only over the hits needed. Iterating over all hits is generally not desirable and may be the source of performance issues.
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).
see Searcher.search(org.apache.lucene.search.Query , int), Searcher.search(org.apache.lucene.search.Query , org.apache.lucene.search.Filter , int)
and Searcher.search(org.apache.lucene.search.Query , org.apache.lucene.search.Filter , int, org.apache.lucene.search.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
...
| Constructor and Description |
|---|
Hits(org.apache.lucene.search.IndexSearcher s,
org.apache.lucene.search.Query q,
org.apache.lucene.search.Filter f) |
Hits(org.apache.lucene.search.IndexSearcher s,
org.apache.lucene.search.Query q,
org.apache.lucene.search.Filter f,
org.apache.lucene.search.Sort o,
boolean score) |
| Modifier and Type | Method and Description |
|---|---|
org.apache.lucene.document.Document |
doc(int n)
Returns the stored fields of the nth document in this set.
|
int |
length()
Returns the total number of hits available in this set.
|
float |
score(int n)
Returns the score for the nth document in this set.
|
public Hits(org.apache.lucene.search.IndexSearcher s,
org.apache.lucene.search.Query q,
org.apache.lucene.search.Filter f)
throws IOException
IOExceptionpublic Hits(org.apache.lucene.search.IndexSearcher s,
org.apache.lucene.search.Query q,
org.apache.lucene.search.Filter f,
org.apache.lucene.search.Sort o,
boolean score)
throws IOException
IOExceptionpublic int length()
public org.apache.lucene.document.Document doc(int n)
throws org.apache.lucene.index.CorruptIndexException,
IOException
Documents are cached, so that repeated requests for the same element may return the same Document object.
n - the index of the document to getorg.apache.lucene.index.CorruptIndexException - if the index is corruptIOException - if there is a low-level IO errorpublic float score(int n)
throws IOException
n - the index of the documentIOException - if there is a low-level IO errorCopyright © 2002–2015 The Neo4j Graph Database Project. All rights reserved.