Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-955: Fixed SegmentTermPositions to work correctly with the first term in the dictionary.

Michael Buschc8f84d670791
diff --git a/CHANGES.txt b/CHANGES.txt
index a8fbee97c87..ef1fa8cbeef 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -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
diff --git a/src/java/org/apache/lucene/index/SegmentTermPositions.java b/src/java/org/apache/lucene/index/SegmentTermPositions.java
index 982ea0468a5..9870e068143 100644
--- a/src/java/org/apache/lucene/index/SegmentTermPositions.java
+++ b/src/java/org/apache/lucene/index/SegmentTermPositions.java
@@ -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) {
diff --git a/src/test/org/apache/lucene/index/TestLazyProxSkipping.java b/src/test/org/apache/lucene/index/TestLazyProxSkipping.java
index 01994873f8a..abdfe2163ed 100755
--- a/src/test/org/apache/lucene/index/TestLazyProxSkipping.java
+++ b/src/test/org/apache/lucene/index/TestLazyProxSkipping.java
@@ -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()