lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject [19/37] lucene-solr:jira/http2: LUCENE-8586: Fix infinite loop in Intervals.or()
Date Fri, 07 Dec 2018 09:57:34 GMT
LUCENE-8586: Fix infinite loop in Intervals.or()


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/c78429a5
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/c78429a5
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/c78429a5

Branch: refs/heads/jira/http2
Commit: c78429a554d28611dacd90c388e6c34039b228d1
Parents: 75a053d
Author: Alan Woodward <romseygeek@apache.org>
Authored: Mon Dec 3 16:04:54 2018 +0000
Committer: Alan Woodward <romseygeek@apache.org>
Committed: Tue Dec 4 09:47:42 2018 +0000

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  3 ++
 .../intervals/DisjunctionIntervalsSource.java   | 47 +++++++++++++++++++-
 .../lucene/search/intervals/TestIntervals.java  | 14 ++++++
 3 files changed, 62 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c78429a5/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 0a41d70..3c2a409 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

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c78429a5/lucene/sandbox/src/java/org/apache/lucene/search/intervals/DisjunctionIntervalsSource.java
----------------------------------------------------------------------
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 79c1bcf..c54f18b 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;
+    }
+  };
+
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c78429a5/lucene/sandbox/src/test/org/apache/lucene/search/intervals/TestIntervals.java
----------------------------------------------------------------------
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 d7754be..6002b3a 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"),


Mime
View raw message