From 993488ea07eb838099b3176030269eacbe318f26 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 13 May 2011 17:50:33 +0000 Subject: [PATCH] LUCENE-3040: three more missed cases of tokenStream->reusableTokenStream git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1102827 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/lucene/search/highlight/Highlighter.java | 4 ++-- lucene/contrib/lucli/src/java/lucli/LuceneMethods.java | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lucene/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Highlighter.java b/lucene/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Highlighter.java index 3957c46f3df..9448a25dfa9 100644 --- a/lucene/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Highlighter.java +++ b/lucene/contrib/highlighter/src/java/org/apache/lucene/search/highlight/Highlighter.java @@ -78,7 +78,7 @@ public class Highlighter public final String getBestFragment(Analyzer analyzer, String fieldName,String text) throws IOException, InvalidTokenOffsetsException { - TokenStream tokenStream = analyzer.tokenStream(fieldName, new StringReader(text)); + TokenStream tokenStream = analyzer.reusableTokenStream(fieldName, new StringReader(text)); return getBestFragment(tokenStream, text); } @@ -130,7 +130,7 @@ public class Highlighter int maxNumFragments) throws IOException, InvalidTokenOffsetsException { - TokenStream tokenStream = analyzer.tokenStream(fieldName, new StringReader(text)); + TokenStream tokenStream = analyzer.reusableTokenStream(fieldName, new StringReader(text)); return getBestFragments(tokenStream, text, maxNumFragments); } diff --git a/lucene/contrib/lucli/src/java/lucli/LuceneMethods.java b/lucene/contrib/lucli/src/java/lucli/LuceneMethods.java index 266297b1f3b..8d5c1e5d45c 100644 --- a/lucene/contrib/lucli/src/java/lucli/LuceneMethods.java +++ b/lucene/contrib/lucli/src/java/lucli/LuceneMethods.java @@ -305,11 +305,12 @@ class LuceneMethods { int position = 0; // Tokenize field and add to postingTable - TokenStream stream = analyzer.tokenStream(fieldName, reader); + TokenStream stream = analyzer.reusableTokenStream(fieldName, reader); CharTermAttribute termAtt = stream.addAttribute(CharTermAttribute.class); PositionIncrementAttribute posIncrAtt = stream.addAttribute(PositionIncrementAttribute.class); try { + stream.reset(); while (stream.incrementToken()) { position += (posIncrAtt.getPositionIncrement() - 1); position++; @@ -323,6 +324,7 @@ class LuceneMethods { } if (position > maxFieldLength) break; } + stream.end(); } finally { stream.close(); }