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