lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r691617 - in /lucene/java/trunk/src: java/org/apache/lucene/document/AbstractField.java java/org/apache/lucene/index/FieldsWriter.java test/org/apache/lucene/index/TestIndexWriter.java
Date Wed, 03 Sep 2008 13:59:32 GMT
Author: mikemccand
Date: Wed Sep  3 06:59:31 2008
New Revision: 691617

URL: http://svn.apache.org/viewvc?rev=691617&view=rev
Log:
LUCENE-1374: fixed NPE case when merging compressed fields with heterogeneous segments

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/document/AbstractField.java
    lucene/java/trunk/src/java/org/apache/lucene/index/FieldsWriter.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/document/AbstractField.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/document/AbstractField.java?rev=691617&r1=691616&r2=691617&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/document/AbstractField.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/document/AbstractField.java Wed Sep  3 06:59:31
2008
@@ -218,7 +218,10 @@
   }
   
   public byte[] getBinaryValue(byte[] result){
-    return isBinary ? (byte[]) fieldsData : null;
+    if (isBinary || fieldsData instanceof byte[])
+      return (byte[]) fieldsData;
+    else
+      return null;
   }
 
   /**
@@ -227,8 +230,16 @@
    * @return length of byte[] segment that represents this Field value
    */
   public int getBinaryLength() {
-     return binaryLength;
-    }
+    if (isBinary) {
+      if (!isCompressed)
+        return binaryLength;
+      else
+        return ((byte[]) fieldsData).length;
+    } else if (fieldsData instanceof byte[])
+      return ((byte[]) fieldsData).length;
+    else
+      return 0;
+  }
 
   /**
    * Returns offset into byte[] segment that is used as value, if Field is not binary

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/FieldsWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/FieldsWriter.java?rev=691617&r1=691616&r2=691617&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/FieldsWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/FieldsWriter.java Wed Sep  3 06:59:31
2008
@@ -197,6 +197,7 @@
           // optimized case for merging, the data
           // is already compressed
           data = field.getBinaryValue();
+          assert data != null;
           len = field.getBinaryLength();
           offset = field.getBinaryOffset();  
         } else {

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=691617&r1=691616&r2=691617&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java Wed Sep  3 06:59:31
2008
@@ -4076,5 +4076,39 @@
     ir.close();
     dir.close();
   }
-  
+
+  // LUCENE-1374
+  public void testMergeCompressedFields() throws IOException {
+    File indexDir = new File(System.getProperty("tempDir"), "mergecompressedfields");
+    Directory dir = FSDirectory.getDirectory(indexDir);
+    try {
+      for(int i=0;i<5;i++) {
+        // Must make a new writer & doc each time, w/
+        // different fields, so bulk merge of stored fields
+        // cannot run:
+        IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), i==0, IndexWriter.MaxFieldLength.UNLIMITED);
+        w.setMergeFactor(5);
+        w.setMergeScheduler(new SerialMergeScheduler());
+        Document doc = new Document();
+        doc.add(new Field("test1", "this is some data that will be compressed this this this",
Field.Store.COMPRESS, Field.Index.NO));
+        doc.add(new Field("test2", new byte[20], Field.Store.COMPRESS));
+        doc.add(new Field("field" + i, "random field", Field.Store.NO, Field.Index.TOKENIZED));
+        w.addDocument(doc);
+        w.close();
+      }
+
+      byte[] cmp = new byte[20];
+
+      IndexReader r = IndexReader.open(dir);
+      for(int i=0;i<5;i++) {
+        Document doc = r.document(i);
+        assertEquals("this is some data that will be compressed this this this", doc.getField("test1").stringValue());
+        byte[] b = doc.getField("test2").binaryValue();
+        assertTrue(Arrays.equals(b, cmp));
+      }
+    } finally {
+      dir.close();
+      _TestUtil.rmDir(indexDir);
+    }
+  }
 }



Mime
View raw message