mirror of https://github.com/apache/lucene.git
LUCENE-508: make sure SegmentTermEnum.prev() is accurate (= last term) after next() returns false
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@609780 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
eaba22c72a
commit
2677871bbb
|
@ -213,7 +213,11 @@ Bug fixes
|
|||
|
||||
28. LUCENE-749: ChainedFilter behavior fixed when logic of
|
||||
first filter is ANDNOT. (Antonio Bruno via Doron Cohen)
|
||||
|
||||
|
||||
29. LUCENE-508: Make sure SegmentTermEnum.prev() is accurate (= last
|
||||
term) after next() returns false. (Steven Tamm via Mike
|
||||
McCandless)
|
||||
|
||||
|
||||
New features
|
||||
|
||||
|
|
|
@ -114,6 +114,7 @@ final class SegmentTermEnum extends TermEnum implements Cloneable {
|
|||
/** Increments the enumeration to the next element. True if one exists.*/
|
||||
public final boolean next() throws IOException {
|
||||
if (position++ >= size - 1) {
|
||||
prevBuffer.set(termBuffer);
|
||||
termBuffer.reset();
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.apache.lucene.index.Term;
|
|||
import org.apache.lucene.index.TermEnum;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
import org.apache.lucene.store.MockRAMDirectory;
|
||||
|
||||
/**
|
||||
* @author goller
|
||||
|
@ -66,6 +67,23 @@ public class TestSegmentTermEnum extends LuceneTestCase
|
|||
verifyDocFreq();
|
||||
}
|
||||
|
||||
public void testPrevTermAtEnd() throws IOException
|
||||
{
|
||||
Directory dir = new MockRAMDirectory();
|
||||
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
||||
addDoc(writer, "aaa bbb");
|
||||
writer.close();
|
||||
IndexReader reader = IndexReader.open(dir);
|
||||
SegmentTermEnum termEnum = (SegmentTermEnum) reader.terms();
|
||||
assertTrue(termEnum.next());
|
||||
assertEquals("aaa", termEnum.term().text());
|
||||
assertTrue(termEnum.next());
|
||||
assertEquals("aaa", termEnum.prev().text());
|
||||
assertEquals("bbb", termEnum.term().text());
|
||||
assertFalse(termEnum.next());
|
||||
assertEquals("bbb", termEnum.prev().text());
|
||||
}
|
||||
|
||||
private void verifyDocFreq()
|
||||
throws IOException
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue