Search in sources :

Example 1 with SortedBinaryDocValues

use of org.elasticsearch.index.fielddata.SortedBinaryDocValues in project elasticsearch by elastic.

the class MultiValueModeTests method verify.

private void verify(SortedBinaryDocValues values, int maxDoc) {
    for (BytesRef missingValue : new BytesRef[] { new BytesRef(), new BytesRef(RandomStrings.randomAsciiOfLength(random(), 8)) }) {
        for (MultiValueMode mode : new MultiValueMode[] { MultiValueMode.MIN, MultiValueMode.MAX }) {
            final BinaryDocValues selected = mode.select(values, missingValue);
            for (int i = 0; i < maxDoc; ++i) {
                final BytesRef actual = selected.get(i);
                BytesRef expected = null;
                values.setDocument(i);
                int numValues = values.count();
                if (numValues == 0) {
                    expected = missingValue;
                } else {
                    for (int j = 0; j < numValues; ++j) {
                        if (expected == null) {
                            expected = BytesRef.deepCopyOf(values.valueAt(j));
                        } else {
                            if (mode == MultiValueMode.MIN) {
                                expected = expected.compareTo(values.valueAt(j)) <= 0 ? expected : BytesRef.deepCopyOf(values.valueAt(j));
                            } else if (mode == MultiValueMode.MAX) {
                                expected = expected.compareTo(values.valueAt(j)) > 0 ? expected : BytesRef.deepCopyOf(values.valueAt(j));
                            }
                        }
                    }
                    if (expected == null) {
                        expected = missingValue;
                    }
                }
                assertEquals(mode.toString() + " docId=" + i, expected, actual);
            }
        }
    }
}
Also used : BytesRef(org.apache.lucene.util.BytesRef) SortedBinaryDocValues(org.elasticsearch.index.fielddata.SortedBinaryDocValues) BinaryDocValues(org.apache.lucene.index.BinaryDocValues)

Example 2 with SortedBinaryDocValues

use of org.elasticsearch.index.fielddata.SortedBinaryDocValues in project elasticsearch by elastic.

the class MultiValueModeTests method testSingleValuedStrings.

public void testSingleValuedStrings() throws Exception {
    final int numDocs = scaledRandomIntBetween(1, 100);
    final BytesRef[] array = new BytesRef[numDocs];
    final FixedBitSet docsWithValue = randomBoolean() ? null : new FixedBitSet(numDocs);
    for (int i = 0; i < array.length; ++i) {
        if (randomBoolean()) {
            array[i] = new BytesRef(RandomStrings.randomAsciiOfLength(random(), 8));
            if (docsWithValue != null) {
                docsWithValue.set(i);
            }
        } else {
            array[i] = new BytesRef();
            if (docsWithValue != null && randomBoolean()) {
                docsWithValue.set(i);
            }
        }
    }
    final BinaryDocValues singleValues = new BinaryDocValues() {

        @Override
        public BytesRef get(int docID) {
            return BytesRef.deepCopyOf(array[docID]);
        }
    };
    final SortedBinaryDocValues multiValues = FieldData.singleton(singleValues, docsWithValue);
    verify(multiValues, numDocs);
    final FixedBitSet rootDocs = randomRootDocs(numDocs);
    final FixedBitSet innerDocs = randomInnerDocs(rootDocs);
    verify(multiValues, numDocs, rootDocs, innerDocs);
}
Also used : FixedBitSet(org.apache.lucene.util.FixedBitSet) BytesRef(org.apache.lucene.util.BytesRef) SortedBinaryDocValues(org.elasticsearch.index.fielddata.SortedBinaryDocValues) BinaryDocValues(org.apache.lucene.index.BinaryDocValues) SortedBinaryDocValues(org.elasticsearch.index.fielddata.SortedBinaryDocValues)

Example 3 with SortedBinaryDocValues

use of org.elasticsearch.index.fielddata.SortedBinaryDocValues in project elasticsearch by elastic.

the class MultiValueModeTests method verify.

private void verify(SortedBinaryDocValues values, int maxDoc, FixedBitSet rootDocs, FixedBitSet innerDocs) throws IOException {
    for (BytesRef missingValue : new BytesRef[] { new BytesRef(), new BytesRef(RandomStrings.randomAsciiOfLength(random(), 8)) }) {
        for (MultiValueMode mode : new MultiValueMode[] { MultiValueMode.MIN, MultiValueMode.MAX }) {
            final BinaryDocValues selected = mode.select(values, missingValue, rootDocs, new BitSetIterator(innerDocs, 0L), maxDoc);
            int prevRoot = -1;
            for (int root = rootDocs.nextSetBit(0); root != -1; root = root + 1 < maxDoc ? rootDocs.nextSetBit(root + 1) : -1) {
                final BytesRef actual = selected.get(root);
                BytesRef expected = null;
                for (int child = innerDocs.nextSetBit(prevRoot + 1); child != -1 && child < root; child = innerDocs.nextSetBit(child + 1)) {
                    values.setDocument(child);
                    for (int j = 0; j < values.count(); ++j) {
                        if (expected == null) {
                            expected = BytesRef.deepCopyOf(values.valueAt(j));
                        } else {
                            if (mode == MultiValueMode.MIN) {
                                expected = expected.compareTo(values.valueAt(j)) <= 0 ? expected : BytesRef.deepCopyOf(values.valueAt(j));
                            } else if (mode == MultiValueMode.MAX) {
                                expected = expected.compareTo(values.valueAt(j)) > 0 ? expected : BytesRef.deepCopyOf(values.valueAt(j));
                            }
                        }
                    }
                }
                if (expected == null) {
                    expected = missingValue;
                }
                assertEquals(mode.toString() + " docId=" + root, expected, actual);
                prevRoot = root;
            }
        }
    }
}
Also used : BitSetIterator(org.apache.lucene.util.BitSetIterator) BytesRef(org.apache.lucene.util.BytesRef) SortedBinaryDocValues(org.elasticsearch.index.fielddata.SortedBinaryDocValues) BinaryDocValues(org.apache.lucene.index.BinaryDocValues)

Example 4 with SortedBinaryDocValues

use of org.elasticsearch.index.fielddata.SortedBinaryDocValues in project elasticsearch by elastic.

the class ValuesSourceConfigTests method testEmptyKeyword.

public void testEmptyKeyword() throws Exception {
    IndexService indexService = createIndex("index", Settings.EMPTY, "type", "bytes", "type=keyword");
    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.Bytes> config = ValuesSourceConfig.resolve(context, null, "bytes", null, null, null, null);
        ValuesSource.Bytes valuesSource = config.toValuesSource(context);
        LeafReaderContext ctx = searcher.reader().leaves().get(0);
        SortedBinaryDocValues values = valuesSource.bytesValues(ctx);
        values.setDocument(0);
        assertEquals(0, values.count());
        config = ValuesSourceConfig.resolve(context, null, "bytes", null, "abc", null, null);
        valuesSource = config.toValuesSource(context);
        values = valuesSource.bytesValues(ctx);
        values.setDocument(0);
        assertEquals(1, values.count());
        assertEquals(new BytesRef("abc"), values.valueAt(0));
    }
}
Also used : IndexService(org.elasticsearch.index.IndexService) Searcher(org.elasticsearch.index.engine.Engine.Searcher) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) BytesRef(org.apache.lucene.util.BytesRef) SortedBinaryDocValues(org.elasticsearch.index.fielddata.SortedBinaryDocValues)

Example 5 with SortedBinaryDocValues

use of org.elasticsearch.index.fielddata.SortedBinaryDocValues in project elasticsearch by elastic.

the class ValuesSourceConfigTests method testKeyword.

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

Aggregations

SortedBinaryDocValues (org.elasticsearch.index.fielddata.SortedBinaryDocValues)17 BytesRef (org.apache.lucene.util.BytesRef)13 BinaryDocValues (org.apache.lucene.index.BinaryDocValues)6 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)6 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)3 IndexService (org.elasticsearch.index.IndexService)3 Searcher (org.elasticsearch.index.engine.Engine.Searcher)3 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)3 IOException (java.io.IOException)2 SortedDocValues (org.apache.lucene.index.SortedDocValues)2 Scorer (org.apache.lucene.search.Scorer)2 FixedBitSet (org.apache.lucene.util.FixedBitSet)2 LeafBucketCollectorBase (org.elasticsearch.search.aggregations.LeafBucketCollectorBase)2 RandomAccessOrds (org.apache.lucene.index.RandomAccessOrds)1 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)1 Explanation (org.apache.lucene.search.Explanation)1 SortField (org.apache.lucene.search.SortField)1 ByteArrayDataInput (org.apache.lucene.store.ByteArrayDataInput)1 BitSet (org.apache.lucene.util.BitSet)1 BitSetIterator (org.apache.lucene.util.BitSetIterator)1