lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sim...@apache.org
Subject svn commit: r1301423 - in /lucene/dev/trunk/lucene/core/src: java/org/apache/lucene/util/PagedBytes.java test/org/apache/lucene/index/TestDocValuesIndexing.java
Date Fri, 16 Mar 2012 10:39:58 GMT
Author: simonw
Date: Fri Mar 16 10:39:58 2012
New Revision: 1301423

URL: http://svn.apache.org/viewvc?rev=1301423&view=rev
Log:
LUCENE-3870: allow prefixes across block boundaries in PagedBytes.Reader

Modified:
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java?rev=1301423&r1=1301422&r2=1301423&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/PagedBytes.java Fri Mar 16
10:39:58 2012
@@ -193,17 +193,27 @@ public final class PagedBytes {
      * @lucene.internal
      **/
     public BytesRef fillSliceWithPrefix(BytesRef b, long start) {
-      final int index = (int) (start >> blockBits);
+      int index = (int) (start >> blockBits);
       int offset = (int) (start & blockMask);
-      final byte[] block = blocks[index];
+      byte[] block = blocks[index];
       final int length;
+      assert offset <= block.length-1;
       if ((block[offset] & 128) == 0) {
         length = block[offset];
         offset = offset+1;
       } else {
-        length = ((block[offset] & 0x7f) << 8) | (block[1+offset] & 0xff);
-        offset = offset+2;
-        assert length > 0;
+        if (offset==block.length-1) {
+          final byte[] nextBlock = blocks[++index];
+          length = ((block[offset] & 0x7f) << 8) | (nextBlock[0] & 0xff);
+          offset = 1;
+          block = nextBlock;
+          assert length > 0; 
+        } else {
+          assert offset < block.length-1;
+          length = ((block[offset] & 0x7f) << 8) | (block[1+offset] & 0xff);
+          offset = offset+2;
+          assert length > 0;
+        }
       }
       assert length >= 0: "length=" + length;
       b.length = length;

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java?rev=1301423&r1=1301422&r2=1301423&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
(original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java
Fri Mar 16 10:39:58 2012
@@ -470,7 +470,6 @@ public class TestDocValuesIndexing exten
       }
       break;
       case VAR_INTS:
-        System.out.println(source.hasArray());
         assertFalse(source.hasArray());
         break;
       case FLOAT_32:
@@ -931,4 +930,34 @@ public class TestDocValuesIndexing exten
     r.close();
     dir.close();
   }
+
+  // LUCENE-3870
+  public void testLengthPrefixAcrossTwoPages() throws Exception {
+    Directory d = newDirectory();
+    IndexWriter w = new IndexWriter(d, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
+    Document doc = new Document();
+    byte[] bytes = new byte[32764];
+    BytesRef b = new BytesRef();
+    b.bytes = bytes;
+    b.length = bytes.length;
+    doc.add(new DocValuesField("field", b, DocValues.Type.BYTES_VAR_DEREF));
+    w.addDocument(doc);
+    bytes[0] = 1;
+    w.addDocument(doc);
+    DirectoryReader r = w.getReader();
+    Source s = r.getSequentialSubReaders()[0].docValues("field").getSource();
+
+    BytesRef bytes1 = s.getBytes(0, new BytesRef());
+    assertEquals(bytes.length, bytes1.length);
+    bytes[0] = 0;
+    assertEquals(b, bytes1);
+    
+    bytes1 = s.getBytes(1, new BytesRef());
+    assertEquals(bytes.length, bytes1.length);
+    bytes[0] = 1;
+    assertEquals(b, bytes1);
+    r.close();
+    w.close();
+    d.close();
+  }
 }
\ No newline at end of file



Mime
View raw message