Apache Lucene open-source search software
LUCENE-1800: reusable token streams for query parser
Yonik Seeleyf79712ce8294
diff --git a/CHANGES.txt b/CHANGES.txtindex 190526e166e..cdbc31b36be 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -727,6 +727,8 @@ Optimizationsstrings, the StringHelper.intern() interface was added with adefault implementation that uses a lockless cache.(Earwin Burrfoot, yonik)++13. LUCENE-1800: QueryParser should use reusable TokenStreams. (yonik)Documentationdiff --git a/src/java/org/apache/lucene/queryParser/QueryParser.java b/src/java/org/apache/lucene/queryParser/QueryParser.javaindex d1ed9abb6b5..3d7dd5e48dc 100644--- a/src/java/org/apache/lucene/queryParser/QueryParser.java+++ b/src/java/org/apache/lucene/queryParser/QueryParser.java@@ -537,7 +537,13 @@ public class QueryParser implements QueryParserConstants {// Use the analyzer to get all the tokens, and then build a TermQuery,// PhraseQuery, or nothing based on the term count- TokenStream source = analyzer.tokenStream(field, new StringReader(queryText));+ TokenStream source;+ try {+ source = analyzer.reusableTokenStream(field, new StringReader(queryText));+ source.reset();+ } catch (IOException e) {+ source = analyzer.tokenStream(field, new StringReader(queryText));+ }CachingTokenFilter buffer = new CachingTokenFilter(source);TermAttribute termAtt = null;PositionIncrementAttribute posIncrAtt = null;diff --git a/src/java/org/apache/lucene/queryParser/QueryParser.jj b/src/java/org/apache/lucene/queryParser/QueryParser.jjindex 0c99696103a..309f28b893c 100644--- a/src/java/org/apache/lucene/queryParser/QueryParser.jj+++ b/src/java/org/apache/lucene/queryParser/QueryParser.jj@@ -562,7 +562,13 @@ public class QueryParser {// Use the analyzer to get all the tokens, and then build a TermQuery,// PhraseQuery, or nothing based on the term count- TokenStream source = analyzer.tokenStream(field, new StringReader(queryText));+ TokenStream source;+ try {+ source = analyzer.reusableTokenStream(field, new StringReader(queryText));+ source.reset();+ } catch (IOException e) {+ source = analyzer.tokenStream(field, new StringReader(queryText));+ }CachingTokenFilter buffer = new CachingTokenFilter(source);TermAttribute termAtt = null;PositionIncrementAttribute posIncrAtt = null;