Apache Lucene open-source search software
Don't allow negatives in the positions file
Robert Muird0dd5fadcc90
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 7b636380280..7030490cc5c 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -31,6 +31,11 @@ Bug Fixeshad a custom Similarity where coord(1,1) != 1F, then the rewrittenquery would be scored differently. (Robert Muir)+* Don't allow negatives in the positions file. If you have an index+ from 2.4.0 or earlier with such negative positions, and you already+ upgraded to 3.x, then to Lucene 4.0-ALPHA or -BETA, you should run+ CheckIndex. If it fails, then you need to upgrade again to 4.0 (Robert Muir)+======================= Lucene 4.0.0-BETA =======================New featuresdiff --git a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.javaindex d71c8e6bf27..3bcf7d17ff2 100644--- a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java+++ b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java@@ -822,11 +822,8 @@ public class CheckIndex {if (hasPositions) {for(int j=0;j<freq;j++) {final int pos = postings.nextPosition();- // NOTE: pos=-1 is allowed because of ancient bug- // (LUCENE-1542) whereby IndexWriter could- // write pos=-1 when first token's posInc is 0- if (pos < -1) {+ if (pos < 0) {throw new RuntimeException("term " + term + ": doc " + doc + ": pos " + pos + " is out of bounds");}if (pos < lastPos) {@@ -919,14 +916,8 @@ public class CheckIndex {int lastOffset = 0;for(int posUpto=0;posUpto<freq;posUpto++) {final int pos = postings.nextPosition();- // NOTE: pos=-1 is allowed because of ancient bug- // (LUCENE-1542) whereby IndexWriter could- // write pos=-1 when first token's posInc is 0- // (separately: analyzers should not give- // posInc=0 to first token); also, term- // vectors are allowed to return pos=-1 if- // they indexed offset but not positions:- if (pos < -1) {++ if (pos < 0) {throw new RuntimeException("position " + pos + " is out of bounds");}if (pos < lastPosition) {@@ -1498,7 +1489,7 @@ public class CheckIndex {int pos = postings.nextPosition();if (postingsPostings != null) {int postingsPos = postingsPostings.nextPosition();- if (pos != -1 && postingsPos != -1 && pos != postingsPos) {+ if (terms.hasPositions() && pos != postingsPos) {throw new RuntimeException("vector term=" + term + " field=" + field + " doc=" + j + ": pos=" + pos + " differs from postings pos=" + postingsPos);}}