From 1a18acd783745f8fa11042f854f96a3e5ed5aa72 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Thu, 26 Apr 2018 11:27:33 +0100 Subject: [PATCH] LUCENE-8196: Fix unordered case with non-matching subinterval --- .../search/intervals/IntervalFunction.java | 4 ++- .../search/intervals/TestIntervalQuery.java | 12 +++++++++ .../search/intervals/TestIntervals.java | 25 +++++++++++++++++-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/lucene/sandbox/src/java/org/apache/lucene/search/intervals/IntervalFunction.java b/lucene/sandbox/src/java/org/apache/lucene/search/intervals/IntervalFunction.java index c550a722517..ddd891f61ec 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/search/intervals/IntervalFunction.java +++ b/lucene/sandbox/src/java/org/apache/lucene/search/intervals/IntervalFunction.java @@ -238,7 +238,9 @@ abstract class IntervalFunction { queueEnd = start = end = -1; this.queue.clear(); for (IntervalIterator it : subIterators) { - it.nextInterval(); + if (it.nextInterval() == NO_MORE_INTERVALS) { + break; + } queue.add(it); updateRightExtreme(it); } diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/intervals/TestIntervalQuery.java b/lucene/sandbox/src/test/org/apache/lucene/search/intervals/TestIntervalQuery.java index de7341e9bc4..8f0623e8369 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/search/intervals/TestIntervalQuery.java +++ b/lucene/sandbox/src/test/org/apache/lucene/search/intervals/TestIntervalQuery.java @@ -166,4 +166,16 @@ public class TestIntervalQuery extends LuceneTestCase { 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}); + } } diff --git a/lucene/sandbox/src/test/org/apache/lucene/search/intervals/TestIntervals.java b/lucene/sandbox/src/test/org/apache/lucene/search/intervals/TestIntervals.java index 8f91a7f9788..9405f79e5ff 100644 --- a/lucene/sandbox/src/test/org/apache/lucene/search/intervals/TestIntervals.java +++ b/lucene/sandbox/src/test/org/apache/lucene/search/intervals/TestIntervals.java @@ -20,6 +20,7 @@ package org.apache.lucene.search.intervals; import java.io.IOException; import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.CharArraySet; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -60,7 +61,7 @@ public class TestIntervals extends LuceneTestCase { private static Directory directory; private static IndexSearcher searcher; - private static Analyzer analyzer = new StandardAnalyzer(); + private static Analyzer analyzer = new StandardAnalyzer(CharArraySet.EMPTY_SET); @BeforeClass public static void setupIndex() throws IOException { @@ -172,7 +173,7 @@ public class TestIntervals extends LuceneTestCase { } 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, 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}, + {}, + {}, + {} + }); + } + }