LUCENE-1442: fix double-counting of offsets of multiple instances of NOT_ANALYZED field under the same field name

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@712233 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2008-11-07 19:37:39 +00:00
parent 391119f207
commit 9136b7a0e0
2 changed files with 23 additions and 1 deletions

View File

@ -79,7 +79,7 @@ final class DocInverterPerField extends DocFieldConsumerPerField {
if (!field.isTokenized()) { // un-tokenized field
String stringValue = field.stringValue();
final int valueLength = stringValue.length();
Token token = perThread.localToken.reinit(stringValue, fieldState.offset, fieldState.offset + valueLength);
Token token = perThread.localToken.reinit(stringValue, 0, valueLength);
boolean success = false;
try {
consumer.add(token);

View File

@ -4206,4 +4206,26 @@ public class TestIndexWriter extends LuceneTestCase
// throws IllegalStateEx w/o bug fix
writer.close();
}
// LUCENE-1442
public void testDoubleOffsetCounting() throws Exception {
MockRAMDirectory dir = new MockRAMDirectory();
IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
Document doc = new Document();
Field f = new Field("field", "abcd", Field.Store.NO, Field.Index.NOT_ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
doc.add(f);
doc.add(f);
w.addDocument(doc);
w.close();
IndexReader r = IndexReader.open(dir);
TermVectorOffsetInfo[] termOffsets = ((TermPositionVector) r.getTermFreqVector(0, "field")).getOffsets(0);
assertEquals(2, termOffsets.length);
assertEquals(0, termOffsets[0].getStartOffset());
assertEquals(4, termOffsets[0].getEndOffset());
assertEquals(4, termOffsets[1].getStartOffset());
assertEquals(8, termOffsets[1].getEndOffset());
r.close();
dir.close();
}
}