see {@link Searcher#Search(Query, int)},
/// {@link Searcher#Search(Query, Filter, int)} and
/// {@link 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
/// ...
///
///
[Obsolete("see Searcher.Search(Query, int), Searcher.Search(Query, Filter, int) and Searcher.Search(Query, Filter, int, Sort)")]
public sealed class Hits
{
private Weight weight;
private Searcher searcher;
private Filter filter = null;
private Sort sort = null;
private int length; // the total number of hits
private System.Collections.ArrayList hitDocs = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); // cache of hits retrieved
private HitDoc first; // head of LRU cache
private HitDoc last; // tail of LRU cache
private int numDocs = 0; // number cached
private int maxDocs = 200; // max to cache
private int nDeletions; // # deleted docs in the index.
private int lengthAtStart; // this is the number apps usually count on (although deletions can bring it down).
private int nDeletedHits = 0; // # of already collected hits that were meanwhile deleted.
public /*internal*/ bool debugCheckedForDeletions = false; // for test purposes.
internal Hits(Searcher s, Query q, Filter f)
{
weight = q.Weight(s);
searcher = s;
filter = f;
nDeletions = CountDeletions(s);
GetMoreDocs(50); // retrieve 100 initially
lengthAtStart = length;
}
internal Hits(Searcher s, Query q, Filter f, Sort o)
{
weight = q.Weight(s);
searcher = s;
filter = f;
sort = o;
nDeletions = CountDeletions(s);
GetMoreDocs(50); // retrieve 100 initially
lengthAtStart = length;
}
// count # deletions, return -1 if unknown.
private int CountDeletions(Searcher s)
{
int cnt = - 1;
if (s is IndexSearcher)
{
cnt = s.MaxDoc() - ((IndexSearcher) s).GetIndexReader().NumDocs();
}
return cnt;
}
///