Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-8586: Fix infinite loop in Intervals.or()

Alan Woodwardc78429a554d2
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 0a41d70b7ff..3c2a4092fc8 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -305,6 +305,9 @@ Bug fixes
* LUCENE-8556: Use latitude and longitude instead of encoding values to check if triangle is ear
when using morton optimisation. (Ignacio Vera)
+* LUCENE-8586: Intervals.or() could get stuck in an infinite loop on certain indexes
+ (Alan Woodward)
+
New Features
* LUCENE-8496: Selective indexing - modify BKDReader/BKDWriter to allow users
diff --git a/lucene/sandbox/src/java/org/apache/lucene/search/intervals/DisjunctionIntervalsSource.java b/lucene/sandbox/src/java/org/apache/lucene/search/intervals/DisjunctionIntervalsSource.java
index 79c1bcf66e7..c54f18bec12 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/search/intervals/DisjunctionIntervalsSource.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/search/intervals/DisjunctionIntervalsSource.java
@@ -146,7 +146,7 @@ class DisjunctionIntervalsSource extends IntervalsSource {
@Override
public int nextInterval() throws IOException {
- if (current == EMPTY) {
+ if (current == EMPTY || current == EXHAUSTED) {
if (intervalQueue.size() > 0) {
current = intervalQueue.top();
}
@@ -160,7 +160,7 @@ class DisjunctionIntervalsSource extends IntervalsSource {
}
}
if (intervalQueue.size() == 0) {
- current = EMPTY;
+ current = EXHAUSTED;
return NO_MORE_INTERVALS;
}
current = intervalQueue.top();
@@ -239,4 +239,47 @@ class DisjunctionIntervalsSource extends IntervalsSource {
}
};
+ private static final IntervalIterator EXHAUSTED = new IntervalIterator() {
+
+ @Override
+ public int docID() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int nextDoc() throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int advance(int target) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public long cost() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int start() {
+ return NO_MORE_INTERVALS;
+ }
+
+ @Override
+ public int end() {
+ return NO_MORE_INTERVALS;
+ }
+
+ @Override
+ public int nextInterval() {
+ return NO_MORE_INTERVALS;
+ }
+
+ @Override
+ public float matchCost() {
+ return 0;
+ }
+ };
+
}
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 d7754bea5e9..6002b3a74fc 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
@@ -56,6 +56,8 @@ public class TestIntervals extends LuceneTestCase {
"Porridge is great"
};
+ // 0 1 2 3 4 5 6 7 8 9
+ // 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
private static String field2_docs[] = {
"In Xanadu did Kubla Khan a stately pleasure dome decree",
"Where Alph the sacred river ran through caverns measureless to man",
@@ -260,6 +262,18 @@ public class TestIntervals extends LuceneTestCase {
assertFalse(mi.next());
}
+ public void testCombinationDisjunction() throws IOException {
+ IntervalsSource source = Intervals.ordered(
+ Intervals.or(Intervals.term("alph"), Intervals.term("sacred")),
+ Intervals.term("measureless")
+ );
+ checkIntervals(source, "field2", 1, new int[][]{
+ {},
+ { 3, 8 },
+ {}, {}, {}, {}
+ });
+ }
+
public void testNesting() throws IOException {
IntervalsSource source = Intervals.unordered(
Intervals.term("pease"),