Search in sources :

Example 1 with AtomicNumericFieldData

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

the class CountMethodValueSource method getValues.

@Override
// ValueSource uses a rawtype
@SuppressWarnings("rawtypes")
public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException {
    AtomicNumericFieldData leafData = (AtomicNumericFieldData) fieldData.load(leaf);
    final SortedNumericDoubleValues values = leafData.getDoubleValues();
    return new DoubleDocValues(this) {

        @Override
        public double doubleVal(int doc) {
            values.setDocument(doc);
            return values.count();
        }
    };
}
Also used : DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues) AtomicNumericFieldData(org.elasticsearch.index.fielddata.AtomicNumericFieldData)

Example 2 with AtomicNumericFieldData

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

the class DateMethodValueSource method getValues.

@Override
// ValueSource uses a rawtype
@SuppressWarnings("rawtypes")
public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException {
    AtomicNumericFieldData leafData = (AtomicNumericFieldData) fieldData.load(leaf);
    final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT);
    NumericDoubleValues docValues = multiValueMode.select(leafData.getDoubleValues(), 0d);
    return new DoubleDocValues(this) {

        @Override
        public double doubleVal(int docId) {
            long millis = (long) docValues.get(docId);
            calendar.setTimeInMillis(millis);
            return calendar.get(calendarType);
        }
    };
}
Also used : Calendar(java.util.Calendar) DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) NumericDoubleValues(org.elasticsearch.index.fielddata.NumericDoubleValues) AtomicNumericFieldData(org.elasticsearch.index.fielddata.AtomicNumericFieldData)

Example 3 with AtomicNumericFieldData

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

the class DateObjectValueSource method getValues.

@Override
// ValueSource uses a rawtype
@SuppressWarnings("rawtypes")
public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException {
    AtomicNumericFieldData leafData = (AtomicNumericFieldData) fieldData.load(leaf);
    MutableDateTime joda = new MutableDateTime(0, DateTimeZone.UTC);
    NumericDoubleValues docValues = multiValueMode.select(leafData.getDoubleValues(), 0d);
    return new DoubleDocValues(this) {

        @Override
        public double doubleVal(int docId) {
            long millis = (long) docValues.get(docId);
            joda.setMillis(millis);
            return function.applyAsInt(joda);
        }
    };
}
Also used : DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) MutableDateTime(org.joda.time.MutableDateTime) NumericDoubleValues(org.elasticsearch.index.fielddata.NumericDoubleValues) AtomicNumericFieldData(org.elasticsearch.index.fielddata.AtomicNumericFieldData)

Example 4 with AtomicNumericFieldData

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

the class EmptyMemberValueSource method getValues.

@Override
// ValueSource uses a rawtype
@SuppressWarnings("rawtypes")
public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException {
    AtomicNumericFieldData leafData = (AtomicNumericFieldData) fieldData.load(leaf);
    final SortedNumericDoubleValues values = leafData.getDoubleValues();
    return new DoubleDocValues(this) {

        @Override
        public double doubleVal(int doc) {
            values.setDocument(doc);
            if (values.count() == 0) {
                return 1;
            } else {
                return 0;
            }
        }
    };
}
Also used : DoubleDocValues(org.apache.lucene.queries.function.docvalues.DoubleDocValues) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues) AtomicNumericFieldData(org.elasticsearch.index.fielddata.AtomicNumericFieldData)

Example 5 with AtomicNumericFieldData

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

the class ScaledFloatFieldTypeTests method testFieldData.

public void testFieldData() throws IOException {
    ScaledFloatFieldMapper.ScaledFloatFieldType ft = new ScaledFloatFieldMapper.ScaledFloatFieldType();
    ft.setScalingFactor(0.1 + randomDouble() * 100);
    Directory dir = newDirectory();
    IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(null));
    Document doc = new Document();
    doc.add(new SortedNumericDocValuesField("scaled_float1", 10));
    doc.add(new SortedNumericDocValuesField("scaled_float2", 5));
    doc.add(new SortedNumericDocValuesField("scaled_float2", 12));
    w.addDocument(doc);
    try (DirectoryReader reader = DirectoryReader.open(w)) {
        IndexMetaData indexMetadata = new IndexMetaData.Builder("index").settings(Settings.builder().put("index.version.created", Version.CURRENT).put("index.number_of_shards", 1).put("index.number_of_replicas", 0).build()).build();
        IndexSettings indexSettings = new IndexSettings(indexMetadata, Settings.EMPTY);
        // single-valued
        ft.setName("scaled_float1");
        IndexNumericFieldData fielddata = (IndexNumericFieldData) ft.fielddataBuilder().build(indexSettings, ft, null, null, null);
        assertEquals(fielddata.getNumericType(), IndexNumericFieldData.NumericType.DOUBLE);
        AtomicNumericFieldData leafFieldData = fielddata.load(reader.leaves().get(0));
        SortedNumericDoubleValues values = leafFieldData.getDoubleValues();
        values.setDocument(0);
        assertEquals(1, values.count());
        assertEquals(10 / ft.getScalingFactor(), values.valueAt(0), 10e-5);
        // multi-valued
        ft.setName("scaled_float2");
        fielddata = (IndexNumericFieldData) ft.fielddataBuilder().build(indexSettings, ft, null, null, null);
        leafFieldData = fielddata.load(reader.leaves().get(0));
        values = leafFieldData.getDoubleValues();
        values.setDocument(0);
        assertEquals(2, values.count());
        assertEquals(5 / ft.getScalingFactor(), values.valueAt(0), 10e-5);
        assertEquals(12 / ft.getScalingFactor(), values.valueAt(1), 10e-5);
    }
    IOUtils.close(w, dir);
}
Also used : DirectoryReader(org.apache.lucene.index.DirectoryReader) IndexSettings(org.elasticsearch.index.IndexSettings) IndexNumericFieldData(org.elasticsearch.index.fielddata.IndexNumericFieldData) Document(org.apache.lucene.document.Document) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) IndexWriter(org.apache.lucene.index.IndexWriter) SortedNumericDoubleValues(org.elasticsearch.index.fielddata.SortedNumericDoubleValues) AtomicNumericFieldData(org.elasticsearch.index.fielddata.AtomicNumericFieldData) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Aggregations

AtomicNumericFieldData (org.elasticsearch.index.fielddata.AtomicNumericFieldData)6 DoubleDocValues (org.apache.lucene.queries.function.docvalues.DoubleDocValues)5 NumericDoubleValues (org.elasticsearch.index.fielddata.NumericDoubleValues)3 SortedNumericDoubleValues (org.elasticsearch.index.fielddata.SortedNumericDoubleValues)3 Calendar (java.util.Calendar)1 Document (org.apache.lucene.document.Document)1 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)1 DirectoryReader (org.apache.lucene.index.DirectoryReader)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)1 Directory (org.apache.lucene.store.Directory)1 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)1 IndexSettings (org.elasticsearch.index.IndexSettings)1 IndexNumericFieldData (org.elasticsearch.index.fielddata.IndexNumericFieldData)1 MutableDateTime (org.joda.time.MutableDateTime)1