LUCENE-8196: Fix unordered case with non-matching subinterval

This commit is contained in:
Alan Woodward 2018-04-26 11:27:33 +01:00
parent 2265ec1947
commit 1a18acd783
3 changed files with 38 additions and 3 deletions

View File

@ -238,7 +238,9 @@ abstract class IntervalFunction {
queueEnd = start = end = -1; queueEnd = start = end = -1;
this.queue.clear(); this.queue.clear();
for (IntervalIterator it : subIterators) { for (IntervalIterator it : subIterators) {
it.nextInterval(); if (it.nextInterval() == NO_MORE_INTERVALS) {
break;
}
queue.add(it); queue.add(it);
updateRightExtreme(it); updateRightExtreme(it);
} }

View File

@ -166,4 +166,16 @@ public class TestIntervalQuery extends LuceneTestCase {
checkHits(q, new int[]{ 6, 7 }); checkHits(q, new int[]{ 6, 7 });
} }
public void testUnordered() throws IOException {
Query q = new IntervalQuery(field,
Intervals.unordered(
Intervals.term("w1"),
Intervals.ordered(
Intervals.term("w3"),
Intervals.term("yy")
)
)
);
checkHits(q, new int[]{3});
}
} }

View File

@ -20,6 +20,7 @@ package org.apache.lucene.search.intervals;
import java.io.IOException; import java.io.IOException;
import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.CharArraySet;
import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document; import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field; import org.apache.lucene.document.Field;
@ -60,7 +61,7 @@ public class TestIntervals extends LuceneTestCase {
private static Directory directory; private static Directory directory;
private static IndexSearcher searcher; private static IndexSearcher searcher;
private static Analyzer analyzer = new StandardAnalyzer(); private static Analyzer analyzer = new StandardAnalyzer(CharArraySet.EMPTY_SET);
@BeforeClass @BeforeClass
public static void setupIndex() throws IOException { public static void setupIndex() throws IOException {
@ -172,7 +173,7 @@ public class TestIntervals extends LuceneTestCase {
} }
public void testIntervalDisjunction() throws IOException { public void testIntervalDisjunction() throws IOException {
checkIntervals(Intervals.or(Intervals.term("pease"), Intervals.term("hot")), "field1", 4, new int[][]{ checkIntervals(Intervals.or(Intervals.term("pease"), Intervals.term("hot"), Intervals.term("notMatching")), "field1", 4, new int[][]{
{}, {},
{ 0, 0, 2, 2, 3, 3, 6, 6, 17, 17}, { 0, 0, 2, 2, 3, 3, 6, 6, 17, 17},
{ 0, 0, 3, 3, 5, 5, 6, 6, 21, 21}, { 0, 0, 3, 3, 5, 5, 6, 6, 21, 21},
@ -194,4 +195,24 @@ public class TestIntervals extends LuceneTestCase {
}); });
} }
public void testNesting2() throws IOException {
checkIntervals(
Intervals.unordered(
Intervals.ordered(
Intervals.term("like"),
Intervals.term("it"),
Intervals.term("cold")
),
Intervals.term("pease")
),
"field1", 2, new int[][]{
{},
{6, 21},
{6, 17},
{},
{},
{}
});
}
} }