mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-04-01 04:48:28 +00:00
Return NO_INTERVALS rather than null from empty TokenStream (#42750)
IntervalBuilder#analyzeText will currently return null if it is passed an empty TokenStream, which can lead to a confusing NullPointerException later on during querying. This commit changes the code to return NO_INTERVALS instead. Fixes #42587
This commit is contained in:
parent
61c6a26b31
commit
d0da30e5f4
@ -96,7 +96,7 @@ public class IntervalBuilder {
|
|||||||
// formulate a single term, boolean, or phrase.
|
// formulate a single term, boolean, or phrase.
|
||||||
|
|
||||||
if (numTokens == 0) {
|
if (numTokens == 0) {
|
||||||
return null;
|
return NO_INTERVALS;
|
||||||
} else if (numTokens == 1) {
|
} else if (numTokens == 1) {
|
||||||
// single term
|
// single term
|
||||||
return analyzeTerm(stream);
|
return analyzeTerm(stream);
|
||||||
@ -231,7 +231,7 @@ public class IntervalBuilder {
|
|||||||
return clauses;
|
return clauses;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final IntervalsSource NO_INTERVALS = new IntervalsSource() {
|
static final IntervalsSource NO_INTERVALS = new IntervalsSource() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IntervalIterator intervals(String field, LeafReaderContext ctx) {
|
public IntervalIterator intervals(String field, LeafReaderContext ctx) {
|
||||||
|
@ -110,6 +110,12 @@ public class IntervalBuilderTests extends ESTestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testEmptyTokenStream() throws IOException {
|
||||||
|
CannedTokenStream ts = new CannedTokenStream();
|
||||||
|
IntervalsSource source = BUILDER.analyzeText(new CachingTokenFilter(ts), 0, true);
|
||||||
|
assertSame(IntervalBuilder.NO_INTERVALS, source);
|
||||||
|
}
|
||||||
|
|
||||||
public void testSimpleSynonyms() throws IOException {
|
public void testSimpleSynonyms() throws IOException {
|
||||||
|
|
||||||
CannedTokenStream ts = new CannedTokenStream(
|
CannedTokenStream ts = new CannedTokenStream(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user