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 } } }
本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6808500.html,如需转载请自行联系原作者