lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1200584 - in /lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index: ./ codecs/ codecs/simpletext/
Date Thu, 10 Nov 2011 21:49:33 GMT
Author: rmuir
Date: Thu Nov 10 21:49:33 2011
New Revision: 1200584

URL: http://svn.apache.org/viewvc?rev=1200584&view=rev
Log:
LUCENE-2621: pass info instead of number to storedfieldswriter, add boilerplate methods to
tvwriter

Modified:
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/StoredFieldsConsumer.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/DefaultStoredFieldsWriter.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/DefaultTermVectorsWriter.java
    lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/StoredFieldsWriter.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/simpletext/SimpleTextStoredFieldsWriter.java

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/StoredFieldsConsumer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/StoredFieldsConsumer.java?rev=1200584&r1=1200583&r2=1200584&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/StoredFieldsConsumer.java
(original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/StoredFieldsConsumer.java
Thu Nov 10 21:49:33 2011
@@ -45,12 +45,12 @@ final class StoredFieldsConsumer {
 
   private int numStoredFields;
   private IndexableField[] storedFields;
-  private int[] fieldNumbers;
+  private FieldInfo[] fieldInfos;
 
   public void reset() {
     numStoredFields = 0;
     storedFields = new IndexableField[1];
-    fieldNumbers = new int[1];
+    fieldInfos = new FieldInfo[1];
   }
 
   public void startDocument() {
@@ -116,7 +116,7 @@ final class StoredFieldsConsumer {
     if (fieldsWriter != null && numStoredFields > 0) {
       fieldsWriter.startDocument(numStoredFields);
       for (int i = 0; i < numStoredFields; i++) {
-        fieldsWriter.writeField(fieldNumbers[i], storedFields[i]);
+        fieldsWriter.writeField(fieldInfos[i], storedFields[i]);
       }
       lastDocID++;
     }
@@ -131,14 +131,14 @@ final class StoredFieldsConsumer {
       IndexableField[] newArray = new IndexableField[newSize];
       System.arraycopy(storedFields, 0, newArray, 0, numStoredFields);
       storedFields = newArray;
-    }
-
-    if (numStoredFields == fieldNumbers.length) {
-      fieldNumbers = ArrayUtil.grow(fieldNumbers);
+      
+      FieldInfo[] newInfoArray = new FieldInfo[newSize];
+      System.arraycopy(fieldInfos, 0, newInfoArray, 0, numStoredFields);
+      fieldInfos = newInfoArray;
     }
 
     storedFields[numStoredFields] = field;
-    fieldNumbers[numStoredFields] = fieldInfo.number;
+    fieldInfos[numStoredFields] = fieldInfo;
     numStoredFields++;
 
     assert docState.testPoint("StoredFieldsWriterPerThread.processFields.writeField");

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/DefaultStoredFieldsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/DefaultStoredFieldsWriter.java?rev=1200584&r1=1200583&r2=1200584&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/DefaultStoredFieldsWriter.java
(original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/DefaultStoredFieldsWriter.java
Thu Nov 10 21:49:33 2011
@@ -20,6 +20,7 @@ import java.io.IOException;
 
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.IndexFileNames;
 import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.index.MergeState;
@@ -129,8 +130,8 @@ public final class DefaultStoredFieldsWr
     } catch (IOException ignored) {}
   }
 
-  public final void writeField(int fieldNumber, IndexableField field) throws IOException
{
-    fieldsStream.writeVInt(fieldNumber);
+  public final void writeField(FieldInfo info, IndexableField field) throws IOException {
+    fieldsStream.writeVInt(info.number);
     int bits = 0;
     final BytesRef bytes;
     final String string;

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/DefaultTermVectorsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/DefaultTermVectorsWriter.java?rev=1200584&r1=1200583&r2=1200584&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/DefaultTermVectorsWriter.java
(original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/DefaultTermVectorsWriter.java
Thu Nov 10 21:49:33 2011
@@ -36,10 +36,13 @@ import org.apache.lucene.util.StringHelp
 import java.io.IOException;
 
 public final class DefaultTermVectorsWriter extends TermVectorsWriter {
-
+  private final Directory directory;
+  private final String segment;
   private IndexOutput tvx = null, tvd = null, tvf = null;
 
   public DefaultTermVectorsWriter(Directory directory, String segment, IOContext context)
throws IOException {
+    this.directory = directory;
+    this.segment = segment;
     boolean success = false;
     try {
       // Open files for TermVector storage
@@ -173,6 +176,32 @@ public final class DefaultTermVectorsWri
     } else
       tvd.writeVInt(0);
   }
+  
+  @Override
+  public void startDocument(int numVectorFields) throws IOException {
+    tvx.writeLong(tvd.getFilePointer());
+    tvx.writeLong(tvf.getFilePointer());
+    tvd.writeVInt(numVectorFields);
+  }
+  
+  @Override
+  public void abort() {
+    try {
+      close();
+    } catch (IOException ignored) {}
+    
+    try {
+      directory.deleteFile(IndexFileNames.segmentFileName(segment, "", IndexFileNames.VECTORS_INDEX_EXTENSION));
+    } catch (IOException ignored) {}
+    
+    try {
+      directory.deleteFile(IndexFileNames.segmentFileName(segment, "", IndexFileNames.VECTORS_DOCUMENTS_EXTENSION));
+    } catch (IOException ignored) {}
+    
+    try {
+      directory.deleteFile(IndexFileNames.segmentFileName(segment, "", IndexFileNames.VECTORS_FIELDS_EXTENSION));
+    } catch (IOException ignored) {}
+  }
 
   /**
    * Do a bulk copy of numDocs documents from reader to our
@@ -330,5 +359,6 @@ public final class DefaultTermVectorsWri
     // make an effort to close all streams we can but remember and re-throw
     // the first exception encountered in this process
     IOUtils.close(tvx, tvd, tvf);
+    tvx = tvd = tvf = null;
   }
 }

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/StoredFieldsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/StoredFieldsWriter.java?rev=1200584&r1=1200583&r2=1200584&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/StoredFieldsWriter.java
(original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/StoredFieldsWriter.java
Thu Nov 10 21:49:33 2011
@@ -4,6 +4,7 @@ import java.io.Closeable;
 import java.io.IOException;
 
 import org.apache.lucene.document.Document;
+import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.FieldInfos;
 import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.index.MergeState;
@@ -31,7 +32,7 @@ import org.apache.lucene.util.Bits;
  * <ol>
  *   <li>For every document, {@link #startDocument(int)} is called,
  *       informing the Codec how many fields will be written.
- *   <li>{@link #writeField(int, IndexableField)} is called for 
+ *   <li>{@link #writeField(FieldInfo, IndexableField)} is called for 
  *       each field in the document.
  *   <li>After all documents have been written, {@link #finish(int)} 
  *       is called for verification/sanity-checks.
@@ -50,7 +51,7 @@ public abstract class StoredFieldsWriter
   public abstract void startDocument(int numStoredFields) throws IOException;
   
   /** Writes a single stored field. */
-  public abstract void writeField(int fieldNumber, IndexableField field) throws IOException;
+  public abstract void writeField(FieldInfo info, IndexableField field) throws IOException;
 
   /** Aborts writing entirely, implementation should remove
    *  any partially-written files, etc. */
@@ -110,7 +111,7 @@ public abstract class StoredFieldsWriter
 
     for (IndexableField field : doc) {
       if (field.fieldType().stored()) {
-        writeField(fieldInfos.fieldNumber(field.name()), field);
+        writeField(fieldInfos.fieldInfo(field.name()), field);
       }
     }
   }

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=1200584&r1=1200583&r2=1200584&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
Thu Nov 10 21:49:33 2011
@@ -27,6 +27,17 @@ import org.apache.lucene.util.Bits;
 
 public abstract class TermVectorsWriter implements Closeable {
   
+  /** Called before writing the stored fields of the document.
+   *  XXX will be called <code>numVectorFields</code> times.
+   *  Note that if term vectors are enabled, this is called 
+   *  even if the document has no vector fields, in
+   *  this case <code>numVectorFields</code> will be zero. */
+  public abstract void startDocument(int numVectorFields) throws IOException;
+  
+  /** Aborts writing entirely, implementation should remove
+   *  any partially-written files, etc. */
+  public abstract void abort();
+
   /** Called before {@link #close()}, passing in the number
    *  of documents that were written. Note that this is 
    *  intentionally redundant (equivalent to the number of

Modified: lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextStoredFieldsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextStoredFieldsWriter.java?rev=1200584&r1=1200583&r2=1200584&view=diff
==============================================================================
--- lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextStoredFieldsWriter.java
(original)
+++ lucene/dev/branches/lucene2621/lucene/src/java/org/apache/lucene/index/codecs/simpletext/SimpleTextStoredFieldsWriter.java
Thu Nov 10 21:49:33 2011
@@ -19,6 +19,7 @@ package org.apache.lucene.index.codecs.s
 
 import java.io.IOException;
 
+import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.IndexFileNames;
 import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.index.codecs.StoredFieldsWriter;
@@ -87,9 +88,9 @@ public class SimpleTextStoredFieldsWrite
   }
 
   @Override
-  public void writeField(int fieldNumber, IndexableField field) throws IOException {
+  public void writeField(FieldInfo info, IndexableField field) throws IOException {
     write(FIELD);
-    write(Integer.toString(fieldNumber));
+    write(Integer.toString(info.number));
     newLine();
     
     write(NAME);



Mime
View raw message