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);
}
}
}
}
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);
}
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;
}
}
}
}
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));
}
}
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));
}
}
Aggregations