Apache Lucene open-source search software
LUCENE-2696: fix sep bug when some fields have payloads and others don't and you reuse the d&p enum
Michael McCandless3fc915a06980
diff --git a/lucene/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/src/java/org/apache/lucene/index/IndexWriter.javaindex e9b68b4f4e9..91dfdffa910 100644--- a/lucene/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/src/java/org/apache/lucene/index/IndexWriter.java@@ -686,7 +686,7 @@ public class IndexWriter implements Closeable {* Used internally to throw an {@link* AlreadyClosedException} if this IndexWriter has been* closed.- * @throws AlreadyClosedException if this IndexWriter is+ * @throws AlreadyClosedException if this IndexWriter is closed*/protected final void ensureOpen(boolean includePendingClose) throws AlreadyClosedException {if (closed || (includePendingClose && closing)) {diff --git a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsReaderImpl.java b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsReaderImpl.javaindex 73a3639d38b..7aab6816e92 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsReaderImpl.java+++ b/lucene/src/java/org/apache/lucene/index/codecs/sep/SepPostingsReaderImpl.java@@ -504,6 +504,7 @@ public class SepPostingsReaderImpl extends PostingsReaderBase {posIndex.set(termState.posIndex);posSeekPending = true;//posIndex.seek(posReader);+ payloadPending = false;skipOffset = termState.skipOffset;payloadOffset = termState.payloadOffset;@@ -640,7 +641,6 @@ public class SepPostingsReaderImpl extends PostingsReaderBase {assert payloadLength >= 0;}pendingPosCount--;- payloadPending = true;position = 0;pendingPayloadBytes += payloadLength;}@@ -653,14 +653,13 @@ public class SepPostingsReaderImpl extends PostingsReaderBase {assert payloadLength >= 0;}position += code >> 1;+ pendingPayloadBytes += payloadLength;+ payloadPending = payloadLength > 0;} else {position += code;}- pendingPayloadBytes += payloadLength;- payloadPending = payloadLength > 0;pendingPosCount--;- payloadPending = true;assert pendingPosCount >= 0;return position;}diff --git a/lucene/src/test/org/apache/lucene/index/TestPayloads.java b/lucene/src/test/org/apache/lucene/index/TestPayloads.javaindex debaf354a9d..39df3638884 100644--- a/lucene/src/test/org/apache/lucene/index/TestPayloads.java+++ b/lucene/src/test/org/apache/lucene/index/TestPayloads.java@@ -245,8 +245,8 @@ public class TestPayloads extends LuceneTestCase {for (int i = 0; i < freq; i++) {for (int j = 0; j < numTerms; j++) {tps[j].nextPosition();- BytesRef br = tps[j].getPayload();- if (br != null) {+ if (tps[j].hasPayload()) {+ BytesRef br = tps[j].getPayload();System.arraycopy(br.bytes, br.offset, verifyPayloadData, offset, br.length);offset += br.length;}@@ -604,4 +604,27 @@ public class TestPayloads extends LuceneTestCase {return pool.size();}}++ public void testAcrossFields() throws Exception {+ Directory dir = newDirectory();+ RandomIndexWriter writer = new RandomIndexWriter(random, dir,+ new MockAnalyzer(MockTokenizer.WHITESPACE, true, true));+ Document doc = new Document();+ doc.add(new Field("haspayload", "here we go", Field.Store.YES, Field.Index.ANALYZED));+ writer.addDocument(doc);+ writer.close();++ writer = new RandomIndexWriter(random, dir,+ new MockAnalyzer(MockTokenizer.WHITESPACE, true, false));+ doc = new Document();+ doc.add(new Field("nopayload", "here we go", Field.Store.YES, Field.Index.ANALYZED));+ writer.addDocument(doc);+ writer.addDocument(doc);+ writer.optimize();+ writer.close();++ _TestUtil.checkIndex(dir);++ dir.close();+ }}diff --git a/lucene/src/test/org/apache/lucene/search/QueryUtils.java b/lucene/src/test/org/apache/lucene/search/QueryUtils.javaindex 8a4266b8525..1c8b7a7b8a3 100644--- a/lucene/src/test/org/apache/lucene/search/QueryUtils.java+++ b/lucene/src/test/org/apache/lucene/search/QueryUtils.java@@ -399,7 +399,7 @@ public class QueryUtils {public void collect(int doc) throws IOException {float score = scorer.score();try {-+ long startMS = System.currentTimeMillis();for (int i=lastDoc[0]+1; i<=doc; i++) {Weight w = q.weight(s);Scorer scorer = w.scorer(reader, true, false);@@ -408,6 +408,12 @@ public class QueryUtils {float skipToScore = scorer.score();Assert.assertEquals("unstable skipTo("+i+") score!",skipToScore,scorer.score(),maxDiff);Assert.assertEquals("query assigned doc "+doc+" a score of <"+score+"> but skipTo("+i+") has <"+skipToScore+">!",score,skipToScore,maxDiff);++ // Hurry things along if they are going slow (eg+ // if you got SimpleText codec this will kick in):+ if (i < doc && System.currentTimeMillis() - startMS > 5) {+ i = doc-1;+ }}lastDoc[0] = doc;} catch (IOException e) {