コード例 #1
0
  private static void duelFieldDataLong(
      Random random,
      AtomicReaderContext context,
      IndexNumericFieldData left,
      IndexNumericFieldData right)
      throws Exception {
    AtomicNumericFieldData leftData =
        random.nextBoolean() ? left.load(context) : left.loadDirect(context);
    AtomicNumericFieldData rightData =
        random.nextBoolean() ? right.load(context) : right.loadDirect(context);

    int numDocs = context.reader().maxDoc();
    SortedNumericDocValues leftLongValues = leftData.getLongValues();
    SortedNumericDocValues rightLongValues = rightData.getLongValues();
    for (int i = 0; i < numDocs; i++) {
      leftLongValues.setDocument(i);
      rightLongValues.setDocument(i);
      int numValues = leftLongValues.count();
      long previous = 0;
      assertThat(numValues, equalTo(rightLongValues.count()));
      for (int j = 0; j < numValues; j++) {
        long current;
        assertThat(leftLongValues.valueAt(j), equalTo(current = rightLongValues.valueAt(j)));
        if (j > 0) {
          assertThat(previous, lessThan(current));
        }
        previous = current;
      }
    }
  }
コード例 #2
0
  private static void duelFieldDataDouble(
      Random random,
      AtomicReaderContext context,
      IndexNumericFieldData left,
      IndexNumericFieldData right)
      throws Exception {
    AtomicNumericFieldData leftData =
        random.nextBoolean() ? left.load(context) : left.loadDirect(context);
    AtomicNumericFieldData rightData =
        random.nextBoolean() ? right.load(context) : right.loadDirect(context);

    int numDocs = context.reader().maxDoc();
    SortedNumericDoubleValues leftDoubleValues = leftData.getDoubleValues();
    SortedNumericDoubleValues rightDoubleValues = rightData.getDoubleValues();
    for (int i = 0; i < numDocs; i++) {
      leftDoubleValues.setDocument(i);
      rightDoubleValues.setDocument(i);
      int numValues = leftDoubleValues.count();
      assertThat(numValues, equalTo(rightDoubleValues.count()));
      double previous = 0;
      for (int j = 0; j < numValues; j++) {
        double current = rightDoubleValues.valueAt(j);
        if (Double.isNaN(current)) {
          assertTrue(Double.isNaN(leftDoubleValues.valueAt(j)));
        } else {
          assertThat(leftDoubleValues.valueAt(j), closeTo(current, 0.0001));
        }
        if (j > 0) {
          assertThat(Double.compare(previous, current), lessThan(0));
        }
        previous = current;
      }
    }
  }