コード例 #1
0
ファイル: Hits.java プロジェクト: realfirst/cqchineseword
  private final void addToFront(HitDoc hitDoc) { // insert at front of cache
    if (first == null) {
      last = hitDoc;
    } else {
      first.prev = hitDoc;
    }

    hitDoc.next = first;
    first = hitDoc;
    hitDoc.prev = null;

    numDocs++;
  }
コード例 #2
0
ファイル: Hits.java プロジェクト: realfirst/cqchineseword
  /**
   * 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.
   *
   * @throws CorruptIndexException if the index is corrupt
   * @throws IOException if there is a low-level IO error
   */
  public final Document doc(int n) throws CorruptIndexException, IOException {
    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) {
      hitDoc.doc = searcher.doc(hitDoc.id); // cache miss: read document
    }

    return hitDoc.doc;
  }