lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r1442170 - in /lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index: BinaryDocValues.java MultiDocValues.java SortedDocValues.java
Date Mon, 04 Feb 2013 16:37:33 GMT
Author: rmuir
Date: Mon Feb  4 16:37:33 2013
New Revision: 1442170

URL: http://svn.apache.org/viewvc?rev=1442170&view=rev
Log:
clean up these slow-wrapper impls a little bit

Modified:
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/BinaryDocValues.java
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/MultiDocValues.java
    lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/BinaryDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/BinaryDocValues.java?rev=1442170&r1=1442169&r2=1442170&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/BinaryDocValues.java
(original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/BinaryDocValues.java
Mon Feb  4 16:37:33 2013
@@ -36,10 +36,12 @@ public abstract class BinaryDocValues {
    */
   public static final byte[] MISSING = new byte[0];
   
-  /** An empty BinaryDocValues which returns empty bytes for every document */
+  /** An empty BinaryDocValues which returns {@link #MISSING} for every document */
   public static final BinaryDocValues EMPTY = new BinaryDocValues() {
     @Override
     public void get(int docID, BytesRef result) {
+      result.bytes = MISSING;
+      result.offset = 0;
       result.length = 0;
     }
   };

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/MultiDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/MultiDocValues.java?rev=1442170&r1=1442169&r2=1442170&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/MultiDocValues.java
(original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/MultiDocValues.java
Mon Feb  4 16:37:33 2013
@@ -51,61 +51,82 @@ public class MultiDocValues {
   /** No instantiation */
   private MultiDocValues() {}
   
-  /** returns a NumericDocValues for a reader's norms (potentially merging on-the-fly) */
-  // moved to src/java so SlowWrapper can use it... uggggggh
+  /** Returns a NumericDocValues for a reader's norms (potentially merging on-the-fly).
+   * <p>
+   * This is a slow way to access normalization values. Instead, access them per-segment
+   * with {@link AtomicReader#getNormValues(String)}
+   * </p> 
+   */
   public static NumericDocValues getNormValues(final IndexReader r, final String field) throws
IOException {
     final List<AtomicReaderContext> leaves = r.leaves();
-    if (leaves.size() == 1) {
+    final int size = leaves.size();
+    if (size == 0) {
+      return null;
+    } else if (size == 1) {
       return leaves.get(0).reader().getNormValues(field);
     }
     FieldInfo fi = MultiFields.getMergedFieldInfos(r).fieldInfo(field);
     if (fi == null || fi.hasNorms() == false) {
       return null;
     }
-    boolean anyReal = false;
-    for(AtomicReaderContext ctx : leaves) {
-      NumericDocValues norms = ctx.reader().getNormValues(field);
 
-      if (norms != null) {
+    boolean anyReal = false;
+    final NumericDocValues[] values = new NumericDocValues[size];
+    final int[] starts = new int[size+1];
+    for (int i = 0; i < size; i++) {
+      AtomicReaderContext context = leaves.get(i);
+      NumericDocValues v = context.reader().getNormValues(field);
+      if (v == null) {
+        v = NumericDocValues.EMPTY;
+      } else {
         anyReal = true;
       }
+      values[i] = v;
+      starts[i] = context.docBase;
     }
-
+    starts[size] = r.maxDoc();
+    
     assert anyReal;
 
     return new NumericDocValues() {
       @Override
       public long get(int docID) {
-        int subIndex = ReaderUtil.subIndex(docID, leaves);
-        NumericDocValues norms;
-        try {
-          norms = leaves.get(subIndex).reader().getNormValues(field);
-        } catch (IOException ioe) {
-          throw new RuntimeException(ioe);
-        }
-        if (norms == null) {
-          return 0;
-        } else {
-          return norms.get(docID - leaves.get(subIndex).docBase);
-        }
+        int subIndex = ReaderUtil.subIndex(docID, starts);
+        return values[subIndex].get(docID - starts[subIndex]);
       }
     };
   }
 
-  /** returns a NumericDocValues for a reader's docvalues (potentially merging on-the-fly)
*/
+  /** Returns a NumericDocValues for a reader's docvalues (potentially merging on-the-fly)

+   * <p>
+   * This is a slow way to access numeric values. Instead, access them per-segment
+   * with {@link AtomicReader#getNumericDocValues(String)}
+   * </p> 
+   * */
   public static NumericDocValues getNumericValues(final IndexReader r, final String field)
throws IOException {
     final List<AtomicReaderContext> leaves = r.leaves();
-    if (leaves.size() == 1) {
+    final int size = leaves.size();
+    if (size == 0) {
+      return null;
+    } else if (size == 1) {
       return leaves.get(0).reader().getNumericDocValues(field);
     }
-    boolean anyReal = false;
-    for(AtomicReaderContext ctx : leaves) {
-      NumericDocValues values = ctx.reader().getNumericDocValues(field);
 
-      if (values != null) {
+    boolean anyReal = false;
+    final NumericDocValues[] values = new NumericDocValues[size];
+    final int[] starts = new int[size+1];
+    for (int i = 0; i < size; i++) {
+      AtomicReaderContext context = leaves.get(i);
+      NumericDocValues v = context.reader().getNumericDocValues(field);
+      if (v == null) {
+        v = NumericDocValues.EMPTY;
+      } else {
         anyReal = true;
       }
+      values[i] = v;
+      starts[i] = context.docBase;
     }
+    starts[size] = r.maxDoc();
 
     if (!anyReal) {
       return null;
@@ -113,66 +134,64 @@ public class MultiDocValues {
       return new NumericDocValues() {
         @Override
         public long get(int docID) {
-          int subIndex = ReaderUtil.subIndex(docID, leaves);
-          NumericDocValues values;
-          try {
-            values = leaves.get(subIndex).reader().getNumericDocValues(field);
-          } catch (IOException ioe) {
-            throw new RuntimeException(ioe);
-          }
-          if (values == null) {
-            return 0;
-          } else {
-            return values.get(docID - leaves.get(subIndex).docBase);
-          }
+          int subIndex = ReaderUtil.subIndex(docID, starts);
+          return values[subIndex].get(docID - starts[subIndex]);
         }
       };
     }
   }
 
-  /** returns a BinaryDocValues for a reader's docvalues (potentially merging on-the-fly)
*/
+  /** Returns a BinaryDocValues for a reader's docvalues (potentially merging on-the-fly)
+   * <p>
+   * This is a slow way to access binary values. Instead, access them per-segment
+   * with {@link AtomicReader#getBinaryDocValues(String)}
+   * </p>  
+   */
   public static BinaryDocValues getBinaryValues(final IndexReader r, final String field)
throws IOException {
     final List<AtomicReaderContext> leaves = r.leaves();
-    if (leaves.size() == 1) {
+    final int size = leaves.size();
+    
+    if (size == 0) {
+      return null;
+    } else if (size == 1) {
       return leaves.get(0).reader().getBinaryDocValues(field);
     }
+    
     boolean anyReal = false;
-
-    for(AtomicReaderContext ctx : leaves) {
-      BinaryDocValues values = ctx.reader().getBinaryDocValues(field);
-
-      if (values != null) {
+    final BinaryDocValues[] values = new BinaryDocValues[size];
+    final int[] starts = new int[size+1];
+    for (int i = 0; i < size; i++) {
+      AtomicReaderContext context = leaves.get(i);
+      BinaryDocValues v = context.reader().getBinaryDocValues(field);
+      if (v == null) {
+        v = BinaryDocValues.EMPTY;
+      } else {
         anyReal = true;
       }
+      values[i] = v;
+      starts[i] = context.docBase;
     }
-
+    starts[size] = r.maxDoc();
+    
     if (!anyReal) {
       return null;
     } else {
-
       return new BinaryDocValues() {
         @Override
         public void get(int docID, BytesRef result) {
-          int subIndex = ReaderUtil.subIndex(docID, leaves);
-          BinaryDocValues values;
-          try {
-            values = leaves.get(subIndex).reader().getBinaryDocValues(field);
-          } catch (IOException ioe) {
-            throw new RuntimeException(ioe);
-          }
-          if (values != null) {
-            values.get(docID - leaves.get(subIndex).docBase, result);
-          } else {
-            result.length = 0;
-            result.offset = 0;
-            result.bytes = BinaryDocValues.MISSING;
-          }
+          int subIndex = ReaderUtil.subIndex(docID, starts);
+          values[subIndex].get(docID - starts[subIndex], result);
         }
       };
     }
   }
   
-  /** returns a SortedDocValues for a reader's docvalues (potentially doing extremely slow
things) */
+  /** Returns a SortedDocValues for a reader's docvalues (potentially doing extremely slow
things).
+   * <p>
+   * This is an extremely slow way to access sorted values. Instead, access them per-segment
+   * with {@link AtomicReader#getSortedDocValues(String)}
+   * </p>  
+   */
   public static SortedDocValues getSortedValues(final IndexReader r, final String field)
throws IOException {
     final List<AtomicReaderContext> leaves = r.leaves();
     if (leaves.size() == 1) {

Modified: lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java?rev=1442170&r1=1442169&r2=1442170&view=diff
==============================================================================
--- lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java
(original)
+++ lucene/dev/branches/lucene4547/lucene/core/src/java/org/apache/lucene/index/SortedDocValues.java
Mon Feb  4 16:37:33 2013
@@ -67,7 +67,7 @@ public abstract class SortedDocValues ex
     }
   }
 
-  /** An empty SortedDocValues which returns empty bytes for every document */
+  /** An empty SortedDocValues which returns {@link #MISSING} for every document */
   public static final SortedDocValues EMPTY = new SortedDocValues() {
     @Override
     public int getOrd(int docID) {
@@ -76,6 +76,8 @@ public abstract class SortedDocValues ex
 
     @Override
     public void lookupOrd(int ord, BytesRef result) {
+      result.bytes = MISSING;
+      result.offset = 0;
       result.length = 0;
     }
 



Mime
View raw message