You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/04/24 16:44:22 UTC

svn commit: r1589752 - in /lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index: CheckIndex.java Terms.java

Author: mikemccand
Date: Thu Apr 24 14:44:22 2014
New Revision: 1589752

URL: http://svn.apache.org/r1589752
Log:
LUCENE-5610: improve CheckIndex checking; javadocs

Modified:
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/Terms.java

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java?rev=1589752&r1=1589751&r2=1589752&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java Thu Apr 24 14:44:22 2014
@@ -758,12 +758,28 @@ public class CheckIndex {
       final boolean hasOffsets = terms.hasOffsets();
       
       BytesRef bb = terms.getMin();
-      assert bb.isValid();
-      final BytesRef minTerm = bb == null ? null : BytesRef.deepCopyOf(bb);
-      
+      BytesRef minTerm;
+      if (bb != null) {
+        assert bb.isValid();
+        minTerm = BytesRef.deepCopyOf(bb);
+      } else {
+        minTerm = null;
+      }
+
+      BytesRef maxTerm;
       bb = terms.getMax();
-      assert bb.isValid();
-      final BytesRef maxTerm = bb == null ? null : BytesRef.deepCopyOf(bb);
+      if (bb != null) {
+        assert bb.isValid();
+        maxTerm = BytesRef.deepCopyOf(bb);
+        if (minTerm == null) {
+          throw new RuntimeException("field \"" + field + "\" has null minTerm but non-null maxTerm");
+        }
+      } else {
+        maxTerm = null;
+        if (minTerm != null) {
+          throw new RuntimeException("field \"" + field + "\" has non-null minTerm but null maxTerm");
+        }
+      }
 
       // term vectors cannot omit TF:
       final boolean expectedHasFreqs = (isVectors || fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS) >= 0);
@@ -825,12 +841,18 @@ public class CheckIndex {
           lastTerm.copyBytes(term);
         }
         
+        if (minTerm == null) {
+          // We checked this above:
+          assert maxTerm == null;
+          throw new RuntimeException("field=\"" + field + "\": invalid term: term=" + term + ", minTerm=" + minTerm);
+        }
+        
         if (term.compareTo(minTerm) < 0) {
-          throw new RuntimeException("invalid term: term=" + term + ", minTerm=" + minTerm);
+          throw new RuntimeException("field=\"" + field + "\": invalid term: term=" + term + ", minTerm=" + minTerm);
         }
         
         if (term.compareTo(maxTerm) > 0) {
-          throw new RuntimeException("invalid term: term=" + term + ", maxTerm=" + maxTerm);
+          throw new RuntimeException("field=\"" + field + "\": invalid term: term=" + term + ", maxTerm=" + maxTerm);
         }
         
         final int docFreq = termsEnum.docFreq();
@@ -1080,6 +1102,10 @@ public class CheckIndex {
         }
       }
       
+      if (minTerm != null && status.termCount + status.delTermCount == 0) {
+        throw new RuntimeException("field=\"" + field + "\": minTerm is non-null yet we saw no terms: " + minTerm);
+      }
+
       final Terms fieldTerms = fields.terms(field);
       if (fieldTerms == null) {
         // Unusual: the FieldsEnum returned a field but

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/Terms.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/Terms.java?rev=1589752&r1=1589751&r2=1589752&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/Terms.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/Terms.java Thu Apr 24 14:44:22 2014
@@ -120,14 +120,16 @@ public abstract class Terms {
   
   /** Returns the smallest term (in lexicographic order) in the field. 
    *  Note that, just like other term measures, this measure does not 
-   *  take deleted documents into account. */
+   *  take deleted documents into account.  This returns
+   *  null when there are no terms. */
   public BytesRef getMin() throws IOException {
     return iterator(null).next();
   }
 
   /** Returns the largest term (in lexicographic order) in the field. 
    *  Note that, just like other term measures, this measure does not 
-   *  take deleted documents into account. */
+   *  take deleted documents into account.  This returns
+   *  null when there are no terms. */
   @SuppressWarnings("fallthrough")
   public BytesRef getMax() throws IOException {
     long size = size();