/// <summary>Returns the stored fields of the n<sup>th</sup> document in this set.
/// <p>Documents are cached, so that repeated requests for the same element may
/// return the same Document object. If the fieldselector is changed, then the new
/// fields will not be loaded.
/// </summary>
public Document Doc(int n, FieldSelector fieldSelector)
{
HitDoc hitDoc = HitDoc(n);
// Update LRU cache of documents
Remove(hitDoc); // remove from list, if there
AddToFront(hitDoc); // add to front of list
if (numDocs > maxDocs)
{
// if cache is full
HitDoc oldLast = last;
Remove(last); // flush last
oldLast.doc = null; // let doc get gc'd
}
if (hitDoc.doc == null)
{
if (fieldSelector == null)
{
hitDoc.doc = searcher.Doc(hitDoc.id); // cache miss: read document
}
else
{
hitDoc.doc = searcher.Doc(hitDoc.id, fieldSelector); // cache miss: read document
}
}
return(hitDoc.doc);
}