mirror of https://github.com/apache/lucene.git
LUCENE-6404: fix 0-length payload semantics in MemoryIndex
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1671813 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
58107a2b76
commit
5aa3cbfb2d
|
@ -480,7 +480,12 @@ public class MemoryIndex {
|
|||
}
|
||||
if (storePayloads) {
|
||||
final BytesRef payload = payloadAtt.getPayload();
|
||||
int pIndex = payload == null ? -1 : payloadsBytesRefs.append(payload);
|
||||
final int pIndex;
|
||||
if (payload == null || payload.length == 0) {
|
||||
pIndex = -1;
|
||||
} else {
|
||||
pIndex = payloadsBytesRefs.append(payload);
|
||||
}
|
||||
postingsWriter.writeInt(pIndex);
|
||||
}
|
||||
sliceArray.end[ord] = postingsWriter.getCurrentOffset();
|
||||
|
|
|
@ -161,6 +161,7 @@ public class TestMemoryIndexAgainstRAMDir extends BaseTokenStreamTestCase {
|
|||
memory.addField("term", termField.toString(), analyzer);
|
||||
|
||||
LeafReader reader = (LeafReader) memory.createSearcher().getIndexReader();
|
||||
TestUtil.checkReader(reader);
|
||||
DirectoryReader competitor = DirectoryReader.open(ramdir);
|
||||
duellReaders(competitor, reader);
|
||||
IOUtils.close(reader, competitor);
|
||||
|
@ -318,6 +319,7 @@ public class TestMemoryIndexAgainstRAMDir extends BaseTokenStreamTestCase {
|
|||
MemoryIndex memory = new MemoryIndex(random().nextBoolean(), false, random().nextInt(50) * 1024 * 1024);
|
||||
memory.addField("foo", "bar", analyzer);
|
||||
LeafReader reader = (LeafReader) memory.createSearcher().getIndexReader();
|
||||
TestUtil.checkReader(reader);
|
||||
PostingsEnum disi = TestUtil.docs(random(), reader, "foo", new BytesRef("bar"), null, null, PostingsEnum.NONE);
|
||||
int docid = disi.docID();
|
||||
assertEquals(-1, docid);
|
||||
|
@ -352,6 +354,7 @@ public class TestMemoryIndexAgainstRAMDir extends BaseTokenStreamTestCase {
|
|||
for (int i = 0; i < numIters; i++) { // check reuse
|
||||
memory.addField("foo", "bar", analyzer);
|
||||
LeafReader reader = (LeafReader) memory.createSearcher().getIndexReader();
|
||||
TestUtil.checkReader(reader);
|
||||
assertEquals(1, reader.terms("foo").getSumTotalTermFreq());
|
||||
PostingsEnum disi = reader.postings(new Term("foo", "bar"), PostingsEnum.ALL);
|
||||
int docid = disi.docID();
|
||||
|
@ -383,6 +386,7 @@ public class TestMemoryIndexAgainstRAMDir extends BaseTokenStreamTestCase {
|
|||
|
||||
// This throws an NPE
|
||||
assertEquals(0, mindex.search(wrappedquery), 0.00001f);
|
||||
TestUtil.checkReader(mindex.createSearcher().getIndexReader());
|
||||
}
|
||||
|
||||
// LUCENE-3831
|
||||
|
@ -395,6 +399,7 @@ public class TestMemoryIndexAgainstRAMDir extends BaseTokenStreamTestCase {
|
|||
|
||||
// This passes though
|
||||
assertEquals(0, mindex.search(wrappedquery), 0.00001f);
|
||||
TestUtil.checkReader(mindex.createSearcher().getIndexReader());
|
||||
}
|
||||
|
||||
public void testSameFieldAddedMultipleTimes() throws IOException {
|
||||
|
@ -403,6 +408,7 @@ public class TestMemoryIndexAgainstRAMDir extends BaseTokenStreamTestCase {
|
|||
mindex.addField("field", "the quick brown fox", mockAnalyzer);
|
||||
mindex.addField("field", "jumps over the", mockAnalyzer);
|
||||
LeafReader reader = (LeafReader) mindex.createSearcher().getIndexReader();
|
||||
TestUtil.checkReader(reader);
|
||||
assertEquals(7, reader.terms("field").getSumTotalTermFreq());
|
||||
PhraseQuery query = new PhraseQuery();
|
||||
query.add(new Term("field", "fox"));
|
||||
|
@ -415,6 +421,7 @@ public class TestMemoryIndexAgainstRAMDir extends BaseTokenStreamTestCase {
|
|||
assertEquals(0, mindex.search(query), 0.00001f);
|
||||
query.setSlop(10);
|
||||
assertTrue("posGap" + mockAnalyzer.getPositionIncrementGap("field") , mindex.search(query) > 0.0001);
|
||||
TestUtil.checkReader(mindex.createSearcher().getIndexReader());
|
||||
}
|
||||
|
||||
public void testNonExistentField() throws IOException {
|
||||
|
@ -422,6 +429,7 @@ public class TestMemoryIndexAgainstRAMDir extends BaseTokenStreamTestCase {
|
|||
MockAnalyzer mockAnalyzer = new MockAnalyzer(random());
|
||||
mindex.addField("field", "the quick brown fox", mockAnalyzer);
|
||||
LeafReader reader = (LeafReader) mindex.createSearcher().getIndexReader();
|
||||
TestUtil.checkReader(reader);
|
||||
assertNull(reader.getNumericDocValues("not-in-index"));
|
||||
assertNull(reader.getNormValues("not-in-index"));
|
||||
assertNull(reader.postings(new Term("not-in-index", "foo")));
|
||||
|
@ -456,6 +464,7 @@ public class TestMemoryIndexAgainstRAMDir extends BaseTokenStreamTestCase {
|
|||
}
|
||||
DirectoryReader competitor = DirectoryReader.open(dir);
|
||||
LeafReader memIndexReader= (LeafReader) memory.createSearcher().getIndexReader();
|
||||
TestUtil.checkReader(memIndexReader);
|
||||
duellReaders(competitor, memIndexReader);
|
||||
IOUtils.close(competitor, memIndexReader);
|
||||
memory.reset();
|
||||
|
@ -471,6 +480,7 @@ public class TestMemoryIndexAgainstRAMDir extends BaseTokenStreamTestCase {
|
|||
IndexSearcher searcher = memory.createSearcher();
|
||||
TopDocs docs = searcher.search(new TermQuery(new Term("foo", "")), 10);
|
||||
assertEquals(1, docs.totalHits);
|
||||
TestUtil.checkReader(searcher.getIndexReader());
|
||||
}
|
||||
|
||||
public void testDuelMemoryIndexCoreDirectoryWithArrayField() throws Exception {
|
||||
|
@ -507,6 +517,7 @@ public class TestMemoryIndexAgainstRAMDir extends BaseTokenStreamTestCase {
|
|||
//compare term vectors
|
||||
Terms ramTv = reader.getTermVector(0, field_name);
|
||||
IndexReader memIndexReader = memIndex.createSearcher().getIndexReader();
|
||||
TestUtil.checkReader(memIndexReader);
|
||||
Terms memTv = memIndexReader.getTermVector(0, field_name);
|
||||
|
||||
compareTermVectors(ramTv, memTv, field_name);
|
||||
|
|
Loading…
Reference in New Issue