コード例 #1
0
  private static SortedNumericDocValues sparseSingles(
      final NumericDocValues deltas,
      final long minValue,
      final long missingValue,
      final int maxDoc) {
    final NumericDocValues values =
        new NumericDocValues() {
          @Override
          public long get(int docID) {
            final long delta = deltas.get(docID);
            if (delta == missingValue) {
              return 0;
            }
            return minValue + delta;
          }
        };
    final Bits docsWithFields =
        new Bits() {
          @Override
          public boolean get(int index) {
            return deltas.get(index) != missingValue;
          }

          @Override
          public int length() {
            return maxDoc;
          }
        };
    return DocValues.singleton(values, docsWithFields);
  }
コード例 #2
0
  private static SortedNumericDocValues withOrdinals(
      Ordinals ordinals, final LongValues values, int maxDoc) {
    final RandomAccessOrds ords = ordinals.ordinals();
    final SortedDocValues singleOrds = DocValues.unwrapSingleton(ords);
    if (singleOrds != null) {
      final NumericDocValues singleValues =
          new NumericDocValues() {
            @Override
            public long get(int docID) {
              final int ord = singleOrds.getOrd(docID);
              if (ord >= 0) {
                return values.get(singleOrds.getOrd(docID));
              } else {
                return 0;
              }
            }
          };
      return DocValues.singleton(singleValues, DocValues.docsWithValue(ords, maxDoc));
    } else {
      return new SortedNumericDocValues() {
        @Override
        public long valueAt(int index) {
          return values.get(ords.ordAt(index));
        }

        @Override
        public void setDocument(int doc) {
          ords.setDocument(doc);
        }

        @Override
        public int count() {
          return ords.cardinality();
        }
      };
    }
  }
コード例 #3
0
 private static SortedNumericDocValues pagedSingles(
     final PackedLongValues values, final Bits docsWithValue) {
   return DocValues.singleton(
       new NumericDocValues() {
         // we need to wrap since NumericDocValues must return 0 when a doc has no value
         @Override
         public long get(int docID) {
           if (docsWithValue == null || docsWithValue.get(docID)) {
             return values.get(docID);
           } else {
             return 0;
           }
         }
       },
       docsWithValue);
 }
コード例 #4
0
 private static SortedNumericDocValues singles(
     final NumericDocValues deltas, final long minValue) {
   final NumericDocValues values;
   if (minValue == 0) {
     values = deltas;
   } else {
     values =
         new NumericDocValues() {
           @Override
           public long get(int docID) {
             return minValue + deltas.get(docID);
           }
         };
   }
   return DocValues.singleton(values, null);
 }