Apache Lucene open-source search software
LUCENE-6256: Change PostingsEnum.nextPosition() to consistently return -1 when positions are not available
Ryan Ernstd3e7357d288c
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex e87d70cf8c2..1e486bc1fda 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -127,6 +127,10 @@ API Changes* LUCENE-6245: Force Filter subclasses to implement toString API from Query.(Ryan Ernst)+* LUCENE-6256: Change PostingsEnum.nextPosition() to consistently return -1 when+ positions are not available.+ (Ryan Ernst)+Other* LUCENE-6248: Remove unused odd constants from StandardSyntaxParser.jjdiff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java b/lucene/codecs/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.javaindex 8fe30388fdb..47902067127 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/memory/DirectPostingsFormat.java@@ -1566,7 +1566,6 @@ public final class DirectPostingsFormat extends PostingsFormat {@Overridepublic int nextPosition() throws IOException {- assert false : "Shouldn't be calling nextPosition() if you haven't asked for positions";return -1;}@@ -1655,7 +1654,6 @@ public final class DirectPostingsFormat extends PostingsFormat {@Overridepublic int nextPosition() throws IOException {- assert false : "Shouldn't be calling nextPosition() if you haven't asked for positions";return -1;}@@ -1760,7 +1758,6 @@ public final class DirectPostingsFormat extends PostingsFormat {@Overridepublic int nextPosition() throws IOException {- assert false : "should be using LowFreqDocsAndPositionsEnum";return -1;}diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.javaindex 13d16c0d8bf..2c5eb4dfba8 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextFieldsReader.java@@ -278,7 +278,6 @@ class SimpleTextFieldsReader extends FieldsProducer {@Overridepublic int nextPosition() throws IOException {- assert false : "Shouldn't be calling nextPosition() if you haven't asked for positions";return -1;}diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextTermVectorsReader.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextTermVectorsReader.javaindex 55997442adb..b8d74e3302c 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextTermVectorsReader.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextTermVectorsReader.java@@ -423,7 +423,6 @@ public class SimpleTextTermVectorsReader extends TermVectorsReader {@Overridepublic int nextPosition() throws IOException {- assert false;return -1;}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50PostingsReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50PostingsReader.javaindex c15fa0c5240..aa28d973727 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50PostingsReader.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50PostingsReader.java@@ -336,7 +336,6 @@ public final class Lucene50PostingsReader extends PostingsReaderBase {@Overridepublic int nextPosition() throws IOException {- assert false; // shouldn't be calling nextPosition() on thisreturn -1;}diff --git a/lucene/core/src/java/org/apache/lucene/index/FreqProxFields.java b/lucene/core/src/java/org/apache/lucene/index/FreqProxFields.javaindex a672e444ced..6d319b794e4 100644--- a/lucene/core/src/java/org/apache/lucene/index/FreqProxFields.java+++ b/lucene/core/src/java/org/apache/lucene/index/FreqProxFields.java@@ -345,7 +345,6 @@ class FreqProxFields extends Fields {@Overridepublic int nextPosition() throws IOException {- assert false : "Shouldn't be calling nextPositions on DocsEnum";return -1;}diff --git a/lucene/core/src/java/org/apache/lucene/index/PostingsEnum.java b/lucene/core/src/java/org/apache/lucene/index/PostingsEnum.javaindex 4dfb19e43ce..fe8418ced87 100644--- a/lucene/core/src/java/org/apache/lucene/index/PostingsEnum.java+++ b/lucene/core/src/java/org/apache/lucene/index/PostingsEnum.java@@ -92,9 +92,9 @@ public abstract class PostingsEnum extends DocIdSetIterator {}/**- * Returns the next position. If there are no more- * positions, or the iterator does not support positions,- * this will return DocsEnum.NO_MORE_POSITIONS */+ * Returns the next position, or -1 if positions were not indexed.+ * Calling this more than {@link #freq()} times is undefined.+ */public abstract int nextPosition() throws IOException;/** Returns start offset for the current position, or -1diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.javaindex daf6aa558b2..6779713c8f2 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java@@ -231,7 +231,7 @@ public abstract class BasePostingsFormatTestCase extends BaseIndexFileFormatTestpublic int nextPosition() {if (!doPositions) {posUpto = freq;- return 0;+ return -1;}assert posUpto < freq;