mirror of https://github.com/apache/lucene.git
LUCENE-3580: fix broken DISIs in contrib/memory
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1204145 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
df8ece84c2
commit
4a7da8e14e
|
@ -974,26 +974,28 @@ public class MemoryIndex {
|
|||
private ArrayIntList positions;
|
||||
private boolean hasNext;
|
||||
private Bits liveDocs;
|
||||
private int doc = -1;
|
||||
|
||||
public DocsEnum reset(Bits liveDocs, ArrayIntList positions) {
|
||||
this.liveDocs = liveDocs;
|
||||
this.positions = positions;
|
||||
hasNext = true;
|
||||
doc = -1;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int docID() {
|
||||
return 0;
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextDoc() {
|
||||
if (hasNext && (liveDocs == null || liveDocs.get(0))) {
|
||||
hasNext = false;
|
||||
return 0;
|
||||
return doc = 0;
|
||||
} else {
|
||||
return NO_MORE_DOCS;
|
||||
return doc = NO_MORE_DOCS;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1013,27 +1015,29 @@ public class MemoryIndex {
|
|||
private int posUpto;
|
||||
private boolean hasNext;
|
||||
private Bits liveDocs;
|
||||
private int doc = -1;
|
||||
|
||||
public DocsAndPositionsEnum reset(Bits liveDocs, ArrayIntList positions) {
|
||||
this.liveDocs = liveDocs;
|
||||
this.positions = positions;
|
||||
posUpto = 0;
|
||||
hasNext = true;
|
||||
doc = -1;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int docID() {
|
||||
return 0;
|
||||
return doc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nextDoc() {
|
||||
if (hasNext && (liveDocs == null || liveDocs.get(0))) {
|
||||
hasNext = false;
|
||||
return 0;
|
||||
return doc = 0;
|
||||
} else {
|
||||
return NO_MORE_DOCS;
|
||||
return doc = NO_MORE_DOCS;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,14 +32,19 @@ import org.apache.lucene.analysis.MockTokenizer;
|
|||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.TextField;
|
||||
import org.apache.lucene.index.DocsAndPositionsEnum;
|
||||
import org.apache.lucene.index.DocsEnum;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.index.TermsEnum;
|
||||
import org.apache.lucene.index.codecs.lucene40.Lucene40PostingsFormat;
|
||||
import org.apache.lucene.queryparser.classic.QueryParser;
|
||||
import org.apache.lucene.search.DocIdSetIterator;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.TopDocs;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util._TestUtil;
|
||||
|
||||
/**
|
||||
|
@ -177,4 +182,44 @@ public class MemoryIndexTest extends BaseTokenStreamTestCase {
|
|||
return _TestUtil.randomUnicodeString(random);
|
||||
}
|
||||
}
|
||||
|
||||
public void testDocsEnumStart() throws Exception {
|
||||
Analyzer analyzer = new MockAnalyzer(random);
|
||||
MemoryIndex memory = new MemoryIndex();
|
||||
memory.addField("foo", "bar", analyzer);
|
||||
IndexReader reader = memory.createSearcher().getIndexReader();
|
||||
DocsEnum disi = reader.termDocsEnum(null, "foo", new BytesRef("bar"));
|
||||
int docid = disi.docID();
|
||||
assertTrue(docid == -1 || docid == DocIdSetIterator.NO_MORE_DOCS);
|
||||
assertTrue(disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
|
||||
|
||||
// now reuse and check again
|
||||
TermsEnum te = reader.terms("foo").iterator(null);
|
||||
assertTrue(te.seekExact(new BytesRef("bar"), true));
|
||||
disi = te.docs(null, disi);
|
||||
docid = disi.docID();
|
||||
assertTrue(docid == -1 || docid == DocIdSetIterator.NO_MORE_DOCS);
|
||||
assertTrue(disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
|
||||
reader.close();
|
||||
}
|
||||
|
||||
public void testDocsAndPositionsEnumStart() throws Exception {
|
||||
Analyzer analyzer = new MockAnalyzer(random);
|
||||
MemoryIndex memory = new MemoryIndex();
|
||||
memory.addField("foo", "bar", analyzer);
|
||||
IndexReader reader = memory.createSearcher().getIndexReader();
|
||||
DocsAndPositionsEnum disi = reader.termPositionsEnum(null, "foo", new BytesRef("bar"));
|
||||
int docid = disi.docID();
|
||||
assertTrue(docid == -1 || docid == DocIdSetIterator.NO_MORE_DOCS);
|
||||
assertTrue(disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
|
||||
|
||||
// now reuse and check again
|
||||
TermsEnum te = reader.terms("foo").iterator(null);
|
||||
assertTrue(te.seekExact(new BytesRef("bar"), true));
|
||||
disi = te.docsAndPositions(null, disi);
|
||||
docid = disi.docID();
|
||||
assertTrue(docid == -1 || docid == DocIdSetIterator.NO_MORE_DOCS);
|
||||
assertTrue(disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue