mirror of https://github.com/apache/lucene.git
LUCENE-955: Fixed SegmentTermPositions to work correctly with the first term in the dictionary.
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@555678 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
96ea45d193
commit
c8f84d6707
|
@ -20,6 +20,9 @@ Bug fixes
|
|||
1. LUCENE-933: QueryParser fixed to not produce empty sub
|
||||
BooleanQueries "()" even if the Analyzer proudced no
|
||||
tokens for input. (Doron Cohen)
|
||||
|
||||
2. LUCENE-955: Fixed SegmentTermPositions to work correctly with the
|
||||
first term in the dictionary. (Michael Busch)
|
||||
|
||||
New features
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ extends SegmentTermDocs implements TermPositions {
|
|||
|
||||
// these variables are being used to remember information
|
||||
// for a lazy skip
|
||||
private long lazySkipPointer = 0;
|
||||
private long lazySkipPointer = -1;
|
||||
private int lazySkipProxCount = 0;
|
||||
|
||||
SegmentTermPositions(SegmentReader p) {
|
||||
|
@ -152,9 +152,9 @@ extends SegmentTermDocs implements TermPositions {
|
|||
// if it was not read yet
|
||||
skipPayload();
|
||||
|
||||
if (lazySkipPointer != 0) {
|
||||
if (lazySkipPointer != -1) {
|
||||
proxStream.seek(lazySkipPointer);
|
||||
lazySkipPointer = 0;
|
||||
lazySkipPointer = -1;
|
||||
}
|
||||
|
||||
if (lazySkipProxCount != 0) {
|
||||
|
|
|
@ -98,7 +98,7 @@ public class TestLazyProxSkipping extends TestCase {
|
|||
assertEquals(numHits, hits.length());
|
||||
|
||||
// check if the number of calls of seek() does not exceed the number of hits
|
||||
assertEquals(numHits, this.seeksCounter);
|
||||
assertTrue(this.seeksCounter <= numHits + 1);
|
||||
}
|
||||
|
||||
public void testLazySkipping() throws IOException {
|
||||
|
@ -107,6 +107,34 @@ public class TestLazyProxSkipping extends TestCase {
|
|||
performTest(10);
|
||||
}
|
||||
|
||||
public void testSeek() throws IOException {
|
||||
Directory directory = new RAMDirectory();
|
||||
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Document doc = new Document();
|
||||
doc.add(new Field(this.field, "a b", Field.Store.YES, Field.Index.TOKENIZED));
|
||||
writer.addDocument(doc);
|
||||
}
|
||||
|
||||
writer.close();
|
||||
IndexReader reader = IndexReader.open(directory);
|
||||
TermPositions tp = reader.termPositions();
|
||||
tp.seek(new Term(this.field, "b"));
|
||||
for (int i = 0; i < 10; i++) {
|
||||
tp.next();
|
||||
assertEquals(tp.doc(), i);
|
||||
assertEquals(tp.nextPosition(), 1);
|
||||
}
|
||||
tp.seek(new Term(this.field, "a"));
|
||||
for (int i = 0; i < 10; i++) {
|
||||
tp.next();
|
||||
assertEquals(tp.doc(), i);
|
||||
assertEquals(tp.nextPosition(), 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Simply extends IndexInput in a way that we are able to count the number
|
||||
// of invocations of seek()
|
||||
|
|
Loading…
Reference in New Issue