lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1039322 - in /lucene/java/branches/lucene_2_9/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:24 GMT
Author: mikemccand
Date: Fri Nov 26 11:50:23 2010
New Revision: 1039322

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

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

Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/TermVectorsReader.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/TermVectorsReader.java?rev=1039322&r1=1039321&r2=1039322&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/TermVectorsReader.java
(original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/TermVectorsReader.java
Fri Nov 26 11:50:23 2010
@@ -107,8 +107,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_2_9/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java?rev=1039322&r1=1039321&r2=1039322&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java
(original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/TermVectorsTermsWriter.java
Fri Nov 26 11:50:23 2010
@@ -53,12 +53,13 @@ final class TermVectorsTermsWriter exten
 
   synchronized void flush(Map 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_2_9/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=1039322&r1=1039321&r2=1039322&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/index/TestIndexWriter.java
(original)
+++ lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/index/TestIndexWriter.java
Fri Nov 26 11:50:23 2010
@@ -4907,4 +4907,39 @@ public class TestIndexWriter extends Bas
 
     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(int idx=0;idx<files.length;idx++) {
+      String file = files[idx];
+      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