lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r712233 - in /lucene/java/trunk/src: java/org/apache/lucene/index/DocInverterPerField.java test/org/apache/lucene/index/TestIndexWriter.java
Date Fri, 07 Nov 2008 19:37:40 GMT
Author: mikemccand
Date: Fri Nov  7 11:37:39 2008
New Revision: 712233

URL: http://svn.apache.org/viewvc?rev=712233&view=rev
Log:
LUCENE-1442: fix double-counting of offsets of multiple instances of NOT_ANALYZED field under
the same field name

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/DocInverterPerField.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/DocInverterPerField.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/DocInverterPerField.java?rev=712233&r1=712232&r2=712233&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/DocInverterPerField.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/DocInverterPerField.java Fri Nov  7
11:37:39 2008
@@ -79,7 +79,7 @@
         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);

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=712233&r1=712232&r2=712233&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java Fri Nov  7 11:37:39
2008
@@ -4206,4 +4206,26 @@
     // 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();
+  }
 }



Mime
View raw message