Example usage for org.apache.lucene.index SortedNumericDocValues SortedNumericDocValues

List of usage examples for org.apache.lucene.index SortedNumericDocValues SortedNumericDocValues

Introduction

In this page you can find the example usage for org.apache.lucene.index SortedNumericDocValues SortedNumericDocValues.

Prototype

protected SortedNumericDocValues() 

Source Link

Document

Sole constructor.

Usage

From source file:org.codelibs.elasticsearch.search.aggregations.support.MissingValues.java

License:Apache License

static SortedNumericDocValues replaceMissing(final SortedNumericDocValues values, final long missing) {
    return new SortedNumericDocValues() {

        private int count;

        @Override/* www.j a  va  2  s . c o  m*/
        public void setDocument(int doc) {
            values.setDocument(doc);
            count = values.count();
        }

        @Override
        public long valueAt(int index) {
            if (count > 0) {
                return values.valueAt(index);
            } else if (index == 0) {
                return missing;
            } else {
                throw new IndexOutOfBoundsException();
            }
        }

        @Override
        public int count() {
            return count == 0 ? 1 : count;
        }

    };
}

From source file:org.elasticsearch.index.fielddata.FieldDataTests.java

License:Apache License

public void testSortableLongBitsToDoubles() {
    final double value = randomDouble();
    final long valueBits = NumericUtils.doubleToSortableLong(value);

    NumericDocValues values = new NumericDocValues() {
        @Override// w ww. ja va  2 s  .  co m
        public long get(int docID) {
            return valueBits;
        }
    };

    SortedNumericDoubleValues asMultiDoubles = FieldData
            .sortableLongBitsToDoubles(DocValues.singleton(values, null));
    NumericDoubleValues asDoubles = FieldData.unwrapSingleton(asMultiDoubles);
    assertNotNull(asDoubles);
    assertEquals(value, asDoubles.get(0), 0);

    NumericDocValues backToLongs = DocValues.unwrapSingleton(FieldData.toSortableLongBits(asMultiDoubles));
    assertSame(values, backToLongs);

    SortedNumericDocValues multiValues = new SortedNumericDocValues() {

        @Override
        public long valueAt(int index) {
            return valueBits;
        }

        @Override
        public void setDocument(int doc) {
        }

        @Override
        public int count() {
            return 1;
        }
    };

    asMultiDoubles = FieldData.sortableLongBitsToDoubles(multiValues);
    assertEquals(value, asMultiDoubles.valueAt(0), 0);
    assertSame(multiValues, FieldData.toSortableLongBits(asMultiDoubles));
}

From source file:org.elasticsearch.index.fielddata.ScriptDocValuesDatesTests.java

License:Apache License

private Dates wrap(long[][] values) {
    return new Dates(new SortedNumericDocValues() {
        long[] current;

        @Override//from   w ww  .ja  v a2s.c o m
        public void setDocument(int doc) {
            current = values[doc];
        }

        @Override
        public int count() {
            return current.length;
        }

        @Override
        public long valueAt(int index) {
            return current[index];
        }
    });
}

From source file:org.elasticsearch.index.fielddata.ScriptDocValuesLongsTests.java

License:Apache License

private Longs wrap(long[][] values) {
    return new Longs(new SortedNumericDocValues() {
        long[] current;

        @Override/*  w w  w . j a va  2s  .com*/
        public void setDocument(int doc) {
            current = values[doc];
        }

        @Override
        public int count() {
            return current.length;
        }

        @Override
        public long valueAt(int index) {
            return current[index];
        }
    });
}

From source file:org.elasticsearch.search.aggregations.bucket.composite.RoundingValuesSource.java

License:Apache License

@Override
public SortedNumericDocValues longValues(LeafReaderContext context) throws IOException {
    SortedNumericDocValues values = vs.longValues(context);
    return new SortedNumericDocValues() {
        @Override//from  w  w  w  .  jav  a  2  s  .  c o  m
        public long nextValue() throws IOException {
            return round(values.nextValue());
        }

        @Override
        public int docValueCount() {
            return values.docValueCount();
        }

        @Override
        public boolean advanceExact(int target) throws IOException {
            return values.advanceExact(target);
        }

        @Override
        public int docID() {
            return values.docID();
        }

        @Override
        public int nextDoc() throws IOException {
            return values.nextDoc();
        }

        @Override
        public int advance(int target) throws IOException {
            return values.advance(target);
        }

        @Override
        public long cost() {
            return values.cost();
        }
    };
}

From source file:org.elasticsearch.search.aggregations.support.MissingValuesTests.java

License:Apache License

public void testMissingLongs() {
    final int numDocs = TestUtil.nextInt(random(), 1, 100);
    final int[][] values = new int[numDocs][];
    for (int i = 0; i < numDocs; ++i) {
        values[i] = new int[random().nextInt(4)];
        for (int j = 0; j < values[i].length; ++j) {
            values[i][j] = randomInt();/* ww w. jav  a  2  s .c  om*/
        }
        Arrays.sort(values[i]);
    }
    SortedNumericDocValues asNumericValues = new SortedNumericDocValues() {

        int i = -1;

        @Override
        public long valueAt(int index) {
            return values[i][index];
        }

        @Override
        public void setDocument(int docId) {
            i = docId;
        }

        @Override
        public int count() {
            return values[i].length;
        }
    };
    final long missing = randomInt();
    SortedNumericDocValues withMissingReplaced = MissingValues.replaceMissing(asNumericValues, missing);
    for (int i = 0; i < numDocs; ++i) {
        withMissingReplaced.setDocument(i);
        if (values[i].length > 0) {
            assertEquals(values[i].length, withMissingReplaced.count());
            for (int j = 0; j < values[i].length; ++j) {
                assertEquals(values[i][j], withMissingReplaced.valueAt(j));
            }
        } else {
            assertEquals(1, withMissingReplaced.count());
            assertEquals(missing, withMissingReplaced.valueAt(0));
        }
    }
}

From source file:org.elasticsearch.search.MultiValueModeTests.java

License:Apache License

public void testMultiValuedLongs() throws Exception {
    final int numDocs = scaledRandomIntBetween(1, 100);
    final long[][] array = new long[numDocs][];
    for (int i = 0; i < numDocs; ++i) {
        final long[] values = new long[randomInt(4)];
        for (int j = 0; j < values.length; ++j) {
            values[j] = randomLong();// w  w  w . j a  v  a  2  s . c  o m
        }
        Arrays.sort(values);
        array[i] = values;
    }
    final SortedNumericDocValues multiValues = new SortedNumericDocValues() {
        int doc;

        @Override
        public long valueAt(int index) {
            return array[doc][index];
        }

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

        @Override
        public int count() {
            return array[doc].length;
        }
    };
    verify(multiValues, numDocs);
    final FixedBitSet rootDocs = randomRootDocs(numDocs);
    final FixedBitSet innerDocs = randomInnerDocs(rootDocs);
    verify(multiValues, numDocs, rootDocs, innerDocs);
}