mirror of
https://github.com/apache/lucene.git
synced 2025-03-06 16:29:30 +00:00
LUCENE-6121: QueryBuilder put 2nd reset() to where it was, and add test to ensure no double-reset if there is no term attribute.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1646794 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
da92c34404
commit
72d3f29460
@ -225,19 +225,25 @@ public class QueryBuilder {
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
// rewind the buffer stream
|
||||
buffer.reset();//will never through on subsequent reset calls
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Error analyzing query text", e);
|
||||
}
|
||||
|
||||
// rewind the buffer stream
|
||||
try {
|
||||
if (numTokens > 0) {
|
||||
buffer.reset();//will never throw; the buffer is cached
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
BytesRef bytes = termAtt == null ? null : termAtt.getBytesRef();
|
||||
|
||||
if (numTokens == 0)
|
||||
if (numTokens == 0) {
|
||||
return null;
|
||||
else if (numTokens == 1) {
|
||||
} else if (numTokens == 1) {
|
||||
try {
|
||||
boolean hasNext = buffer.incrementToken();
|
||||
assert hasNext == true;
|
||||
|
@ -19,6 +19,7 @@ package org.apache.lucene.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.analysis.MockAnalyzer;
|
||||
@ -355,4 +356,32 @@ public class TestQueryBuilder extends LuceneTestCase {
|
||||
expected.setSlop(3);
|
||||
assertEquals(expected, builder.createPhraseQuery("field", "中国", 3));
|
||||
}
|
||||
|
||||
public void testNoTermAttribute() {
|
||||
//Can't use MockTokenizer because it adds TermAttribute and we don't want that
|
||||
Analyzer analyzer = new Analyzer() {
|
||||
@Override
|
||||
protected TokenStreamComponents createComponents(String fieldName) {
|
||||
return new TokenStreamComponents(
|
||||
new Tokenizer() {
|
||||
boolean wasReset = false;
|
||||
@Override
|
||||
public void reset() throws IOException {
|
||||
super.reset();
|
||||
assertFalse(wasReset);
|
||||
wasReset = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean incrementToken() throws IOException {
|
||||
assertTrue(wasReset);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
QueryBuilder builder = new QueryBuilder(analyzer);
|
||||
assertNull(builder.createBooleanQuery("field", "whatever"));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user