| Index: lucene/src/test/org/apache/lucene/index/TestSameTokenSamePosition.java |
| =================================================================== |
| --- lucene/src/test/org/apache/lucene/index/TestSameTokenSamePosition.java (revision 1147578) |
| +++ lucene/src/test/org/apache/lucene/index/TestSameTokenSamePosition.java (revision ) |
| @@ -21,7 +21,9 @@ |
| import java.io.Reader; |
| |
| import org.apache.lucene.analysis.Analyzer; |
| +import org.apache.lucene.analysis.ReusableAnalyzerBase; |
| import org.apache.lucene.analysis.TokenStream; |
| +import org.apache.lucene.analysis.Tokenizer; |
| import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; |
| import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; |
| import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; |
| @@ -35,7 +37,6 @@ |
| /** |
| * Attempt to reproduce an assertion error that happens |
| * only with the trunk version around April 2011. |
| - * @param args |
| */ |
| public void test() throws Exception { |
| Directory dir = newDirectory(); |
| @@ -72,16 +73,16 @@ |
| } |
| } |
| |
| -final class BugReproAnalyzerTokenizer extends TokenStream { |
| +final class BugReproAnalyzerTokenizer extends Tokenizer { |
| private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class); |
| private final OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class); |
| private final PositionIncrementAttribute posIncAtt = addAttribute(PositionIncrementAttribute.class); |
| - int tokenCount = 4; |
| - int nextTokenIndex = 0; |
| - String terms[] = new String[]{"six", "six", "drunken", "drunken"}; |
| - int starts[] = new int[]{0, 0, 4, 4}; |
| - int ends[] = new int[]{3, 3, 11, 11}; |
| - int incs[] = new int[]{1, 0, 1, 0}; |
| + private final int tokenCount = 4; |
| + private int nextTokenIndex = 0; |
| + private final String terms[] = new String[]{"six", "six", "drunken", "drunken"}; |
| + private final int starts[] = new int[]{0, 0, 4, 4}; |
| + private final int ends[] = new int[]{3, 3, 11, 11}; |
| + private final int incs[] = new int[]{1, 0, 1, 0}; |
| |
| @Override |
| public boolean incrementToken() throws IOException { |
| @@ -95,4 +96,10 @@ |
| return false; |
| } |
| } |
| + |
| + @Override |
| + public void reset() throws IOException { |
| + super.reset(); |
| + this.nextTokenIndex = 0; |
| -} |
| + } |
| +} |
| Index: lucene/src/test/org/apache/lucene/index/TestPayloads.java |
| =================================================================== |
| --- lucene/src/test/org/apache/lucene/index/TestPayloads.java (revision 1152089) |
| +++ lucene/src/test/org/apache/lucene/index/TestPayloads.java (revision ) |
| @@ -457,7 +457,7 @@ |
| private byte[] data; |
| private int length; |
| private int offset; |
| - Payload payload = new Payload(); |
| + private int startOffset; |
| PayloadAttribute payloadAtt; |
| |
| public PayloadFilter(TokenStream in, byte[] data, int offset, int length) { |
| @@ -465,6 +465,7 @@ |
| this.data = data; |
| this.length = length; |
| this.offset = offset; |
| + this.startOffset = offset; |
| payloadAtt = addAttribute(PayloadAttribute.class); |
| } |
| |
| @@ -484,7 +485,13 @@ |
| |
| return hasNext; |
| } |
| + |
| + @Override |
| + public void reset() throws IOException { |
| + super.reset(); |
| + this.offset = startOffset; |
| - } |
| + } |
| + } |
| |
| public void testThreadSafety() throws Exception { |
| final int numThreads = 5; |
| Index: lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java |
| =================================================================== |
| --- lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java (revision 1143415) |
| +++ lucene/src/test/org/apache/lucene/search/TestPositionIncrement.java (revision ) |
| @@ -17,15 +17,12 @@ |
| * limitations under the License. |
| */ |
| |
| +import java.io.IOException; |
| import java.io.Reader; |
| import java.io.StringReader; |
| import java.util.Collection; |
| |
| -import org.apache.lucene.analysis.Analyzer; |
| -import org.apache.lucene.analysis.MockPayloadAnalyzer; |
| -import org.apache.lucene.analysis.MockTokenizer; |
| -import org.apache.lucene.analysis.TokenStream; |
| -import org.apache.lucene.analysis.MockAnalyzer; |
| +import org.apache.lucene.analysis.*; |
| import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; |
| import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; |
| import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; |
| @@ -82,6 +79,12 @@ |
| i++; |
| return true; |
| } |
| + |
| + @Override |
| + public void reset() throws IOException { |
| + super.reset(); |
| + this.i = 0; |
| + } |
| }; |
| } |
| }; |
| Index: lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java |
| =================================================================== |
| --- lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java (revision 1066691) |
| +++ lucene/src/test/org/apache/lucene/search/payloads/PayloadHelper.java (revision ) |
| @@ -57,7 +57,6 @@ |
| public final class PayloadAnalyzer extends Analyzer { |
| |
| |
| - |
| @Override |
| public TokenStream tokenStream(String fieldName, Reader reader) { |
| TokenStream result = new MockTokenizer(reader, MockTokenizer.SIMPLE, true); |
| @@ -67,9 +66,9 @@ |
| } |
| |
| public final class PayloadFilter extends TokenFilter { |
| - String fieldName; |
| - int numSeen = 0; |
| - PayloadAttribute payloadAtt; |
| + private final String fieldName; |
| + private int numSeen = 0; |
| + private final PayloadAttribute payloadAtt; |
| |
| public PayloadFilter(TokenStream input, String fieldName) { |
| super(input); |
| @@ -81,18 +80,13 @@ |
| public boolean incrementToken() throws IOException { |
| |
| if (input.incrementToken()) { |
| - if (fieldName.equals(FIELD)) |
| - { |
| + if (fieldName.equals(FIELD)) { |
| payloadAtt.setPayload(new Payload(payloadField)); |
| - } |
| - else if (fieldName.equals(MULTI_FIELD)) |
| - { |
| - if (numSeen % 2 == 0) |
| - { |
| + } else if (fieldName.equals(MULTI_FIELD)) { |
| + if (numSeen % 2 == 0) { |
| payloadAtt.setPayload(new Payload(payloadMultiField1)); |
| } |
| - else |
| - { |
| + else { |
| payloadAtt.setPayload(new Payload(payloadMultiField2)); |
| } |
| numSeen++; |
| @@ -101,7 +95,13 @@ |
| } |
| return false; |
| } |
| + |
| + @Override |
| + public void reset() throws IOException { |
| + super.reset(); |
| + this.numSeen = 0; |
| - } |
| + } |
| + } |
| |
| /** |
| * Sets up a RAMDirectory, and adds documents (using English.intToEnglish()) with two fields: field and multiField |
| Index: modules/queryparser/src/test/org/apache/lucene/queryparser/classic/TestMultiPhraseQueryParsing.java |
| =================================================================== |
| --- modules/queryparser/src/test/org/apache/lucene/queryparser/classic/TestMultiPhraseQueryParsing.java (revision 1145016) |
| +++ modules/queryparser/src/test/org/apache/lucene/queryparser/classic/TestMultiPhraseQueryParsing.java (revision ) |
| @@ -79,7 +79,14 @@ |
| return false; |
| } |
| } |
| + |
| + @Override |
| + public void reset(Reader reader) throws IOException { |
| + super.reset(reader); |
| + this.upto = 0; |
| + this.lastPos = 0; |
| - } |
| + } |
| + } |
| |
| public void testMultiPhraseQueryParsing() throws Exception { |
| TokenAndPos[] INCR_0_QUERY_TOKENS_AND = new TokenAndPos[]{ |
| Index: lucene/src/test/org/apache/lucene/index/TestTermVectorsReader.java |
| =================================================================== |
| --- lucene/src/test/org/apache/lucene/index/TestTermVectorsReader.java (revision 1144196) |
| +++ lucene/src/test/org/apache/lucene/index/TestTermVectorsReader.java (revision ) |
| @@ -24,8 +24,7 @@ |
| import java.util.Map; |
| import java.util.SortedSet; |
| |
| -import org.apache.lucene.analysis.Analyzer; |
| -import org.apache.lucene.analysis.TokenStream; |
| +import org.apache.lucene.analysis.*; |
| import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; |
| import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; |
| import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; |
| @@ -131,11 +130,11 @@ |
| } |
| |
| private class MyTokenStream extends TokenStream { |
| - int tokenUpto; |
| + private int tokenUpto; |
| |
| - CharTermAttribute termAtt; |
| - PositionIncrementAttribute posIncrAtt; |
| - OffsetAttribute offsetAtt; |
| + private final CharTermAttribute termAtt; |
| + private final PositionIncrementAttribute posIncrAtt; |
| + private final OffsetAttribute offsetAtt; |
| |
| public MyTokenStream() { |
| termAtt = addAttribute(CharTermAttribute.class); |
| @@ -160,7 +159,13 @@ |
| return true; |
| } |
| } |
| + |
| + @Override |
| + public void reset() throws IOException { |
| + super.reset(); |
| + this.tokenUpto = 0; |
| - } |
| + } |
| + } |
| |
| private class MyAnalyzer extends Analyzer { |
| @Override |
| Index: lucene/src/test/org/apache/lucene/index/TestIndexWriter.java |
| =================================================================== |
| --- lucene/src/test/org/apache/lucene/index/TestIndexWriter.java (revision 1144196) |
| +++ lucene/src/test/org/apache/lucene/index/TestIndexWriter.java (revision ) |
| @@ -1660,23 +1660,17 @@ |
| } |
| |
| private static class StringSplitTokenizer extends Tokenizer { |
| - private final String[] tokens; |
| - private int upto = 0; |
| + private String[] tokens; |
| + private int upto; |
| private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class); |
| |
| public StringSplitTokenizer(Reader r) { |
| try { |
| - final StringBuilder b = new StringBuilder(); |
| - final char[] buffer = new char[1024]; |
| - int n; |
| - while((n = r.read(buffer)) != -1) { |
| - b.append(buffer, 0, n); |
| + reset(r); |
| + } catch (IOException e) { |
| + throw new RuntimeException(e); |
| - } |
| + } |
| - tokens = b.toString().split(" "); |
| - } catch (IOException ioe) { |
| - throw new RuntimeException(ioe); |
| - } |
| + } |
| - } |
| |
| @Override |
| public final boolean incrementToken() throws IOException { |
| @@ -1690,7 +1684,19 @@ |
| return false; |
| } |
| } |
| + |
| + @Override |
| + public void reset(Reader input) throws IOException { |
| + this.upto = 0; |
| + final StringBuilder b = new StringBuilder(); |
| + final char[] buffer = new char[1024]; |
| + int n; |
| + while ((n = input.read(buffer)) != -1) { |
| + b.append(buffer, 0, n); |
| - } |
| + } |
| + this.tokens = b.toString().split(" "); |
| + } |
| + } |
| |
| /** |
| * Make sure we skip wicked long terms. |
| Index: lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java |
| =================================================================== |
| --- lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java (revision 1159846) |
| +++ lucene/contrib/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java (revision ) |
| @@ -31,14 +31,7 @@ |
| import javax.xml.parsers.DocumentBuilder; |
| import javax.xml.parsers.DocumentBuilderFactory; |
| |
| -import org.apache.lucene.analysis.Analyzer; |
| -import org.apache.lucene.analysis.BaseTokenStreamTestCase; |
| -import org.apache.lucene.analysis.MockAnalyzer; |
| -import org.apache.lucene.analysis.MockTokenFilter; |
| -import org.apache.lucene.analysis.MockTokenizer; |
| -import org.apache.lucene.analysis.Token; |
| -import org.apache.lucene.analysis.TokenStream; |
| -import org.apache.lucene.analysis.Tokenizer; |
| +import org.apache.lucene.analysis.*; |
| import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; |
| import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; |
| import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; |
| @@ -1842,18 +1835,18 @@ |
| * |
| */ |
| final class SynonymTokenizer extends TokenStream { |
| - private TokenStream realStream; |
| + private final TokenStream realStream; |
| private Token currentRealToken = null; |
| - private Map<String,String> synonyms; |
| - StringTokenizer st = null; |
| - private CharTermAttribute realTermAtt; |
| - private PositionIncrementAttribute realPosIncrAtt; |
| - private OffsetAttribute realOffsetAtt; |
| - private CharTermAttribute termAtt; |
| - private PositionIncrementAttribute posIncrAtt; |
| - private OffsetAttribute offsetAtt; |
| + private final Map<String, String> synonyms; |
| + private StringTokenizer st = null; |
| + private final CharTermAttribute realTermAtt; |
| + private final PositionIncrementAttribute realPosIncrAtt; |
| + private final OffsetAttribute realOffsetAtt; |
| + private final CharTermAttribute termAtt; |
| + private final PositionIncrementAttribute posIncrAtt; |
| + private final OffsetAttribute offsetAtt; |
| |
| - public SynonymTokenizer(TokenStream realStream, Map<String,String> synonyms) { |
| + public SynonymTokenizer(TokenStream realStream, Map<String, String> synonyms) { |
| this.realStream = realStream; |
| this.synonyms = synonyms; |
| realTermAtt = realStream.addAttribute(CharTermAttribute.class); |
| @@ -1905,6 +1898,13 @@ |
| |
| } |
| |
| + @Override |
| + public void reset() throws IOException { |
| + super.reset(); |
| + this.currentRealToken = null; |
| + this.st = null; |
| + } |
| + |
| static abstract class TestHighlightRunner { |
| static final int QUERY = 0; |
| static final int QUERY_TERM = 1; |
| Index: lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java |
| =================================================================== |
| --- lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java (revision 1145594) |
| +++ lucene/src/test/org/apache/lucene/index/TestDocumentWriter.java (revision ) |
| @@ -149,7 +149,7 @@ |
| @Override |
| public TokenStream tokenStream(String fieldName, Reader reader) { |
| return new TokenFilter(new MockTokenizer(reader, MockTokenizer.WHITESPACE, false)) { |
| - boolean first=true; |
| + boolean first = true; |
| AttributeSource.State state; |
| |
| @Override |
| @@ -180,9 +180,16 @@ |
| |
| } |
| |
| - CharTermAttribute termAtt = addAttribute(CharTermAttribute.class); |
| - PayloadAttribute payloadAtt = addAttribute(PayloadAttribute.class); |
| - PositionIncrementAttribute posIncrAtt = addAttribute(PositionIncrementAttribute.class); |
| + @Override |
| + public void reset() throws IOException { |
| + super.reset(); |
| + first = true; |
| + state = null; |
| + } |
| + |
| + final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class); |
| + final PayloadAttribute payloadAtt = addAttribute(PayloadAttribute.class); |
| + final PositionIncrementAttribute posIncrAtt = addAttribute(PositionIncrementAttribute.class); |
| }; |
| } |
| }; |
| Index: modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java |
| =================================================================== |
| --- modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java (revision 1152892) |
| +++ modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestQPHelper.java (revision ) |
| @@ -28,13 +28,7 @@ |
| import java.util.Locale; |
| import java.util.Map; |
| |
| -import org.apache.lucene.analysis.Analyzer; |
| -import org.apache.lucene.analysis.MockAnalyzer; |
| -import org.apache.lucene.analysis.MockTokenFilter; |
| -import org.apache.lucene.analysis.MockTokenizer; |
| -import org.apache.lucene.analysis.TokenFilter; |
| -import org.apache.lucene.analysis.TokenStream; |
| -import org.apache.lucene.analysis.Tokenizer; |
| +import org.apache.lucene.analysis.*; |
| import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; |
| import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; |
| import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; |
| @@ -98,8 +92,9 @@ |
| super(in); |
| } |
| |
| - boolean inPhrase = false; |
| - int savedStart = 0, savedEnd = 0; |
| + private boolean inPhrase = false; |
| + private int savedStart = 0; |
| + private int savedEnd = 0; |
| |
| @Override |
| public boolean incrementToken() throws IOException { |
| @@ -123,7 +118,15 @@ |
| } |
| return false; |
| } |
| + |
| + @Override |
| + public void reset() throws IOException { |
| + super.reset(); |
| + this.inPhrase = false; |
| + this.savedStart = 0; |
| + this.savedEnd = 0; |
| - } |
| + } |
| + } |
| |
| public static final class QPTestAnalyzer extends Analyzer { |
| |
| @@ -1203,10 +1206,11 @@ |
| super.tearDown(); |
| } |
| |
| - private class CannedTokenStream extends TokenStream { |
| + private class CannedTokenStream extends Tokenizer { |
| private int upto = 0; |
| - final PositionIncrementAttribute posIncr = addAttribute(PositionIncrementAttribute.class); |
| - final CharTermAttribute term = addAttribute(CharTermAttribute.class); |
| + private final PositionIncrementAttribute posIncr = addAttribute(PositionIncrementAttribute.class); |
| + private final CharTermAttribute term = addAttribute(CharTermAttribute.class); |
| + |
| @Override |
| public boolean incrementToken() { |
| clearAttributes(); |
| @@ -1229,7 +1233,13 @@ |
| upto++; |
| return true; |
| } |
| + |
| + @Override |
| + public void reset() throws IOException { |
| + super.reset(); |
| + this.upto = 0; |
| - } |
| + } |
| + } |
| |
| private class CannedAnalyzer extends Analyzer { |
| @Override |
| Index: lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java |
| =================================================================== |
| --- lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java (revision 1145781) |
| +++ lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java (revision ) |
| @@ -16,6 +16,7 @@ |
| * limitations under the License. |
| */ |
| |
| +import org.apache.lucene.analysis.*; |
| import org.apache.lucene.util.BytesRef; |
| import org.apache.lucene.util.LuceneTestCase; |
| import org.apache.lucene.util.English; |
| @@ -33,10 +34,6 @@ |
| import org.apache.lucene.search.spans.MultiSpansWrapper; |
| import org.apache.lucene.search.spans.SpanTermQuery; |
| import org.apache.lucene.search.spans.Spans; |
| -import org.apache.lucene.analysis.Analyzer; |
| -import org.apache.lucene.analysis.MockTokenizer; |
| -import org.apache.lucene.analysis.TokenStream; |
| -import org.apache.lucene.analysis.TokenFilter; |
| import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; |
| import org.apache.lucene.index.FieldInvertState; |
| import org.apache.lucene.index.IndexReader; |
| @@ -78,10 +75,10 @@ |
| } |
| |
| private static class PayloadFilter extends TokenFilter { |
| - String fieldName; |
| - int numSeen = 0; |
| + private final String fieldName; |
| + private int numSeen = 0; |
| |
| - PayloadAttribute payloadAtt; |
| + private final PayloadAttribute payloadAtt; |
| |
| public PayloadFilter(TokenStream input, String fieldName) { |
| super(input); |
| @@ -108,7 +105,13 @@ |
| return false; |
| } |
| } |
| + |
| + @Override |
| + public void reset() throws IOException { |
| + super.reset(); |
| + this.numSeen = 0; |
| - } |
| + } |
| + } |
| |
| @BeforeClass |
| public static void beforeClass() throws Exception { |
| Index: lucene/src/test/org/apache/lucene/index/TestTermdocPerf.java |
| =================================================================== |
| --- lucene/src/test/org/apache/lucene/index/TestTermdocPerf.java (revision 1143415) |
| +++ lucene/src/test/org/apache/lucene/index/TestTermdocPerf.java (revision ) |
| @@ -22,7 +22,9 @@ |
| import java.util.Random; |
| |
| import org.apache.lucene.analysis.Analyzer; |
| +import org.apache.lucene.analysis.ReusableAnalyzerBase; |
| import org.apache.lucene.analysis.TokenStream; |
| +import org.apache.lucene.analysis.Tokenizer; |
| import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; |
| import org.apache.lucene.document.Document; |
| import org.apache.lucene.document.Field; |
| @@ -31,13 +33,20 @@ |
| import org.apache.lucene.util.LuceneTestCase; |
| import org.apache.lucene.util.BytesRef; |
| |
| -class RepeatingTokenStream extends TokenStream { |
| - public int num; |
| +class RepeatingTokenStream extends Tokenizer { |
| + |
| + private final Random random; |
| + private final float percentDocs; |
| + private final int maxTF; |
| + private int num; |
| CharTermAttribute termAtt; |
| String value; |
| |
| - public RepeatingTokenStream(String val) { |
| + public RepeatingTokenStream(String val, Random random, float percentDocs, int maxTF) { |
| this.value = val; |
| + this.random = random; |
| + this.percentDocs = percentDocs; |
| + this.maxTF = maxTF; |
| this.termAtt = addAttribute(CharTermAttribute.class); |
| } |
| |
| @@ -51,19 +60,27 @@ |
| } |
| return false; |
| } |
| + |
| + @Override |
| + public void reset() throws IOException { |
| + super.reset(); |
| + if (random.nextFloat() < percentDocs) { |
| + num = random.nextInt(maxTF) + 1; |
| + } else { |
| + num = 0; |
| -} |
| + } |
| + } |
| +} |
| |
| |
| public class TestTermdocPerf extends LuceneTestCase { |
| |
| void addDocs(final Random random, Directory dir, final int ndocs, String field, final String val, final int maxTF, final float percentDocs) throws IOException { |
| - final RepeatingTokenStream ts = new RepeatingTokenStream(val); |
| + final RepeatingTokenStream ts = new RepeatingTokenStream(val, random, percentDocs, maxTF); |
| |
| Analyzer analyzer = new Analyzer() { |
| @Override |
| public TokenStream tokenStream(String fieldName, Reader reader) { |
| - if (random.nextFloat() < percentDocs) ts.num = random.nextInt(maxTF)+1; |
| - else ts.num=0; |
| return ts; |
| } |
| }; |
| Index: modules/queryparser/src/test/org/apache/lucene/queryparser/classic/TestMultiAnalyzer.java |
| =================================================================== |
| --- modules/queryparser/src/test/org/apache/lucene/queryparser/classic/TestMultiAnalyzer.java (revision 1145016) |
| +++ modules/queryparser/src/test/org/apache/lucene/queryparser/classic/TestMultiAnalyzer.java (revision ) |
| @@ -17,18 +17,15 @@ |
| * limitations under the License. |
| */ |
| |
| +import java.io.IOException; |
| import java.io.Reader; |
| |
| -import org.apache.lucene.analysis.Analyzer; |
| -import org.apache.lucene.analysis.MockTokenizer; |
| -import org.apache.lucene.analysis.TokenFilter; |
| -import org.apache.lucene.analysis.TokenStream; |
| +import org.apache.lucene.analysis.*; |
| import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; |
| import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; |
| import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; |
| import org.apache.lucene.analysis.tokenattributes.TypeAttribute; |
| import org.apache.lucene.search.Query; |
| -import org.apache.lucene.analysis.BaseTokenStreamTestCase; |
| import org.apache.lucene.util.Version; |
| |
| /** |
| @@ -144,10 +141,10 @@ |
| private int prevStartOffset; |
| private int prevEndOffset; |
| |
| - CharTermAttribute termAtt; |
| - PositionIncrementAttribute posIncrAtt; |
| - OffsetAttribute offsetAtt; |
| - TypeAttribute typeAtt; |
| + private final CharTermAttribute termAtt; |
| + private final PositionIncrementAttribute posIncrAtt; |
| + private final OffsetAttribute offsetAtt; |
| + private final TypeAttribute typeAtt; |
| |
| public TestFilter(TokenStream in) { |
| super(in); |
| @@ -168,7 +165,7 @@ |
| return true; |
| } else { |
| boolean next = input.incrementToken(); |
| - if (next == false) { |
| + if (!next) { |
| return false; |
| } |
| prevType = typeAtt.type(); |
| @@ -186,7 +183,14 @@ |
| } |
| } |
| } |
| + |
| + public void reset() throws IOException { |
| + super.reset(); |
| + this.prevType = null; |
| + this.prevStartOffset = 0; |
| + this.prevEndOffset = 0; |
| - } |
| + } |
| + } |
| |
| /** |
| * Analyzes "the quick brown" as: quick(incr=2) brown(incr=1). |
| Index: lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java |
| =================================================================== |
| --- lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java (revision 1145016) |
| +++ lucene/src/test/org/apache/lucene/search/TestMultiPhraseQuery.java (revision ) |
| @@ -378,7 +378,14 @@ |
| return false; |
| } |
| } |
| + |
| + @Override |
| + public void reset() throws IOException { |
| + super.reset(); |
| + this.upto = 0; |
| + this.lastPos = 0; |
| - } |
| + } |
| + } |
| |
| public void testZeroPosIncr() throws IOException { |
| Directory dir = new RAMDirectory(); |
| Index: modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestMultiAnalyzerQPHelper.java |
| =================================================================== |
| --- modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestMultiAnalyzerQPHelper.java (revision 1146548) |
| +++ modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/standard/TestMultiAnalyzerQPHelper.java (revision ) |
| @@ -17,12 +17,10 @@ |
| * limitations under the License. |
| */ |
| |
| +import java.io.IOException; |
| import java.io.Reader; |
| |
| -import org.apache.lucene.analysis.Analyzer; |
| -import org.apache.lucene.analysis.MockTokenizer; |
| -import org.apache.lucene.analysis.TokenFilter; |
| -import org.apache.lucene.analysis.TokenStream; |
| +import org.apache.lucene.analysis.*; |
| import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; |
| import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; |
| import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; |
| @@ -184,7 +182,7 @@ |
| return true; |
| } else { |
| boolean next = input.incrementToken(); |
| - if (next == false) { |
| + if (!next) { |
| return false; |
| } |
| prevType = typeAtt.type(); |
| @@ -203,7 +201,14 @@ |
| } |
| } |
| |
| + @Override |
| + public void reset() throws IOException { |
| + super.reset(); |
| + this.prevType = null; |
| + this.prevStartOffset = 0; |
| + this.prevEndOffset = 0; |
| - } |
| + } |
| + } |
| |
| /** |
| * Analyzes "the quick brown" as: quick(incr=2) brown(incr=1). Does not work |
| Index: modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/precedence/TestPrecedenceQueryParser.java |
| =================================================================== |
| --- modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/precedence/TestPrecedenceQueryParser.java (revision 1158861) |
| +++ modules/queryparser/src/test/org/apache/lucene/queryparser/flexible/precedence/TestPrecedenceQueryParser.java (revision ) |
| @@ -26,12 +26,7 @@ |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| -import org.apache.lucene.analysis.Analyzer; |
| -import org.apache.lucene.analysis.MockAnalyzer; |
| -import org.apache.lucene.analysis.MockTokenFilter; |
| -import org.apache.lucene.analysis.MockTokenizer; |
| -import org.apache.lucene.analysis.TokenFilter; |
| -import org.apache.lucene.analysis.TokenStream; |
| +import org.apache.lucene.analysis.*; |
| import org.apache.lucene.analysis.tokenattributes.OffsetAttribute; |
| import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; |
| import org.apache.lucene.document.DateTools; |
| @@ -78,13 +73,14 @@ |
| super(in); |
| } |
| |
| - boolean inPhrase = false; |
| + private boolean inPhrase = false; |
| |
| - int savedStart = 0, savedEnd = 0; |
| + private int savedStart = 0; |
| + private int savedEnd = 0; |
| |
| - CharTermAttribute termAtt = addAttribute(CharTermAttribute.class); |
| + private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class); |
| |
| - OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class); |
| + private final OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class); |
| |
| @Override |
| public boolean incrementToken() throws IOException { |
| @@ -106,7 +102,15 @@ |
| return true; |
| return false; |
| } |
| + |
| + @Override |
| + public void reset() throws IOException { |
| + super.reset(); |
| + this.inPhrase = false; |
| + this.savedStart = 0; |
| + this.savedEnd = 0; |
| - } |
| + } |
| + } |
| |
| public static final class QPTestAnalyzer extends Analyzer { |
| |
| Index: lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java |
| =================================================================== |
| --- lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java (revision 1159905) |
| +++ lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java (revision ) |
| @@ -18,10 +18,7 @@ |
| import java.io.IOException; |
| import java.io.Reader; |
| |
| -import org.apache.lucene.analysis.Analyzer; |
| -import org.apache.lucene.analysis.MockTokenizer; |
| -import org.apache.lucene.analysis.TokenFilter; |
| -import org.apache.lucene.analysis.TokenStream; |
| +import org.apache.lucene.analysis.*; |
| import org.apache.lucene.analysis.tokenattributes.PayloadAttribute; |
| import org.apache.lucene.document.Document; |
| import org.apache.lucene.document.Field; |
| @@ -68,9 +65,9 @@ |
| } |
| |
| private static class PayloadFilter extends TokenFilter { |
| - String fieldName; |
| - int numSeen = 0; |
| - protected PayloadAttribute payAtt; |
| + private final String fieldName; |
| + private int numSeen = 0; |
| + private final PayloadAttribute payAtt; |
| |
| public PayloadFilter(TokenStream input, String fieldName) { |
| super(input); |
| @@ -81,7 +78,7 @@ |
| @Override |
| public boolean incrementToken() throws IOException { |
| boolean result = false; |
| - if (input.incrementToken() == true){ |
| + if (input.incrementToken()) { |
| if (numSeen % 2 == 0) { |
| payAtt.setPayload(new Payload(payload2)); |
| } else { |
| @@ -92,7 +89,13 @@ |
| } |
| return result; |
| } |
| + |
| + @Override |
| + public void reset() throws IOException { |
| + super.reset(); |
| + this.numSeen = 0; |
| - } |
| + } |
| + } |
| |
| private PayloadNearQuery newPhraseQuery (String fieldName, String phrase, boolean inOrder, PayloadFunction function ) { |
| String[] words = phrase.split("[\\s]+"); |