lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1201671 - in /lucene/dev/branches/lucene2621: lucene/ lucene/contrib/memory/src/java/org/apache/lucene/index/memory/ lucene/contrib/misc/src/java/org/apache/lucene/misc/ lucene/src/java/org/apache/lucene/index/ lucene/src/java/org/apache/l...
Date Mon, 14 Nov 2011 11:45:44 GMT
Author: mikemccand
Date: Mon Nov 14 11:45:42 2011
New Revision: 1201671

URL: http://svn.apache.org/viewvc?rev=1201671&view=rev
Log:
LUCENE-2621: FieldsEnum.terms now returns Terms not TermsEnum

Modified:
    lucene/dev/branches/lucene2621/lucene/common-build.xml
    lucene/dev/branches/lucene2621/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
    lucene/dev/branches/lucene2621/lucene/contrib/misc/src/java/org/apache/lucene/misc/HighFreqTerms.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/CheckIndex.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/FieldsEnum.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/MultiFields.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/MultiFieldsEnum.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/ParallelReader.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/Terms.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/BlockTermsReader.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsReader.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/DefaultTermVectorsReader.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/FieldsConsumer.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/TermVectorsWriter.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/lucene3x/Lucene3xFields.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/memory/MemoryPostingsFormat.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/perfield/PerFieldPostingsFormat.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextFieldsReader.java
    lucene/dev/branches/lucene2621/lucene/src/test-framework/java/org/apache/lucene/index/codecs/ramonly/RAMOnlyPostingsFormat.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestCodecs.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestDoc.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestIndexReader.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestParallelTermEnum.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestSegmentReader.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/codecs/lucene3x/TestSurrogates.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/codecs/lucene3x/TestTermInfosReaderIndex.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestMultiThreadTermVectors.java
    lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestTermVectors.java
    lucene/dev/branches/lucene2621/modules/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
    lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java
    lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/handler/component/TermVectorComponent.java

Modified: lucene/dev/branches/lucene2621/lucene/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/common-build.xml?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/common-build.xml (original)
+++ lucene/dev/branches/lucene2621/lucene/common-build.xml Mon Nov 14 11:45:42 2011
@@ -808,7 +808,7 @@
         <!-- <compilerarg line="-Xmaxwarns 10000000"/>
         <compilerarg line="-Xmaxerrs 10000000"/> -->
         <!-- for generics in Java 1.5: -->
-        <compilerarg line="-Xlint -Xlint:-deprecation -Xlint:-serial"/>
+	<compilerarg line="-Xlint -Xlint:-deprecation -Xlint:-serial"/>
       </javac>
     </sequential>
   </macrodef>

Modified: lucene/dev/branches/lucene2621/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java (original)
+++ lucene/dev/branches/lucene2621/lucene/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java Mon Nov 14 11:45:42 2011
@@ -779,85 +779,85 @@ public class MemoryIndex {
     public ReaderContext getTopReaderContext() {
       return readerInfos;
     }
-  
-    @Override
-    public Fields fields() {
 
-      sortFields();
+    private class MemoryFields extends Fields {
+      @Override
+      public FieldsEnum iterator() {
+        return new FieldsEnum() {
+          int upto = -1;
+
+          @Override
+          public String next() {
+            upto++;
+            if (upto >= sortedFields.length) {
+              return null;
+            }
+            return sortedFields[upto].getKey();
+          }
+
+          @Override
+          public Terms terms() {
+            return MemoryFields.this.terms(sortedFields[upto].getKey());
+          }
+        };
+      }
 
-      return new Fields() {
-        @Override
-        public FieldsEnum iterator() {
-          return new FieldsEnum() {
-            int upto = -1;
+      @Override
+      public Terms terms(final String field) {
+        int i = Arrays.binarySearch(sortedFields, field, termComparator);
+        if (i < 0) {
+          return null;
+        } else {
+          final Info info = getInfo(i);
+          info.sortTerms();
+
+          return new Terms() {
+            @Override 
+            public TermsEnum iterator() {
+              return new MemoryTermsEnum(info);
+            }
 
             @Override
-            public String next() {
-              upto++;
-              if (upto >= sortedFields.length) {
-                return null;
-              }
-              return sortedFields[upto].getKey();
+            public Comparator<BytesRef> getComparator() {
+              return BytesRef.getUTF8SortedAsUnicodeComparator();
             }
 
             @Override
-            public TermsEnum terms() {
-              return new MemoryTermsEnum(sortedFields[upto].getValue());
+            public long getUniqueTermCount() {
+              return info.sortedTerms.length;
             }
-          };
-        }
 
-        @Override
-        public Terms terms(final String field) {
-          int i = Arrays.binarySearch(sortedFields, field, termComparator);
-          if (i < 0) {
-            return null;
-          } else {
-            final Info info = getInfo(i);
-            info.sortTerms();
+            @Override
+            public long getSumTotalTermFreq() {
+              return info.getSumTotalTermFreq();
+            }
+
+            @Override
+            public long getSumDocFreq() throws IOException {
+              // each term has df=1
+              return info.sortedTerms.length;
+            }
 
-            return new Terms() {
-              @Override 
-              public TermsEnum iterator() {
-                return new MemoryTermsEnum(info);
-              }
-
-              @Override
-              public Comparator<BytesRef> getComparator() {
-                return BytesRef.getUTF8SortedAsUnicodeComparator();
-              }
-
-              @Override
-              public long getUniqueTermCount() {
-                return info.sortedTerms.length;
-              }
-
-              @Override
-              public long getSumTotalTermFreq() {
-                return info.getSumTotalTermFreq();
-              }
-
-              @Override
-              public long getSumDocFreq() throws IOException {
-                // each term has df=1
-                return info.sortedTerms.length;
-              }
-
-              @Override
-              public int getDocCount() throws IOException {
-                return info.sortedTerms.length > 0 ? 1 : 0;
-              }
+            @Override
+            public int getDocCount() throws IOException {
+              return info.sortedTerms.length > 0 ? 1 : 0;
+            }
               
               
-            };
-          }
+          };
         }
+      }
 
-        @Override
-        public int getUniqueFieldCount() {
-          return sortedFields.length;
-        }
-      };
+      @Override
+      public int getUniqueFieldCount() {
+        return sortedFields.length;
+      }
+    }
+  
+    @Override
+    public Fields fields() {
+      sortFields();
+      return new MemoryFields();
     }
 
     private class MemoryTermsEnum extends TermsEnum {

Modified: lucene/dev/branches/lucene2621/lucene/contrib/misc/src/java/org/apache/lucene/misc/HighFreqTerms.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/contrib/misc/src/java/org/apache/lucene/misc/HighFreqTerms.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/contrib/misc/src/java/org/apache/lucene/misc/HighFreqTerms.java (original)
+++ lucene/dev/branches/lucene2621/lucene/contrib/misc/src/java/org/apache/lucene/misc/HighFreqTerms.java Mon Nov 14 11:45:42 2011
@@ -131,8 +131,10 @@ public class HighFreqTerms {
       while (true) {
         field = fieldsEnum.next();
         if (field != null) {
-          TermsEnum terms = fieldsEnum.terms();
-          fillQueue(terms, tiq, field);
+          Terms terms = fieldsEnum.terms();
+          if (terms != null) {
+            fillQueue(terms.iterator(), tiq, field);
+          }
         } else {
           break;
         }

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/CheckIndex.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/CheckIndex.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/CheckIndex.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/CheckIndex.java Mon Nov 14 11:45:42 2011
@@ -697,8 +697,13 @@ public class CheckIndex {
         // assert fields.terms(field) != null;
         computedFieldCount++;
         
-        final TermsEnum terms = fieldsEnum.terms();
-        assert terms != null;
+        final Terms terms = fieldsEnum.terms();
+        if (terms == null) {
+          continue;
+        }
+
+        final TermsEnum termsEnum = terms.iterator();
+
         boolean hasOrd = true;
         final long termCountStart = status.termCount;
 
@@ -711,7 +716,7 @@ public class CheckIndex {
         FixedBitSet visitedDocs = new FixedBitSet(reader.maxDoc());
         while(true) {
 
-          final BytesRef term = terms.next();
+          final BytesRef term = termsEnum.next();
           if (term == null) {
             break;
           }
@@ -727,20 +732,20 @@ public class CheckIndex {
             lastTerm.copy(term);
           }
 
-          final int docFreq = terms.docFreq();
+          final int docFreq = termsEnum.docFreq();
           if (docFreq <= 0) {
             throw new RuntimeException("docfreq: " + docFreq + " is out of bounds");
           }
           status.totFreq += docFreq;
           sumDocFreq += docFreq;
 
-          docs = terms.docs(liveDocs, docs);
-          postings = terms.docsAndPositions(liveDocs, postings);
+          docs = termsEnum.docs(liveDocs, docs);
+          postings = termsEnum.docsAndPositions(liveDocs, postings);
 
           if (hasOrd) {
             long ord = -1;
             try {
-              ord = terms.ord();
+              ord = termsEnum.ord();
             } catch (UnsupportedOperationException uoe) {
               hasOrd = false;
             }
@@ -809,12 +814,12 @@ public class CheckIndex {
             }
           }
           
-          final long totalTermFreq2 = terms.totalTermFreq();
+          final long totalTermFreq2 = termsEnum.totalTermFreq();
           final boolean hasTotalTermFreq = postings != null && totalTermFreq2 != -1;
 
           // Re-count if there are deleted docs:
           if (reader.hasDeletions()) {
-            final DocsEnum docsNoDel = terms.docs(null, docs);
+            final DocsEnum docsNoDel = termsEnum.docs(null, docs);
             docCount = 0;
             totalTermFreq = 0;
             while(docsNoDel.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
@@ -841,7 +846,7 @@ public class CheckIndex {
           if (hasPositions) {
             for(int idx=0;idx<7;idx++) {
               final int skipDocID = (int) (((idx+1)*(long) maxDoc)/8);
-              postings = terms.docsAndPositions(liveDocs, postings);
+              postings = termsEnum.docsAndPositions(liveDocs, postings);
               final int docID = postings.advance(skipDocID);
               if (docID == DocsEnum.NO_MORE_DOCS) {
                 break;
@@ -877,7 +882,7 @@ public class CheckIndex {
           } else {
             for(int idx=0;idx<7;idx++) {
               final int skipDocID = (int) (((idx+1)*(long) maxDoc)/8);
-              docs = terms.docs(liveDocs, docs);
+              docs = termsEnum.docs(liveDocs, docs);
               final int docID = docs.advance(skipDocID);
               if (docID == DocsEnum.NO_MORE_DOCS) {
                 break;
@@ -905,7 +910,8 @@ public class CheckIndex {
           // no terms, eg there used to be terms but all
           // docs got deleted and then merged away):
           // make sure TermsEnum is empty:
-          if (fieldsEnum.terms().next() != null) {
+          final Terms fieldTerms2 = fieldsEnum.terms();
+          if (fieldTerms2 != null && fieldTerms2.iterator().next() != null) {
             throw new RuntimeException("Fields.terms(field=" + field + ") returned null yet the field appears to have terms");
           }
         } else {
@@ -932,16 +938,16 @@ public class CheckIndex {
             }
           }
         
-        if (fieldTerms != null) {
-          final int v = fieldTerms.getDocCount();
-          if (v != -1 && visitedDocs.cardinality() != v) {
-            throw new RuntimeException("docCount for field " + field + "=" + v + " != recomputed docCount=" + visitedDocs.cardinality());
+          if (fieldTerms != null) {
+            final int v = fieldTerms.getDocCount();
+            if (v != -1 && visitedDocs.cardinality() != v) {
+              throw new RuntimeException("docCount for field " + field + "=" + v + " != recomputed docCount=" + visitedDocs.cardinality());
+            }
           }
-        }
 
           // Test seek to last term:
           if (lastTerm != null) {
-            if (terms.seekCeil(lastTerm) != TermsEnum.SeekStatus.FOUND) { 
+            if (termsEnum.seekCeil(lastTerm) != TermsEnum.SeekStatus.FOUND) { 
               throw new RuntimeException("seek to last term " + lastTerm + " failed");
             }
 
@@ -968,18 +974,18 @@ public class CheckIndex {
               // Seek by ord
               for(int i=seekCount-1;i>=0;i--) {
                 long ord = i*(termCount/seekCount);
-                terms.seekExact(ord);
-                seekTerms[i] = new BytesRef(terms.term());
+                termsEnum.seekExact(ord);
+                seekTerms[i] = new BytesRef(termsEnum.term());
               }
 
               // Seek by term
               long totDocCount = 0;
               for(int i=seekCount-1;i>=0;i--) {
-                if (terms.seekCeil(seekTerms[i]) != TermsEnum.SeekStatus.FOUND) {
+                if (termsEnum.seekCeil(seekTerms[i]) != TermsEnum.SeekStatus.FOUND) {
                   throw new RuntimeException("seek to existing term " + seekTerms[i] + " failed");
                 }
               
-                docs = terms.docs(liveDocs, docs);
+                docs = termsEnum.docs(liveDocs, docs);
                 if (docs == null) {
                   throw new RuntimeException("null DocsEnum from to existing term " + seekTerms[i]);
                 }

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/FieldsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/FieldsEnum.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/FieldsEnum.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/FieldsEnum.java Mon Nov 14 11:45:42 2011
@@ -47,12 +47,16 @@ public abstract class FieldsEnum {
    * null when there are no more fields.*/
   public abstract String next() throws IOException;
 
-  /** Get {@link TermsEnum} for the current field.  You
-   *  should not call {@link #next} until you're done using
-   *  this {@link TermsEnum}.  After {@link #next} returns
-   *  null this method should not be called. This method
-   *  will not return null. */
-  public abstract TermsEnum terms() throws IOException;
+  // TODO: would be nice to require/fix all impls so they
+  // never return null here... we have to fix the writers to
+  // never write 0-terms fields... or maybe allow a non-null
+  // Terms instance in just this case
+
+  /** Get {@link Terms} for the current field.  After {@link #next} returns
+   *  null this method should not be called. This method may
+   *  return null in some cases, which means the provided
+   *  field does not have any terms. */
+  public abstract Terms terms() throws IOException;
 
   // TODO: should we allow pulling Terms as well?  not just
   // the iterator?
@@ -68,7 +72,7 @@ public abstract class FieldsEnum {
     }
 
     @Override
-    public TermsEnum terms() {
+    public Terms terms() {
       throw new IllegalStateException("this method should never be called");
     }
   };

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/FilterIndexReader.java Mon Nov 14 11:45:42 2011
@@ -134,7 +134,7 @@ public class FilterIndexReader extends I
     }
 
     @Override
-    public TermsEnum terms() throws IOException {
+    public Terms terms() throws IOException {
       return in.terms();
     }
   }

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/MultiFields.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/MultiFields.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/MultiFields.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/MultiFields.java Mon Nov 14 11:45:42 2011
@@ -193,7 +193,8 @@ public final class MultiFields extends F
     if (fieldsEnums.size() == 0) {
       return FieldsEnum.EMPTY;
     } else {
-      return new MultiFieldsEnum(fieldsEnums.toArray(FieldsEnum.EMPTY_ARRAY),
+      return new MultiFieldsEnum(this,
+                                 fieldsEnums.toArray(FieldsEnum.EMPTY_ARRAY),
                                  fieldsSlices.toArray(ReaderUtil.Slice.EMPTY_ARRAY));
     }
   }

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/MultiFieldsEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/MultiFieldsEnum.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/MultiFieldsEnum.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/MultiFieldsEnum.java Mon Nov 14 11:45:42 2011
@@ -47,12 +47,14 @@ public final  class MultiFieldsEnum exte
   private final MultiTermsEnum terms;
   private final MultiIndexDocValues docValues;
 
+  private final Fields fields;
 
   private String currentField;
 
   /** The subs array must be newly initialized FieldsEnum
    *  (ie, {@link FieldsEnum#next} has not been called. */
-  public MultiFieldsEnum(FieldsEnum[] subs, ReaderUtil.Slice[] subSlices) throws IOException {
+  public MultiFieldsEnum(MultiFields fields, FieldsEnum[] subs, ReaderUtil.Slice[] subSlices) throws IOException {
+    this.fields = fields;
     terms = new MultiTermsEnum(subSlices);
     queue = new FieldMergeQueue(subs.length);
     docValues = new MultiIndexDocValues();
@@ -107,20 +109,9 @@ public final  class MultiFieldsEnum exte
   }
 
   @Override
-  public TermsEnum terms() throws IOException {
-    final List<MultiTermsEnum.TermsEnumIndex> termsEnums = new ArrayList<MultiTermsEnum.TermsEnumIndex>();
-    for(int i=0;i<numTop;i++) {
-      final TermsEnum terms = top[i].fields.terms();
-      if (terms != null) {
-        termsEnums.add(new MultiTermsEnum.TermsEnumIndex(terms, top[i].index));
-      }
-    }
-
-    if (termsEnums.size() == 0) {
-      return TermsEnum.EMPTY;
-    } else {
-      return terms.reset(termsEnums.toArray(MultiTermsEnum.TermsEnumIndex.EMPTY_ARRAY));
-    }
+  public Terms terms() throws IOException {
+    // Ask our parent MultiFields:
+    return fields.terms(currentField);
   }
 
   public final static class FieldsEnumWithSlice {

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/ParallelReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/ParallelReader.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/ParallelReader.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/ParallelReader.java Mon Nov 14 11:45:42 2011
@@ -131,10 +131,9 @@ public class ParallelReader extends Inde
     for (final String field : fields) {               // update fieldToReader map
       if (fieldToReader.get(field) == null) {
         fieldToReader.put(field, reader);
+        this.fields.addField(field, MultiFields.getFields(reader).terms(field));
+        this.perDocs.addField(field, reader);
       }
-
-      this.fields.addField(field, MultiFields.getFields(reader).terms(field));
-      this.perDocs.addField(field, reader);
     }
 
     if (!ignoreStoredFields)
@@ -152,7 +151,6 @@ public class ParallelReader extends Inde
 
   private class ParallelFieldsEnum extends FieldsEnum {
     String currentField;
-    IndexReader currentReader;
     Iterator<String> keys;
 
     ParallelFieldsEnum() {
@@ -163,23 +161,15 @@ public class ParallelReader extends Inde
     public String next() throws IOException {
       if (keys.hasNext()) {
         currentField = keys.next();
-        currentReader = fieldToReader.get(currentField);
       } else {
         currentField = null;
-        currentReader = null;
       }
       return currentField;
     }
 
     @Override
-    public TermsEnum terms() throws IOException {
-      assert currentReader != null;
-      Terms terms = MultiFields.getTerms(currentReader, currentField);
-      if (terms != null) {
-        return terms.iterator();
-      } else {
-        return TermsEnum.EMPTY;
-      }
+    public Terms terms() throws IOException {
+      return ParallelReader.this.fields.terms(currentField);
     }
 
   }

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/Terms.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/Terms.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/Terms.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/Terms.java Mon Nov 14 11:45:42 2011
@@ -38,6 +38,7 @@ public abstract class Terms {
 
   /** Returns an iterator that will step through all
    *  terms. This method will not return null.*/
+  // nocommit add reuse required param
   public abstract TermsEnum iterator() throws IOException;
 
   /** Returns a TermsEnum that iterates over all terms that

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/BlockTermsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/BlockTermsReader.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/BlockTermsReader.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/BlockTermsReader.java Mon Nov 14 11:45:42 2011
@@ -233,8 +233,8 @@ public class BlockTermsReader extends Fi
     }
     
     @Override
-    public TermsEnum terms() throws IOException {
-      return current.iterator();
+    public Terms terms() throws IOException {
+      return current;
     }
   }
 

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsReader.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsReader.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsReader.java Mon Nov 14 11:45:42 2011
@@ -244,8 +244,8 @@ public class BlockTreeTermsReader extend
     }
     
     @Override
-    public TermsEnum terms() throws IOException {
-      return current.iterator();
+    public Terms terms() throws IOException {
+      return current;
     }
   }
 

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/DefaultTermVectorsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/DefaultTermVectorsReader.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/DefaultTermVectorsReader.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/DefaultTermVectorsReader.java Mon Nov 14 11:45:42 2011
@@ -293,10 +293,8 @@ public class DefaultTermVectorsReader ex
         }
 
         @Override
-        public TermsEnum terms() throws IOException {
-          tvf.seek(fieldFPs[fieldUpto-1]);
-          final int numTerms = tvf.readVInt();
-          return new TVTermsEnum(numTerms);
+        public Terms terms() throws IOException {
+          return TVFields.this.terms(fieldInfos.fieldName(fieldNumbers[fieldUpto-1]));
         }
       };
     }
@@ -333,6 +331,7 @@ public class DefaultTermVectorsReader ex
     private final long tvfFPStart;
 
     public TVTerms(long tvfFP) throws IOException {
+      // nocommit -- to be "safe" we should clone tvf here...?
       tvf.seek(tvfFP);
       numTerms = tvf.readVInt();
       tvfFPStart = tvf.getFilePointer();

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/FieldsConsumer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/FieldsConsumer.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/FieldsConsumer.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/FieldsConsumer.java Mon Nov 14 11:45:42 2011
@@ -17,14 +17,14 @@ package org.apache.lucene.index.codecs;
  * limitations under the License.
  */
 
+import java.io.Closeable;
+import java.io.IOException;
+
 import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.Fields;
 import org.apache.lucene.index.FieldsEnum;
 import org.apache.lucene.index.MergeState;
-import org.apache.lucene.index.TermsEnum;
-
-import java.io.IOException;
-import java.io.Closeable;
+import org.apache.lucene.index.Terms;
 
 /** Abstract API that consumes terms, doc, freq, prox and
  *  payloads postings.  Concrete implementations of this
@@ -48,10 +48,10 @@ public abstract class FieldsConsumer imp
     while((field = fieldsEnum.next()) != null) {
       mergeState.fieldInfo = mergeState.fieldInfos.fieldInfo(field);
       assert mergeState.fieldInfo != null : "FieldInfo for field is null: "+ field;
-      TermsEnum terms = fieldsEnum.terms();
+      Terms terms = fieldsEnum.terms();
       if (terms != null) {
         final TermsConsumer termsConsumer = addField(mergeState.fieldInfo);
-        termsConsumer.merge(mergeState, terms);
+        termsConsumer.merge(mergeState, terms.iterator());
       }
     }
   }

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/TermVectorsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/TermVectorsWriter.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/TermVectorsWriter.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/TermVectorsWriter.java Mon Nov 14 11:45:42 2011
@@ -187,8 +187,9 @@ public abstract class TermVectorsWriter 
       
       final FieldInfo fieldInfo = fieldInfos.fieldInfo(fieldName);
 
-      final Terms terms = vectors.terms(fieldName);
+      final Terms terms = fieldsEnum.terms();
       if (terms == null) {
+        // FieldsEnum shouldn't lie...
         continue;
       }
       final int numTerms = (int) terms.getUniqueTermCount();
@@ -198,9 +199,10 @@ public abstract class TermVectorsWriter 
 
       final boolean positions;
 
-      final TermsEnum termsEnum = fieldsEnum.terms();
       final OffsetAttribute offsetAtt;
 
+      final TermsEnum termsEnum = terms.iterator();
+
       DocsAndPositionsEnum docsAndPositionsEnum = null;
 
       if (termsEnum.next() != null) {

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/lucene3x/Lucene3xFields.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/lucene3x/Lucene3xFields.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/lucene3x/Lucene3xFields.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/lucene3x/Lucene3xFields.java Mon Nov 14 11:45:42 2011
@@ -199,12 +199,13 @@ public class Lucene3xFields extends Fiel
 
   private class PreFlexFieldsEnum extends FieldsEnum {
     final Iterator<FieldInfo> it;
-    private final PreTermsEnum termsEnum;
+    // nocommit cleanup
+    //private final PreTermsEnum termsEnum;
     FieldInfo current;
 
     public PreFlexFieldsEnum() throws IOException {
       it = fields.values().iterator();
-      termsEnum = new PreTermsEnum();
+      //termsEnum = new PreTermsEnum();
     }
 
     @Override
@@ -218,9 +219,10 @@ public class Lucene3xFields extends Fiel
     }
 
     @Override
-    public TermsEnum terms() throws IOException {
-      termsEnum.reset(current);
-      return termsEnum;
+    public Terms terms() throws IOException {
+      return Lucene3xFields.this.terms(current.name);
+      //termsEnum.reset(current);
+      //return termsEnum;
     }
   }
   

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/memory/MemoryPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/memory/MemoryPostingsFormat.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/memory/MemoryPostingsFormat.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/memory/MemoryPostingsFormat.java Mon Nov 14 11:45:42 2011
@@ -768,8 +768,9 @@ public class MemoryPostingsFormat extend
             return current.field.name;
           }
 
-          public TermsEnum terms() {
-            return current.iterator();
+          @Override
+          public Terms terms() {
+            return current;
           }
         };
       }

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/perfield/PerFieldPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/perfield/PerFieldPostingsFormat.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/perfield/PerFieldPostingsFormat.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/perfield/PerFieldPostingsFormat.java Mon Nov 14 11:45:42 2011
@@ -34,7 +34,6 @@ import org.apache.lucene.index.SegmentIn
 import org.apache.lucene.index.SegmentReadState;
 import org.apache.lucene.index.SegmentWriteState;
 import org.apache.lucene.index.Terms;
-import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.index.codecs.FieldsConsumer;
 import org.apache.lucene.index.codecs.FieldsProducer;
 import org.apache.lucene.index.codecs.PostingsFormat;
@@ -224,13 +223,8 @@ public abstract class PerFieldPostingsFo
       }
 
       @Override
-      public TermsEnum terms() throws IOException {
-        final Terms terms = fields.get(current).terms(current);
-        if (terms != null) {
-          return terms.iterator();
-        } else {
-          return TermsEnum.EMPTY;
-        }
+      public Terms terms() throws IOException {
+        return fields.get(current).terms(current);
       }
     }
 

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextFieldsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextFieldsReader.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextFieldsReader.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextFieldsReader.java Mon Nov 14 11:45:42 2011
@@ -87,8 +87,8 @@ class SimpleTextFieldsReader extends Fie
     }
 
     @Override
-    public TermsEnum terms() throws IOException {
-      return SimpleTextFieldsReader.this.terms(current).iterator();
+    public Terms terms() throws IOException {
+      return SimpleTextFieldsReader.this.terms(current);
     }
   }
 

Modified: lucene/dev/branches/lucene2621/lucene/src/test-framework/java/org/apache/lucene/index/codecs/ramonly/RAMOnlyPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test-framework/java/org/apache/lucene/index/codecs/ramonly/RAMOnlyPostingsFormat.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test-framework/java/org/apache/lucene/index/codecs/ramonly/RAMOnlyPostingsFormat.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test-framework/java/org/apache/lucene/index/codecs/ramonly/RAMOnlyPostingsFormat.java Mon Nov 14 11:45:42 2011
@@ -305,8 +305,8 @@ public class RAMOnlyPostingsFormat exten
     }
 
     @Override
-    public TermsEnum terms() {
-      return new RAMTermsEnum(postings.fieldToTerms.get(current));
+    public Terms terms() {
+      return postings.fieldToTerms.get(current);
     }
   }
 

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestCodecs.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestCodecs.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestCodecs.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestCodecs.java Mon Nov 14 11:45:42 2011
@@ -264,7 +264,10 @@ public class TestCodecs extends LuceneTe
 
     final FieldsEnum fieldsEnum = reader.iterator();
     assertNotNull(fieldsEnum.next());
-    final TermsEnum termsEnum = fieldsEnum.terms();
+    final Terms terms2 = fieldsEnum.terms();
+    assertNotNull(terms2);
+
+    final TermsEnum termsEnum = terms2.iterator();
 
     DocsEnum docsEnum = null;
     for(int i=0;i<NUM_TERMS;i++) {

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestDoc.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestDoc.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestDoc.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestDoc.java Mon Nov 14 11:45:42 2011
@@ -232,7 +232,9 @@ public class TestDoc extends LuceneTestC
       FieldsEnum fis = reader.fields().iterator();
       String field = fis.next();
       while(field != null)  {
-        TermsEnum tis = fis.terms();
+        Terms terms = fis.terms();
+        assertNotNull(terms);
+        TermsEnum tis = terms.iterator();
         while(tis.next() != null) {
 
           out.print("  term=" + field + ":" + tis.term());

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestFilterIndexReader.java Mon Nov 14 11:45:42 2011
@@ -65,8 +65,8 @@ public class TestFilterIndexReader exten
       }
 
       @Override
-      public TermsEnum terms() throws IOException {
-        return new TestTermsEnum(super.terms());
+      public Terms terms() throws IOException {
+        return new TestTerms(super.terms());
       }
     }
 

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestIndexReader.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestIndexReader.java Mon Nov 14 11:45:42 2011
@@ -899,8 +899,17 @@ public class TestIndexReader extends Luc
       Bits liveDocs = MultiFields.getLiveDocs(index1);
       while((field1=fenum1.next()) != null) {
         assertEquals("Different fields", field1, fenum2.next());
-        TermsEnum enum1 = fenum1.terms();
-        TermsEnum enum2 = fenum2.terms();
+        Terms terms1 = fenum1.terms();
+        if (terms1 == null) {
+          assertNull(fenum2.terms());
+          continue;
+        }
+        TermsEnum enum1 = terms1.iterator();
+
+        Terms terms2 = fenum2.terms();
+        assertNotNull(terms2);
+        TermsEnum enum2 = terms2.iterator();
+
         while(enum1.next() != null) {
           assertEquals("Different terms", enum1.term(), enum2.next());
           DocsAndPositionsEnum tp1 = enum1.docsAndPositions(liveDocs, null);

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestParallelTermEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestParallelTermEnum.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestParallelTermEnum.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestParallelTermEnum.java Mon Nov 14 11:45:42 2011
@@ -84,7 +84,8 @@ public class TestParallelTermEnum extend
         f = fe.next();
         assertEquals("field1", f);
 
-        TermsEnum te = fe.terms();
+        Terms terms = fe.terms();
+        TermsEnum te = terms.iterator();
 
         assertEquals("brown", te.next().utf8ToString());
         DocsEnum td = te.docs(liveDocs, null);
@@ -119,7 +120,9 @@ public class TestParallelTermEnum extend
         assertNull(te.next());
         f = fe.next();
         assertEquals("field2", f);
-        te = fe.terms();
+        terms = fe.terms();
+        assertNotNull(terms);
+        te = terms.iterator();
 
         assertEquals("brown", te.next().utf8ToString());
         td = te.docs(liveDocs, td);
@@ -154,7 +157,9 @@ public class TestParallelTermEnum extend
         assertNull(te.next());
         f = fe.next();
         assertEquals("field3", f);
-        te = fe.terms();
+        terms = fe.terms();
+        assertNotNull(terms);
+        te = terms.iterator();
 
         assertEquals("dog", te.next().utf8ToString());
         td = te.docs(liveDocs, td);

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestSegmentReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestSegmentReader.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestSegmentReader.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestSegmentReader.java Mon Nov 14 11:45:42 2011
@@ -121,9 +121,11 @@ public class TestSegmentReader extends L
     FieldsEnum fields = MultiFields.getFields(reader).iterator();
     String field;
     while((field = fields.next()) != null) {
-      TermsEnum terms = fields.terms();
-      while(terms.next() != null) {
-        BytesRef term = terms.term();
+      Terms terms = fields.terms();
+      assertNotNull(terms);
+      TermsEnum termsEnum = terms.iterator();
+      while(termsEnum.next() != null) {
+        BytesRef term = termsEnum.term();
         assertTrue(term != null);
         String fieldValue = (String) DocHelper.nameValues.get(field);
         assertTrue(fieldValue.indexOf(term.utf8ToString()) != -1);

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/TestStressIndexing2.java Mon Nov 14 11:45:42 2011
@@ -395,7 +395,9 @@ public class TestStressIndexing2 extends
           DocsEnum dEnum = null;
           while ((field=fieldsEnum.next()) != null) {
             System.out.println("    " + field + ":");
-            TermsEnum termsEnum2 = fieldsEnum.terms();
+            Terms terms3 = fieldsEnum.terms();
+            assertNotNull(terms3);
+            TermsEnum termsEnum2 = terms3.iterator();
             BytesRef term2;
             while((term2 = termsEnum2.next()) != null) {
               System.out.println("      " + term2.utf8ToString() + ": freq=" + termsEnum2.totalTermFreq());
@@ -427,7 +429,9 @@ public class TestStressIndexing2 extends
           DocsEnum dEnum = null;
           while ((field=fieldsEnum.next()) != null) {
             System.out.println("    " + field + ":");
-            TermsEnum termsEnum2 = fieldsEnum.terms();
+            Terms terms3 = fieldsEnum.terms();
+            assertNotNull(terms3);
+            TermsEnum termsEnum2 = terms3.iterator();
             BytesRef term2;
             while((term2 = termsEnum2.next()) != null) {
               System.out.println("      " + term2.utf8ToString() + ": freq=" + termsEnum2.totalTermFreq());
@@ -482,7 +486,11 @@ public class TestStressIndexing2 extends
           if (field1 == null) {
             break;
           } else {
-            termsEnum1 = fields1.terms();
+            Terms terms = fields1.terms();
+            if (terms == null) {
+              continue;
+            }
+            termsEnum1 = terms.iterator();
           }
         }
         term1 = termsEnum1.next();
@@ -512,7 +520,11 @@ public class TestStressIndexing2 extends
           if (field2 == null) {
             break;
           } else {
-            termsEnum2 = fields2.terms();
+            Terms terms = fields2.terms();
+            if (terms == null) {
+              continue;
+            }
+            termsEnum2 = terms.iterator();
           }
         }
         term2 = termsEnum2.next();
@@ -593,8 +605,14 @@ public class TestStressIndexing2 extends
       String field2 = fieldsEnum2.next();
       assertEquals(field1, field2);
 
-      TermsEnum termsEnum1 = fieldsEnum1.terms();
-      TermsEnum termsEnum2 = fieldsEnum2.terms();
+      Terms terms1 = fieldsEnum1.terms();
+      assertNotNull(terms1);
+      TermsEnum termsEnum1 = terms1.iterator();
+
+      Terms terms2 = fieldsEnum2.terms();
+      assertNotNull(terms2);
+      TermsEnum termsEnum2 = terms2.iterator();
+
       DocsAndPositionsEnum dpEnum1 = null;
       DocsAndPositionsEnum dpEnum2 = null;
       DocsEnum dEnum1 = null;

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/codecs/lucene3x/TestSurrogates.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/codecs/lucene3x/TestSurrogates.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/codecs/lucene3x/TestSurrogates.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/codecs/lucene3x/TestSurrogates.java Mon Nov 14 11:45:42 2011
@@ -108,7 +108,9 @@ public class TestSurrogates extends Luce
       String field;
       int termCount = 0;
       while((field = fieldsEnum.next()) != null) {
-        TermsEnum termsEnum = fieldsEnum.terms();
+        Terms terms = fieldsEnum.terms();
+        assertNotNull(terms);
+        TermsEnum termsEnum = terms.iterator();
         BytesRef text;
         BytesRef lastText = null;
         while((text = termsEnum.next()) != null) {

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/codecs/lucene3x/TestTermInfosReaderIndex.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/codecs/lucene3x/TestTermInfosReaderIndex.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/codecs/lucene3x/TestTermInfosReaderIndex.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/index/codecs/lucene3x/TestTermInfosReaderIndex.java Mon Nov 14 11:45:42 2011
@@ -38,6 +38,7 @@ import org.apache.lucene.index.MultiFiel
 import org.apache.lucene.index.RandomIndexWriter;
 import org.apache.lucene.index.SegmentReader;
 import org.apache.lucene.index.Term;
+import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.index.codecs.preflexrw.PreFlexRWCodec;
 import org.apache.lucene.search.IndexSearcher;
@@ -140,13 +141,15 @@ public class TestTermInfosReaderIndex ex
     FieldsEnum fieldsEnum = MultiFields.getFields(reader).iterator();
     String field;
     while((field = fieldsEnum.next()) != null) {
-      TermsEnum terms = fieldsEnum.terms();
-      while (terms.next() != null) {
+      Terms terms = fieldsEnum.terms();
+      assertNotNull(terms);
+      TermsEnum termsEnum = terms.iterator();
+      while (termsEnum.next() != null) {
         if (sample.size() >= size) {
           int pos = random.nextInt(size);
-          sample.set(pos, new Term(field, terms.term()));
+          sample.set(pos, new Term(field, termsEnum.term()));
         } else {
-          sample.add(new Term(field, terms.term()));
+          sample.add(new Term(field, termsEnum.term()));
         }
       }
     }

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestMultiThreadTermVectors.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestMultiThreadTermVectors.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestMultiThreadTermVectors.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestMultiThreadTermVectors.java Mon Nov 14 11:45:42 2011
@@ -180,7 +180,9 @@ class MultiThreadTermVectorsReader imple
   private void verifyVectors(Fields vectors, int num) throws IOException {
     FieldsEnum fieldsEnum = vectors.iterator();
     while(fieldsEnum.next() != null) {
-      verifyVector(fieldsEnum.terms(), num);
+      Terms terms = fieldsEnum.terms();
+      assert terms != null;
+      verifyVector(terms.iterator(), num);
     }
   }
 

Modified: lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestTermVectors.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestTermVectors.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestTermVectors.java (original)
+++ lucene/dev/branches/lucene2621/lucene/src/test/org/apache/lucene/search/TestTermVectors.java Mon Nov 14 11:45:42 2011
@@ -128,7 +128,9 @@ public class TestTermVectors extends Luc
       assertEquals(3, v.terms(expectedFields[i]).getUniqueTermCount());
 
       DocsAndPositionsEnum dpEnum = null;
-      TermsEnum termsEnum = fieldsEnum.terms();
+      Terms terms = fieldsEnum.terms();
+      assertNotNull(terms);
+      TermsEnum termsEnum = terms.iterator();
       assertEquals("content", termsEnum.next().utf8ToString());
       dpEnum = termsEnum.docsAndPositions(null, dpEnum);
       assertTrue(dpEnum.nextDoc() != DocsEnum.NO_MORE_DOCS);
@@ -261,10 +263,13 @@ public class TestTermVectors extends Luc
     
     DocsEnum docs = null;
     while(fields.next() != null) {
-      TermsEnum terms = fields.terms();
-      while(terms.next() != null) {
-        String text = terms.term().utf8ToString();
-        docs = terms.docs(MultiFields.getLiveDocs(knownSearcher.reader), docs);
+      Terms terms = fields.terms();
+      assertNotNull(terms);
+      TermsEnum termsEnum = terms.iterator();
+
+      while (termsEnum.next() != null) {
+        String text = termsEnum.term().utf8ToString();
+        docs = termsEnum.docs(MultiFields.getLiveDocs(knownSearcher.reader), docs);
         
         while (docs.nextDoc() != DocsEnum.NO_MORE_DOCS) {
           int docId = docs.docID();
@@ -279,11 +284,11 @@ public class TestTermVectors extends Luc
           //float coord = sim.coord()
           //System.out.println("TF: " + tf + " IDF: " + idf + " LenNorm: " + lNorm);
           assertNotNull(vector);
-          TermsEnum termsEnum = vector.iterator();
+          TermsEnum termsEnum2 = vector.iterator();
 
-          while(termsEnum.next() != null) {
-            if (text.equals(termsEnum.term().utf8ToString())) {
-              assertEquals(freq, termsEnum.totalTermFreq());
+          while(termsEnum2.next() != null) {
+            if (text.equals(termsEnum2.term().utf8ToString())) {
+              assertEquals(freq, termsEnum2.totalTermFreq());
             }
           }
         }

Modified: lucene/dev/branches/lucene2621/modules/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/modules/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/modules/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java (original)
+++ lucene/dev/branches/lucene2621/modules/benchmark/src/test/org/apache/lucene/benchmark/byTask/TestPerfTasksLogic.java Mon Nov 14 11:45:42 2011
@@ -38,10 +38,10 @@ import org.apache.lucene.benchmark.byTas
 import org.apache.lucene.benchmark.byTask.tasks.CountingSearchTestTask;
 import org.apache.lucene.benchmark.byTask.tasks.WriteLineDocTask;
 import org.apache.lucene.collation.CollationKeyAnalyzer;
-import org.apache.lucene.index.DocsEnum;
-import org.apache.lucene.index.FieldsEnum;
 import org.apache.lucene.facet.taxonomy.TaxonomyReader;
+import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.Fields;
+import org.apache.lucene.index.FieldsEnum;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig.OpenMode;
@@ -51,6 +51,7 @@ import org.apache.lucene.index.LogMergeP
 import org.apache.lucene.index.MultiFields;
 import org.apache.lucene.index.SegmentInfos;
 import org.apache.lucene.index.SerialMergeScheduler;
+import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.search.FieldCache.DocTermsIndex;
 import org.apache.lucene.search.FieldCache;
@@ -485,10 +486,14 @@ public class TestPerfTasksLogic extends 
       if (fieldName.equals(DocMaker.ID_FIELD) || fieldName.equals(DocMaker.DATE_MSEC_FIELD) || fieldName.equals(DocMaker.TIME_SEC_FIELD)) {
         continue;
       }
-      TermsEnum terms = fields.terms();
+      Terms terms = fields.terms();
+      if (terms == null) {
+        continue;
+      }
+      TermsEnum termsEnum = terms.iterator();
       DocsEnum docs = null;
-      while(terms.next() != null) {
-        docs = terms.docs(MultiFields.getLiveDocs(reader), docs);
+      while(termsEnum.next() != null) {
+        docs = termsEnum.docs(MultiFields.getLiveDocs(reader), docs);
         while(docs.nextDoc() != docs.NO_MORE_DOCS) {
           totalTokenCount2 += docs.freq();
         }

Modified: lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java (original)
+++ lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java Mon Nov 14 11:45:42 2011
@@ -485,9 +485,12 @@ public class LukeRequestHandler extends 
       if (fields != null) {
         FieldsEnum fieldsEnum = fields.iterator();
         while(fieldsEnum.next() != null) {
-          TermsEnum termsEnum = fieldsEnum.terms();
-          while(termsEnum.next() != null) {
-            numTerms++;
+          Terms terms = fieldsEnum.terms();
+          if (terms != null) {
+            TermsEnum termsEnum = terms.iterator();
+            while(termsEnum.next() != null) {
+              numTerms++;
+            }
           }
         }
       }
@@ -639,7 +642,11 @@ public class LukeRequestHandler extends 
       String field;
       while((field = fieldsEnum.next()) != null) {
 
-        TermsEnum termsEnum = fieldsEnum.terms();
+        Terms terms = fieldsEnum.terms();
+        if (terms == null) {
+          continue;
+        }
+        TermsEnum termsEnum = terms.iterator();
         BytesRef text;
         while((text = termsEnum.next()) != null) {
           String t = text.utf8ToChars(spare).toString();

Modified: lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/handler/component/TermVectorComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/handler/component/TermVectorComponent.java?rev=1201671&r1=1201670&r2=1201671&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/handler/component/TermVectorComponent.java (original)
+++ lucene/dev/branches/lucene2621/solr/core/src/java/org/apache/solr/handler/component/TermVectorComponent.java Mon Nov 14 11:45:42 2011
@@ -19,7 +19,6 @@ import org.apache.lucene.index.StoredFie
 import org.apache.lucene.index.StoredFieldVisitor;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.util.BytesRef;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.CommonParams;
@@ -256,7 +255,10 @@ public class TermVectorComponent extends
         final FieldsEnum fieldsEnum = vectors.iterator();
         String field;
         while((field = fieldsEnum.next()) != null) {
-          mapOneVector(docNL, allFields, reader, docId, fieldsEnum.terms(), field);
+          Terms terms = fieldsEnum.terms();
+          if (terms != null) {
+            mapOneVector(docNL, allFields, reader, docId, terms.iterator(), field);
+          }
         }
       }
     }



Mime
View raw message