mirror of https://github.com/apache/lucene.git
LUCENE-6271: bring test up to the new world
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene6271@1670698 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6f70221d21
commit
93969f6d8b
|
@ -32,6 +32,13 @@ import org.apache.lucene.util.BytesRef;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
|
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
|
||||||
|
|
||||||
|
import static org.apache.lucene.index.PostingsEnum.NONE;
|
||||||
|
import static org.apache.lucene.index.PostingsEnum.FREQS;
|
||||||
|
import static org.apache.lucene.index.PostingsEnum.POSITIONS;
|
||||||
|
import static org.apache.lucene.index.PostingsEnum.PAYLOADS;
|
||||||
|
import static org.apache.lucene.index.PostingsEnum.OFFSETS;
|
||||||
|
import static org.apache.lucene.index.PostingsEnum.ALL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test basic postingsenum behavior, flags, reuse, etc.
|
* Test basic postingsenum behavior, flags, reuse, etc.
|
||||||
*/
|
*/
|
||||||
|
@ -66,37 +73,23 @@ public class TestPostingsEnum extends LuceneTestCase {
|
||||||
assertEquals(1, postings.freq());
|
assertEquals(1, postings.freq());
|
||||||
assertEquals(DocIdSetIterator.NO_MORE_DOCS, postings.nextDoc());
|
assertEquals(DocIdSetIterator.NO_MORE_DOCS, postings.nextDoc());
|
||||||
|
|
||||||
// asking for docs only: ok
|
// asking for any flags: ok
|
||||||
PostingsEnum docsOnly = termsEnum.postings(null, null, PostingsEnum.NONE);
|
for (int flag : new int[] { NONE, FREQS, POSITIONS, PAYLOADS, OFFSETS, ALL }) {
|
||||||
assertEquals(-1, docsOnly.docID());
|
postings = termsEnum.postings(null, null, flag);
|
||||||
assertEquals(0, docsOnly.nextDoc());
|
assertEquals(-1, postings.docID());
|
||||||
assertEquals(1, docsOnly.freq());
|
assertEquals(0, postings.nextDoc());
|
||||||
assertEquals(DocIdSetIterator.NO_MORE_DOCS, docsOnly.nextDoc());
|
assertEquals(1, postings.freq());
|
||||||
|
assertEquals(DocIdSetIterator.NO_MORE_DOCS, postings.nextDoc());
|
||||||
// reuse that too
|
// reuse that too
|
||||||
PostingsEnum docsOnly2 = termsEnum.postings(null, docsOnly, PostingsEnum.NONE);
|
postings2 = termsEnum.postings(null, postings, flag);
|
||||||
assertNotNull(docsOnly2);
|
assertNotNull(postings2);
|
||||||
assertSame(docsOnly, docsOnly2);
|
assertSame(postings, postings2);
|
||||||
// and it had better work
|
// and it had better work
|
||||||
assertEquals(-1, docsOnly2.docID());
|
assertEquals(-1, postings2.docID());
|
||||||
assertEquals(0, docsOnly2.nextDoc());
|
assertEquals(0, postings2.nextDoc());
|
||||||
assertEquals(1, docsOnly2.freq());
|
assertEquals(1, postings2.freq());
|
||||||
assertEquals(DocIdSetIterator.NO_MORE_DOCS, docsOnly2.nextDoc());
|
assertEquals(DocIdSetIterator.NO_MORE_DOCS, postings2.nextDoc());
|
||||||
|
}
|
||||||
// we did not index positions
|
|
||||||
PostingsEnum docsAndPositionsEnum = getOnlySegmentReader(reader).postings(new Term("foo", "bar"), PostingsEnum.POSITIONS);
|
|
||||||
assertNotNull(docsAndPositionsEnum);
|
|
||||||
|
|
||||||
// we did not index positions
|
|
||||||
docsAndPositionsEnum = getOnlySegmentReader(reader).postings(new Term("foo", "bar"), PostingsEnum.PAYLOADS);
|
|
||||||
assertNotNull(docsAndPositionsEnum);
|
|
||||||
|
|
||||||
// we did not index positions
|
|
||||||
docsAndPositionsEnum = getOnlySegmentReader(reader).postings(new Term("foo", "bar"), PostingsEnum.OFFSETS);
|
|
||||||
assertNotNull(docsAndPositionsEnum);
|
|
||||||
|
|
||||||
// we did not index positions
|
|
||||||
docsAndPositionsEnum = getOnlySegmentReader(reader).postings(new Term("foo", "bar"), PostingsEnum.ALL);
|
|
||||||
assertNotNull(docsAndPositionsEnum);
|
|
||||||
|
|
||||||
iw.close();
|
iw.close();
|
||||||
reader.close();
|
reader.close();
|
||||||
|
@ -156,21 +149,27 @@ public class TestPostingsEnum extends LuceneTestCase {
|
||||||
assertTrue(docsOnly.freq() == 1 || docsOnly.freq() == 2);
|
assertTrue(docsOnly.freq() == 1 || docsOnly.freq() == 2);
|
||||||
assertEquals(DocIdSetIterator.NO_MORE_DOCS, docsOnly2.nextDoc());
|
assertEquals(DocIdSetIterator.NO_MORE_DOCS, docsOnly2.nextDoc());
|
||||||
|
|
||||||
// we did not index positions
|
// asking for any flags: ok
|
||||||
PostingsEnum docsAndPositionsEnum = getOnlySegmentReader(reader).postings(new Term("foo", "bar"), PostingsEnum.POSITIONS);
|
for (int flag : new int[] { NONE, FREQS, POSITIONS, PAYLOADS, OFFSETS, ALL }) {
|
||||||
assertNotNull(docsAndPositionsEnum);
|
postings = termsEnum.postings(null, null, flag);
|
||||||
|
assertEquals(-1, postings.docID());
|
||||||
// we did not index positions
|
assertEquals(0, postings.nextDoc());
|
||||||
docsAndPositionsEnum = getOnlySegmentReader(reader).postings(new Term("foo", "bar"), PostingsEnum.PAYLOADS);
|
if (flag != NONE) {
|
||||||
assertNotNull(docsAndPositionsEnum);
|
assertEquals(2, postings.freq());
|
||||||
|
}
|
||||||
// we did not index positions
|
assertEquals(DocIdSetIterator.NO_MORE_DOCS, postings.nextDoc());
|
||||||
docsAndPositionsEnum = getOnlySegmentReader(reader).postings(new Term("foo", "bar"), PostingsEnum.OFFSETS);
|
// reuse that too
|
||||||
assertNotNull(docsAndPositionsEnum);
|
postings2 = termsEnum.postings(null, postings, flag);
|
||||||
|
assertNotNull(postings2);
|
||||||
// we did not index positions
|
assertSame(postings, postings2);
|
||||||
docsAndPositionsEnum = getOnlySegmentReader(reader).postings(new Term("foo", "bar"), PostingsEnum.ALL);
|
// and it had better work
|
||||||
assertNotNull(docsAndPositionsEnum);
|
assertEquals(-1, postings2.docID());
|
||||||
|
assertEquals(0, postings2.nextDoc());
|
||||||
|
if (flag != NONE) {
|
||||||
|
assertEquals(2, postings2.freq());
|
||||||
|
}
|
||||||
|
assertEquals(DocIdSetIterator.NO_MORE_DOCS, postings2.nextDoc());
|
||||||
|
}
|
||||||
|
|
||||||
iw.close();
|
iw.close();
|
||||||
reader.close();
|
reader.close();
|
||||||
|
|
Loading…
Reference in New Issue