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

@ -379,6 +379,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
1. LUCENE-1411: Added expert API to open an IndexWriter on a prior 1. LUCENE-1411: Added expert API to open an IndexWriter on a prior

View File

@ -216,16 +216,21 @@ public class SpanOrQuery extends SpanQuery implements Cloneable {
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;
} }
if (skipCalled) {
return queue.size() != 0; return queue.size() != 0;
} }
return next();
}
public int doc() { return top().doc(); } public int doc() { return top().doc(); }
public int start() { return top().start(); } public int start() { return top().start(); }

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);