LUCENE-1583: SpanOrQuery skipTo() doesn't always move forwards as Spans documentation indicates it should.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@794063 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2009-07-14 20:56:50 +00:00
parent b393e4d0af
commit 6bf4d35ce8
3 changed files with 28 additions and 3 deletions

View File

@ -378,6 +378,9 @@ Bug fixes
18. LUCENE-1718: Fix termInfosIndexDivisor to carry over to reopened 18. LUCENE-1718: Fix termInfosIndexDivisor to carry over to reopened
readers (Mike McCandless) readers (Mike McCandless)
19. LUCENE-1583: SpanOrQuery skipTo() doesn't always move forwards as Spans
documentation indicates it should. (Moti Nisenson via Mark Miller)
New features New features

View File

@ -215,16 +215,21 @@ public class SpanOrQuery extends SpanQuery implements Cloneable {
if (queue == null) { if (queue == null) {
return initSpanQueue(target); return initSpanQueue(target);
} }
boolean skipCalled = false;
while (queue.size() != 0 && top().doc() < target) { while (queue.size() != 0 && top().doc() < target) {
if (top().skipTo(target)) { if (top().skipTo(target)) {
queue.adjustTop(); queue.adjustTop();
} else { } else {
queue.pop(); queue.pop();
} }
skipCalled = true;
} }
return queue.size() != 0; if (skipCalled) {
return queue.size() != 0;
}
return next();
} }
public int doc() { return top().doc(); } public int doc() { return top().doc(); }

View File

@ -331,6 +331,23 @@ public class TestSpans extends LuceneTestCase {
assertFalse("final next", spans.next()); 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 { public void testSpanOrDouble() throws Exception {
Spans spans = orSpans(new String[] {"w5", "yy"}); Spans spans = orSpans(new String[] {"w5", "yy"});
tstNextSpans(spans, 0, 4, 5); tstNextSpans(spans, 0, 4, 5);