當前位置: 首頁>>代碼示例>>Java>>正文


Java NumericDoubleValues類代碼示例

本文整理匯總了Java中org.elasticsearch.index.fielddata.NumericDoubleValues的典型用法代碼示例。如果您正苦於以下問題:Java NumericDoubleValues類的具體用法?Java NumericDoubleValues怎麽用?Java NumericDoubleValues使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NumericDoubleValues類屬於org.elasticsearch.index.fielddata包,在下文中一共展示了NumericDoubleValues類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getLeafCollector

import org.elasticsearch.index.fielddata.NumericDoubleValues; //導入依賴的package包/類
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        final LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
}
    final BigArrays bigArrays = context.bigArrays();
    final SortedNumericDoubleValues allValues = valuesSource.doubleValues(ctx);
    final NumericDoubleValues values = MultiValueMode.MAX.select(allValues, Double.NEGATIVE_INFINITY);
    return new LeafBucketCollectorBase(sub, allValues) {

        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (bucket >= maxes.size()) {
                long from = maxes.size();
                maxes = bigArrays.grow(maxes, bucket + 1);
                maxes.fill(from, maxes.size(), Double.NEGATIVE_INFINITY);
            }
            final double value = values.get(doc);
            double max = maxes.get(bucket);
            max = Math.max(max, value);
            maxes.set(bucket, max);
        }

    };
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:27,代碼來源:MaxAggregator.java

示例2: getLeafCollector

import org.elasticsearch.index.fielddata.NumericDoubleValues; //導入依賴的package包/類
@Override
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx,
        final LeafBucketCollector sub) throws IOException {
    if (valuesSource == null) {
        return LeafBucketCollector.NO_OP_COLLECTOR;
    }
    final BigArrays bigArrays = context.bigArrays();
    final SortedNumericDoubleValues allValues = valuesSource.doubleValues(ctx);
    final NumericDoubleValues values = MultiValueMode.MIN.select(allValues, Double.POSITIVE_INFINITY);
    return new LeafBucketCollectorBase(sub, allValues) {

        @Override
        public void collect(int doc, long bucket) throws IOException {
            if (bucket >= mins.size()) {
                long from = mins.size();
                mins = bigArrays.grow(mins, bucket + 1);
                mins.fill(from, mins.size(), Double.POSITIVE_INFINITY);
            }
            final double value = values.get(doc);
            double min = mins.get(bucket);
            min = Math.min(min, value);
            mins.set(bucket, min);
        }

    };
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:27,代碼來源:MinAggregator.java

示例3: distance

import org.elasticsearch.index.fielddata.NumericDoubleValues; //導入依賴的package包/類
@Override
protected NumericDoubleValues distance(LeafReaderContext context) {
    final MultiGeoPointValues geoPointValues = fieldData.load(context).getGeoPointValues();
    return mode.select(new MultiValueMode.UnsortedNumericDoubleValues() {
        @Override
        public int count() {
            return geoPointValues.count();
        }

        @Override
        public void setDocument(int docId) {
            geoPointValues.setDocument(docId);
        }

        @Override
        public double valueAt(int index) {
            GeoPoint other = geoPointValues.valueAt(index);
            return Math.max(0.0d,
                    distFunction.calculate(origin.lat(), origin.lon(), other.lat(), other.lon(), DistanceUnit.METERS) - offset);
        }
    }, 0.0);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:DecayFunctionBuilder.java

示例4: testSingleValuedDoubles

import org.elasticsearch.index.fielddata.NumericDoubleValues; //導入依賴的package包/類
public void testSingleValuedDoubles() throws Exception  {
    final int numDocs = scaledRandomIntBetween(1, 100);
    final double[] array = new double[numDocs];
    final FixedBitSet docsWithValue = randomBoolean() ? null : new FixedBitSet(numDocs);
    for (int i = 0; i < array.length; ++i) {
        if (randomBoolean()) {
            array[i] = randomDouble();
            if (docsWithValue != null) {
                docsWithValue.set(i);
            }
        } else if (docsWithValue != null && randomBoolean()) {
            docsWithValue.set(i);
        }
    }
    final NumericDoubleValues singleValues = new NumericDoubleValues() {
        @Override
        public double get(int docID) {
            return array[docID];
        }
    };
    final SortedNumericDoubleValues multiValues = FieldData.singleton(singleValues, docsWithValue);
    verify(multiValues, numDocs);
    final FixedBitSet rootDocs = randomRootDocs(numDocs);
    final FixedBitSet innerDocs = randomInnerDocs(rootDocs);
    verify(multiValues, numDocs, rootDocs, innerDocs);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:27,代碼來源:MultiValueModeTests.java

示例5: distance

import org.elasticsearch.index.fielddata.NumericDoubleValues; //導入依賴的package包/類
@Override
protected NumericDoubleValues distance(LeafReaderContext context) {
    final MultiGeoPointValues geoPointValues = fieldData.load(context).getGeoPointValues();
    return mode.select(new MultiValueMode.UnsortedNumericDoubleValues() {
        @Override
        public int count() {
            return geoPointValues.count();
        }

        @Override
        public void setDocument(int docId) {
            geoPointValues.setDocument(docId);
        }

        @Override
        public double valueAt(int index) {
            GeoPoint other = geoPointValues.valueAt(index);
            return Math.max(0.0d, distFunction.calculate(origin.lat(), origin.lon(), other.lat(), other.lon(), DistanceUnit.METERS) - offset);
        }
    }, 0.0);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:22,代碼來源:DecayFunctionParser.java

示例6: getValues

import org.elasticsearch.index.fielddata.NumericDoubleValues; //導入依賴的package包/類
@Override
@SuppressWarnings("rawtypes") // ValueSource uses a rawtype
public FunctionValues getValues(Map context, LeafReaderContext leaf) throws IOException {
    AtomicNumericFieldData leafData = (AtomicNumericFieldData) fieldData.load(leaf);
    NumericDoubleValues docValues = multiValueMode.select(leafData.getDoubleValues(), 0d);
    return new DoubleDocValues(this) {
      @Override
      public double doubleVal(int doc) {
        return docValues.get(doc);
      }
    };
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:FieldDataValueSource.java

示例7: getValues

import org.elasticsearch.index.fielddata.NumericDoubleValues; //導入依賴的package包/類
@Override
@SuppressWarnings("rawtypes") // ValueSource uses a rawtype
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);
      }
    };
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:DateObjectValueSource.java

示例8: getValues

import org.elasticsearch.index.fielddata.NumericDoubleValues; //導入依賴的package包/類
@Override
@SuppressWarnings("rawtypes") // ValueSource uses a rawtype
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);
      }
    };
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:DateMethodValueSource.java

示例9: getDoubleValues

import org.elasticsearch.index.fielddata.NumericDoubleValues; //導入依賴的package包/類
@Override
public SortedNumericDoubleValues getDoubleValues() {
    final SortedNumericDocValues values = scaledFieldData.getLongValues();
    final NumericDocValues singleValues = DocValues.unwrapSingleton(values);
    if (singleValues != null) {
        return FieldData.singleton(new NumericDoubleValues() {
            @Override
            public double get(int docID) {
                return singleValues.get(docID) * scalingFactorInverse;
            }
        }, DocValues.unwrapSingletonBits(values));
    } else {
        return new SortedNumericDoubleValues() {

            @Override
            public double valueAt(int index) {
                return values.valueAt(index) * scalingFactorInverse;
            }

            @Override
            public void setDocument(int doc) {
                values.setDocument(doc);
            }

            @Override
            public int count() {
                return values.count();
            }
        };
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:32,代碼來源:ScaledFloatFieldMapper.java

示例10: verify

import org.elasticsearch.index.fielddata.NumericDoubleValues; //導入依賴的package包/類
private void verify(SortedNumericDoubleValues values, int maxDoc, FixedBitSet rootDocs, FixedBitSet innerDocs) throws IOException {
    for (long missingValue : new long[] { 0, randomLong() }) {
        for (MultiValueMode mode : new MultiValueMode[] {MultiValueMode.MIN, MultiValueMode.MAX, MultiValueMode.SUM, MultiValueMode.AVG}) {
            final NumericDoubleValues 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 double actual = selected.get(root);
                double expected = 0.0;
                if (mode == MultiValueMode.MAX) {
                    expected = Long.MIN_VALUE;
                } else if (mode == MultiValueMode.MIN) {
                    expected = Long.MAX_VALUE;
                }
                int numValues = 0;
                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 (mode == MultiValueMode.SUM || mode == MultiValueMode.AVG) {
                            expected += values.valueAt(j);
                        } else if (mode == MultiValueMode.MIN) {
                            expected = Math.min(expected, values.valueAt(j));
                        } else if (mode == MultiValueMode.MAX) {
                            expected = Math.max(expected, values.valueAt(j));
                        }
                        ++numValues;
                    }
                }
                if (numValues == 0) {
                    expected = missingValue;
                } else if (mode == MultiValueMode.AVG) {
                    expected = expected/numValues;
                }

                assertEquals(mode.toString() + " docId=" + root, expected, actual, 0.1);

                prevRoot = root;
            }
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:41,代碼來源:MultiValueModeTests.java

示例11: testUnsortedSingleValuedDoubles

import org.elasticsearch.index.fielddata.NumericDoubleValues; //導入依賴的package包/類
public void testUnsortedSingleValuedDoubles() throws Exception  {
    final int numDocs = scaledRandomIntBetween(1, 100);
    final double[] array = new double[numDocs];
    final FixedBitSet docsWithValue = randomBoolean() ? null : new FixedBitSet(numDocs);
    for (int i = 0; i < array.length; ++i) {
        if (randomBoolean()) {
            array[i] = randomDouble();
            if (docsWithValue != null) {
                docsWithValue.set(i);
            }
        } else if (docsWithValue != null && randomBoolean()) {
            docsWithValue.set(i);
        }
    }
    final NumericDoubleValues singleValues = new NumericDoubleValues() {
        @Override
        public double get(int docID) {
            return array[docID];
        }
    };
    final SortedNumericDoubleValues singletonValues = FieldData.singleton(singleValues, docsWithValue);
    final MultiValueMode.UnsortedNumericDoubleValues multiValues = new MultiValueMode.UnsortedNumericDoubleValues() {

        @Override
        public int count() {
            return singletonValues.count();
        }

        @Override
        public void setDocument(int doc) {
            singletonValues.setDocument(doc);
        }

        @Override
        public double valueAt(int index) {
            return Math.cos(singletonValues.valueAt(index));
        }
    };
    verify(multiValues, numDocs);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:41,代碼來源:MultiValueModeTests.java

示例12: getField

import org.elasticsearch.index.fielddata.NumericDoubleValues; //導入依賴的package包/類
public NumericDoubleValues getField(final int ordinal, LeafReaderContext ctx)
    throws IOException {
  if (ordinal > names.length) {
    throw new IndexOutOfBoundsException(
        "ValuesSource array index " + ordinal + " out of bounds");
  }
  return multiValueMode.select(values[ordinal].doubleValues(ctx), Double.NEGATIVE_INFINITY);
}
 
開發者ID:scaleborn,項目名稱:elasticsearch-linear-regression,代碼行數:9,代碼來源:MultiValuesSource.java

示例13: getField

import org.elasticsearch.index.fielddata.NumericDoubleValues; //導入依賴的package包/類
public NumericDoubleValues getField(final int ordinal, LeafReaderContext ctx) throws IOException {
    if (ordinal > names.length) {
        throw new IndexOutOfBoundsException("ValuesSource array index " + ordinal + " out of bounds");
    }
    return multiValueMode.select(values[ordinal].doubleValues(ctx), Double.NEGATIVE_INFINITY);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:7,代碼來源:MultiValuesSource.java

示例14: build

import org.elasticsearch.index.fielddata.NumericDoubleValues; //導入依賴的package包/類
@Override
public SortFieldAndFormat build(QueryShardContext context) throws IOException {
    final SearchScript searchScript = context.getSearchScript(script, ScriptContext.Standard.SEARCH);

    MultiValueMode valueMode = null;
    if (sortMode != null) {
        valueMode = MultiValueMode.fromString(sortMode.toString());
    }
    boolean reverse = (order == SortOrder.DESC);
    if (valueMode == null) {
        valueMode = reverse ? MultiValueMode.MAX : MultiValueMode.MIN;
    }

    final Nested nested = resolveNested(context, nestedPath, nestedFilter);
    final IndexFieldData.XFieldComparatorSource fieldComparatorSource;
    switch (type) {
        case STRING:
            fieldComparatorSource = new BytesRefFieldComparatorSource(null, null, valueMode, nested) {
                LeafSearchScript leafScript;
                @Override
                protected SortedBinaryDocValues getValues(LeafReaderContext context) throws IOException {
                    leafScript = searchScript.getLeafSearchScript(context);
                    final BinaryDocValues values = new BinaryDocValues() {
                        final BytesRefBuilder spare = new BytesRefBuilder();
                        @Override
                        public BytesRef get(int docID) {
                            leafScript.setDocument(docID);
                            spare.copyChars(leafScript.run().toString());
                            return spare.get();
                        }
                    };
                    return FieldData.singleton(values, null);
                }
                @Override
                protected void setScorer(Scorer scorer) {
                    leafScript.setScorer(scorer);
                }
            };
            break;
        case NUMBER:
            fieldComparatorSource = new DoubleValuesComparatorSource(null, Double.MAX_VALUE, valueMode, nested) {
                LeafSearchScript leafScript;
                @Override
                protected SortedNumericDoubleValues getValues(LeafReaderContext context) throws IOException {
                    leafScript = searchScript.getLeafSearchScript(context);
                    final NumericDoubleValues values = new NumericDoubleValues() {
                        @Override
                        public double get(int docID) {
                            leafScript.setDocument(docID);
                            return leafScript.runAsDouble();
                        }
                    };
                    return FieldData.singleton(values, null);
                }
                @Override
                protected void setScorer(Scorer scorer) {
                    leafScript.setScorer(scorer);
                }
            };
            break;
        default:
        throw new QueryShardException(context, "custom script sort type [" + type + "] not supported");
    }

    return new SortFieldAndFormat(new SortField("_script", fieldComparatorSource, reverse), DocValueFormat.RAW);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:67,代碼來源:ScriptSortBuilder.java


注:本文中的org.elasticsearch.index.fielddata.NumericDoubleValues類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。