Search in sources :

Example 26 with SortedNumericDocValues

use of org.apache.lucene.index.SortedNumericDocValues in project elasticsearch by elastic.

the class FieldDataTests method testDoublesToSortableLongBits.

public void testDoublesToSortableLongBits() {
    final double value = randomDouble();
    final long valueBits = NumericUtils.doubleToSortableLong(value);
    NumericDoubleValues values = new NumericDoubleValues() {

        @Override
        public double get(int docID) {
            return value;
        }
    };
    SortedNumericDocValues asMultiLongs = FieldData.toSortableLongBits(FieldData.singleton(values, null));
    NumericDocValues asLongs = DocValues.unwrapSingleton(asMultiLongs);
    assertNotNull(asLongs);
    assertEquals(valueBits, asLongs.get(0));
    SortedNumericDoubleValues multiValues = new SortedNumericDoubleValues() {

        @Override
        public double valueAt(int index) {
            return value;
        }

        @Override
        public void setDocument(int doc) {
        }

        @Override
        public int count() {
            return 1;
        }
    };
    asMultiLongs = FieldData.toSortableLongBits(multiValues);
    assertEquals(valueBits, asMultiLongs.valueAt(0));
    assertSame(multiValues, FieldData.sortableLongBitsToDoubles(asMultiLongs));
}
Also used : NumericDocValues(org.apache.lucene.index.NumericDocValues) SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues)

Example 27 with SortedNumericDocValues

use of org.apache.lucene.index.SortedNumericDocValues in project elasticsearch by elastic.

the class ValuesSourceConfigTests method testLong.

public void testLong() throws Exception {
    IndexService indexService = createIndex("index", Settings.EMPTY, "type", "long", "type=long");
    client().prepareIndex("index", "type", "1").setSource("long", 42).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
        ValuesSourceConfig<ValuesSource.Numeric> config = ValuesSourceConfig.resolve(context, null, "long", null, null, null, null);
        ValuesSource.Numeric valuesSource = config.toValuesSource(context);
        LeafReaderContext ctx = searcher.reader().leaves().get(0);
        SortedNumericDocValues values = valuesSource.longValues(ctx);
        values.setDocument(0);
        assertEquals(1, values.count());
        assertEquals(42, values.valueAt(0));
    }
}
Also used : SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) IndexService(org.elasticsearch.index.IndexService) Searcher(org.elasticsearch.index.engine.Engine.Searcher) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext)

Example 28 with SortedNumericDocValues

use of org.apache.lucene.index.SortedNumericDocValues in project elasticsearch by elastic.

the class ValuesSourceConfigTests method testEmptyBoolean.

public void testEmptyBoolean() throws Exception {
    IndexService indexService = createIndex("index", Settings.EMPTY, "type", "bool", "type=boolean");
    client().prepareIndex("index", "type", "1").setSource().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
        ValuesSourceConfig<ValuesSource.Numeric> config = ValuesSourceConfig.resolve(context, null, "bool", null, null, null, null);
        ValuesSource.Numeric valuesSource = config.toValuesSource(context);
        LeafReaderContext ctx = searcher.reader().leaves().get(0);
        SortedNumericDocValues values = valuesSource.longValues(ctx);
        values.setDocument(0);
        assertEquals(0, values.count());
        config = ValuesSourceConfig.resolve(context, null, "bool", null, true, null, null);
        valuesSource = config.toValuesSource(context);
        values = valuesSource.longValues(ctx);
        values.setDocument(0);
        assertEquals(1, values.count());
        assertEquals(1, values.valueAt(0));
    }
}
Also used : SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) IndexService(org.elasticsearch.index.IndexService) Searcher(org.elasticsearch.index.engine.Engine.Searcher) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext)

Example 29 with SortedNumericDocValues

use of org.apache.lucene.index.SortedNumericDocValues in project elasticsearch by elastic.

the class ValuesSourceConfigTests method testUnmappedBoolean.

public void testUnmappedBoolean() throws Exception {
    IndexService indexService = createIndex("index", Settings.EMPTY, "type");
    client().prepareIndex("index", "type", "1").setSource().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    try (Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        QueryShardContext context = indexService.newQueryShardContext(0, searcher.reader(), () -> 42L);
        ValuesSourceConfig<ValuesSource.Numeric> config = ValuesSourceConfig.resolve(context, ValueType.BOOLEAN, "bool", null, null, null, null);
        ValuesSource.Numeric valuesSource = config.toValuesSource(context);
        assertNull(valuesSource);
        config = ValuesSourceConfig.resolve(context, ValueType.BOOLEAN, "bool", null, true, null, null);
        valuesSource = config.toValuesSource(context);
        LeafReaderContext ctx = searcher.reader().leaves().get(0);
        SortedNumericDocValues values = valuesSource.longValues(ctx);
        values.setDocument(0);
        assertEquals(1, values.count());
        assertEquals(1, values.valueAt(0));
    }
}
Also used : SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) IndexService(org.elasticsearch.index.IndexService) Searcher(org.elasticsearch.index.engine.Engine.Searcher) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext)

Example 30 with SortedNumericDocValues

use of org.apache.lucene.index.SortedNumericDocValues in project elasticsearch by elastic.

the class MissingValuesTests method testMissingLongs.

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();
        }
        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));
        }
    }
}
Also used : SortedNumericDocValues(org.apache.lucene.index.SortedNumericDocValues) GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Aggregations

SortedNumericDocValues (org.apache.lucene.index.SortedNumericDocValues)44 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)23 NumericDocValues (org.apache.lucene.index.NumericDocValues)13 LeafReader (org.apache.lucene.index.LeafReader)10 BytesRef (org.apache.lucene.util.BytesRef)7 Document (org.apache.lucene.document.Document)6 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)6 Directory (org.apache.lucene.store.Directory)6 IndexService (org.elasticsearch.index.IndexService)6 Searcher (org.elasticsearch.index.engine.Engine.Searcher)6 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)6 IOException (java.io.IOException)5 BinaryDocValues (org.apache.lucene.index.BinaryDocValues)5 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)5 SortedDocValues (org.apache.lucene.index.SortedDocValues)5 SortedSetDocValues (org.apache.lucene.index.SortedSetDocValues)5 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)4 DirectoryReader (org.apache.lucene.index.DirectoryReader)4 IndexWriter (org.apache.lucene.index.IndexWriter)4 BitSet (org.apache.lucene.util.BitSet)4