mirror of https://github.com/apache/lucene.git
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:
parent
391119f207
commit
9136b7a0e0
|
@ -79,7 +79,7 @@ final class DocInverterPerField extends DocFieldConsumerPerField {
|
||||||
if (!field.isTokenized()) { // un-tokenized field
|
if (!field.isTokenized()) { // un-tokenized field
|
||||||
String stringValue = field.stringValue();
|
String stringValue = field.stringValue();
|
||||||
final int valueLength = stringValue.length();
|
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;
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
consumer.add(token);
|
consumer.add(token);
|
||||||
|
|
|
@ -4206,4 +4206,26 @@ public class TestIndexWriter extends LuceneTestCase
|
||||||
// throws IllegalStateEx w/o bug fix
|
// throws IllegalStateEx w/o bug fix
|
||||||
writer.close();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue