Apache Lucene open-source search software
LUCENE-1583: SpanOrQuery skipTo() doesn't always move forwards as Spans documentation indicates it should.
Mark Robert Miller6bf4d35ce812
diff --git a/CHANGES.txt b/CHANGES.txtindex 9df6dcbbb26..378ebd059f7 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -378,6 +378,9 @@ Bug fixes18. LUCENE-1718: Fix termInfosIndexDivisor to carry over to reopenedreaders (Mike McCandless)++19. LUCENE-1583: SpanOrQuery skipTo() doesn't always move forwards as Spans+ documentation indicates it should. (Moti Nisenson via Mark Miller)New featuresdiff --git a/src/java/org/apache/lucene/search/spans/SpanOrQuery.java b/src/java/org/apache/lucene/search/spans/SpanOrQuery.javaindex 1af3a9dbe4c..2171f59c7b0 100644--- a/src/java/org/apache/lucene/search/spans/SpanOrQuery.java+++ b/src/java/org/apache/lucene/search/spans/SpanOrQuery.java@@ -215,16 +215,21 @@ public class SpanOrQuery extends SpanQuery implements Cloneable {if (queue == null) {return initSpanQueue(target);}-++ boolean skipCalled = false;while (queue.size() != 0 && top().doc() < target) {if (top().skipTo(target)) {queue.adjustTop();} else {queue.pop();}+ skipCalled = true;}-- return queue.size() != 0;++ if (skipCalled) {+ return queue.size() != 0;+ }+ return next();}public int doc() { return top().doc(); }diff --git a/src/test/org/apache/lucene/search/spans/TestSpans.java b/src/test/org/apache/lucene/search/spans/TestSpans.javaindex 66268934070..a7d4da7c9e7 100644--- a/src/test/org/apache/lucene/search/spans/TestSpans.java+++ b/src/test/org/apache/lucene/search/spans/TestSpans.java@@ -331,6 +331,23 @@ public class TestSpans extends LuceneTestCase {assertFalse("final next", spans.next());}+ public void testSpanOrMovesForward() throws Exception {+ Spans spans = orSpans(new String[] {"w1", "xx"});++ spans.next();+ int doc = spans.doc();+ assertEquals(0, doc);++ spans.skipTo(0);+ doc = spans.doc();++ // LUCENE-1583:+ // according to Spans, a skipTo to the same doc or less+ // should still call next() on the underlying Spans+ assertEquals(1, doc);++ }+public void testSpanOrDouble() throws Exception {Spans spans = orSpans(new String[] {"w5", "yy"});tstNextSpans(spans, 0, 4, 5);