본문 바로가기

IT-Consultant

특정 Term에 대한 Terminfo 찾기

  /** Returns the TermInfo for a Term in the set, or null. */
  TermInfo get(Term term) throws IOException {
    if (size == 0) return null;

    ensureIndexIsRead();

    // optimize sequential access: first try scanning cached enum w/o seeking
    SegmentTermEnum enumerator = getEnum();
    if (enumerator.term() != null                 // term is at or past current
 && ((enumerator.prev() != null && term.compareTo(enumerator.prev())> 0)
     || term.compareTo(enumerator.term()) >= 0)) {
      int enumOffset = (int)(enumerator.position/enumerator.indexInterval)+1;
      if (indexTerms.length == enumOffset   // but before end of block
   || term.compareTo(indexTerms[enumOffset]) < 0)
 return scanEnum(term);     // no need to seek
    }

    // random-access: must seek
    seekEnum(getIndexOffset(term));
    return scanEnum(term);
  }