lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1039321 - in /lucene/java/branches/lucene_3_0/src: java/org/apache/lucene/index/TermVectorsReader.java java/org/apache/lucene/index/TermVectorsTermsWriter.java test/org/apache/lucene/index/TestIndexWriter.java
Date Fri, 26 Nov 2010 11:50:19 GMT
Author: mikemccand
Date: Fri Nov 26 11:50:19 2010
New Revision: 1039321

URL: http://svn.apache.org/viewvc?rev=1039321&view=rev
Log:
LUCENE-2776: don't create term vectors files if no doc uses term vectors

Modified:
    lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/index/TermVectorsReader.java
    lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java
    lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/index/TestIndexWriter.java

Modified: lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/index/TermVectorsReader.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/index/TermVectorsReader.java?rev=1039321&r1=1039320&r2=1039321&view=diff
==============================================================================
--- lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/index/TermVectorsReader.java
(original)
+++ lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/index/TermVectorsReader.java
Fri Nov 26 11:50:19 2010
@@ -104,8 +104,13 @@ class TermVectorsReader implements Clone
           // docs
           assert numTotalDocs >= size + docStoreOffset: "numTotalDocs=" + numTotalDocs
+ " size=" + size + " docStoreOffset=" + docStoreOffset;
         }
-      } else
+      } else {
+        // If all documents flushed in a segment had hit
+        // non-aborting exceptions, it's possible that
+        // FieldInfos.hasVectors returns true yet the term
+        // vector files don't exist.
         format = 0;
+      }
 
       this.fieldInfos = fieldInfos;
       success = true;

Modified: lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java?rev=1039321&r1=1039320&r2=1039321&view=diff
==============================================================================
--- lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java
(original)
+++ lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java
Fri Nov 26 11:50:19 2010
@@ -56,12 +56,13 @@ final class TermVectorsTermsWriter exten
   @Override
   synchronized void flush(Map<TermsHashConsumerPerThread,Collection<TermsHashConsumerPerField>>
threadsAndFields, final SegmentWriteState state) throws IOException {
 
-    if (state.numDocsInStore > 0) {
-      // It's possible that all documents seen in this segment
-      // hit non-aborting exceptions, in which case we will
-      // not have yet init'd the TermVectorsWriter:
-      initTermVectorsWriter();
-    }
+    // NOTE: it's possible that all documents seen in this segment
+    // hit non-aborting exceptions, in which case we will
+    // not have yet init'd the TermVectorsWriter.  This is
+    // actually OK (unlike in the stored fields case)
+    // because, although IieldInfos.hasVectors() will return
+    // true, the TermVectorsReader gracefully handles
+    // non-existence of the term vectors files.
 
     if (tvx != null) {
 

Modified: lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=1039321&r1=1039320&r2=1039321&view=diff
==============================================================================
--- lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/index/TestIndexWriter.java
(original)
+++ lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/index/TestIndexWriter.java
Fri Nov 26 11:50:19 2010
@@ -4828,4 +4828,38 @@ public class TestIndexWriter extends Luc
 
     dir.close();
   }
+
+  public void testNoUnwantedTVFiles() throws Exception {
+
+    Directory dir = new MockRAMDirectory();
+    IndexWriter indexWriter = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
+    indexWriter.setRAMBufferSizeMB(0.01);
+    indexWriter.setUseCompoundFile(false);
+
+    String BIG="alskjhlaksjghlaksjfhalksvjepgjioefgjnsdfjgefgjhelkgjhqewlrkhgwlekgrhwelkgjhwelkgrhwlkejg";
+    BIG=BIG+BIG+BIG+BIG;
+
+    for (int i=0; i<2; i++) {
+      Document doc = new Document();
+      doc.add(new Field("id", Integer.toString(i)+BIG, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS));
+      doc.add(new Field("str", Integer.toString(i)+BIG, Field.Store.YES, Field.Index.NOT_ANALYZED));
+      doc.add(new Field("str2", Integer.toString(i)+BIG, Field.Store.YES, Field.Index.ANALYZED));
+      doc.add(new Field("str3", Integer.toString(i)+BIG, Field.Store.YES, Field.Index.ANALYZED_NO_NORMS));
+      indexWriter.addDocument(doc);
+    }
+
+    indexWriter.close();
+
+    _TestUtil.checkIndex(dir);
+
+    assertNoUnreferencedFiles(dir, "no tv files");
+    String[] files = dir.listAll();
+    for(String file : files) {
+      assertTrue(!file.endsWith(IndexFileNames.VECTORS_FIELDS_EXTENSION));
+      assertTrue(!file.endsWith(IndexFileNames.VECTORS_INDEX_EXTENSION));
+      assertTrue(!file.endsWith(IndexFileNames.VECTORS_DOCUMENTS_EXTENSION));
+    }
+
+    dir.close();
+  }
 }



Mime
View raw message