Apache Lucene open-source search software
LUCENE-1828: Fix MemoryIndex to call TokenStream.reset() and TokenStream.end().
Michael Busch5a40767d6751
diff --git a/contrib/CHANGES.txt b/contrib/CHANGES.txtindex 9f85f635339..e4cefdaa5d4 100644--- a/contrib/CHANGES.txt+++ b/contrib/CHANGES.txt@@ -78,6 +78,8 @@ Bug fixes10. LUCENE-1792: Fix new query parser to set rewrite method formulti-term queries. (Luis Alves, Mike McCandless via Michael Busch)+11. LUCENE-1828: Fix memory index to call TokenStream.reset() and+ TokenStream.end(). (Tim Smith via Michael Busch)New featuresdiff --git a/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java b/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.javaindex 18b87f01148..cd9b5b6fd3c 100644--- a/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java+++ b/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java@@ -342,6 +342,7 @@ public class MemoryIndex implements Serializable {PositionIncrementAttribute posIncrAttribute = (PositionIncrementAttribute) stream.addAttribute(PositionIncrementAttribute.class);OffsetAttribute offsetAtt = (OffsetAttribute) stream.addAttribute(OffsetAttribute.class);+ stream.reset();while (stream.incrementToken()) {String term = termAtt.term();if (term.length() == 0) continue; // nothing to do@@ -363,7 +364,8 @@ public class MemoryIndex implements Serializable {positions.add(pos, offsetAtt.startOffset(), offsetAtt.endOffset());}}-+ stream.end();+// ensure infos.numTokens > 0 invariant; needed for correct operation of terms()if (numTokens > 0) {boost = boost * docBoost; // see DocumentWriter.addDocument(...)