lucene .doc里存储的skiplist跳表

http://forfuture1978.iteye.com/blog/546841

见图:

lucene-6.5.1-src/lucene-6.5.1
$ grep "skiplistwriter" * -ril
core/src/java/org/apache/lucene/codecs/lucene50/Lucene50PostingsFormat.java
core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SkipWriter.java
core/src/java/org/apache/lucene/codecs/MultiLevelSkipListReader.java
core/src/java/org/apache/lucene/codecs/MultiLevelSkipListWriter.java

 

测试代码位置:

lucene-6.5.1-src/lucene-6.5.1
$ vim core/src/test/org/apache/lucene/codecs/lucene50/TestBlockPostingsFormat3.java

  /**
   * checks advancing docs
   */
  public void assertDocsSkipping(int docFreq, PostingsEnum leftDocs, PostingsEnum rightDocs) throws Exception {
    if (leftDocs == null) {
      assertNull(rightDocs);
      return;
    }
    int docid = -1;
    int averageGap = MAXDOC / (1+docFreq);
    int skipInterval = 16;

    while (true) {
      if (random().nextBoolean()) {
        // nextDoc()
        docid = leftDocs.nextDoc();
        assertEquals(docid, rightDocs.nextDoc());
      } else {
        // advance()
        int skip = docid + (int) Math.ceil(Math.abs(skipInterval + random().nextGaussian() * averageGap));
        docid = leftDocs.advance(skip);
        assertEquals(docid, rightDocs.advance(skip));
      }

      if (docid == DocIdSetIterator.NO_MORE_DOCS) {
        return;
      }
      // we don't assert freqs, they are allowed to be different
    }
  }

 

  /**
   * checks advancing docs + positions
   */
  public void assertPositionsSkipping(int docFreq, PostingsEnum leftDocs, PostingsEnum rightDocs) throws Exception {
    if (leftDocs == null || rightDocs == null) {
      assertNull(leftDocs);
      assertNull(rightDocs);
      return;
    }

    int docid = -1;
    int averageGap = MAXDOC / (1+docFreq);
    int skipInterval = 16;

    while (true) {
      if (random().nextBoolean()) {
        // nextDoc()
        docid = leftDocs.nextDoc();
        assertEquals(docid, rightDocs.nextDoc());
      } else {
        // advance()
        int skip = docid + (int) Math.ceil(Math.abs(skipInterval + random().nextGaussian() * averageGap));
        docid = leftDocs.advance(skip);
        assertEquals(docid, rightDocs.advance(skip));
      }

      if (docid == DocIdSetIterator.NO_MORE_DOCS) {
        return;
      }
      int freq = leftDocs.freq();
      assertEquals(freq, rightDocs.freq());
      for (int i = 0; i < freq; i++) {
        assertEquals(leftDocs.nextPosition(), rightDocs.nextPosition());
        // we don't compare the payloads, it's allowed that one is empty etc
      }
    }
  }

 

posted @ 2017-05-04 17:54  bonelee  阅读(1158)  评论(0编辑  收藏  举报