当前位置: 首页>>代码示例>>Java>>正文


Java SortedNumericDocValuesField类代码示例

本文整理汇总了Java中org.apache.lucene.document.SortedNumericDocValuesField的典型用法代码示例。如果您正苦于以下问题:Java SortedNumericDocValuesField类的具体用法?Java SortedNumericDocValuesField怎么用?Java SortedNumericDocValuesField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SortedNumericDocValuesField类属于org.apache.lucene.document包,在下文中一共展示了SortedNumericDocValuesField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createFields

import org.apache.lucene.document.SortedNumericDocValuesField; //导入依赖的package包/类
@Override
public List<Field> createFields(String name, Number value,
                                boolean indexed, boolean docValued, boolean stored) {
    List<Field> fields = new ArrayList<>();
    if (indexed) {
        fields.add(new HalfFloatPoint(name, value.floatValue()));
    }
    if (docValued) {
        fields.add(new SortedNumericDocValuesField(name,
            HalfFloatPoint.halfFloatToSortableShort(value.floatValue())));
    }
    if (stored) {
        fields.add(new StoredField(name, value.floatValue()));
    }
    return fields;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:NumberFieldMapper.java

示例2: parseCreateField

import org.apache.lucene.document.SortedNumericDocValuesField; //导入依赖的package包/类
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException {
    if (fieldType().indexOptions() == IndexOptions.NONE && !fieldType().stored() && !fieldType().hasDocValues()) {
        return;
    }

    Boolean value = context.parseExternalValue(Boolean.class);
    if (value == null) {
        XContentParser.Token token = context.parser().currentToken();
        if (token == XContentParser.Token.VALUE_NULL) {
            if (fieldType().nullValue() != null) {
                value = fieldType().nullValue();
            }
        } else {
            if (indexCreatedVersion.onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) {
                value = context.parser().booleanValue();
            } else {
                value = context.parser().booleanValueLenient();
                if (context.parser().isBooleanValueLenient() != context.parser().isBooleanValue()) {
                    String rawValue = context.parser().text();
                    deprecationLogger.deprecated("Expected a boolean for property [{}] but got [{}]", fieldType().name(), rawValue);
                }
            }
        }
    }

    if (value == null) {
        return;
    }
    if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) {
        fields.add(new Field(fieldType().name(), value ? "T" : "F", fieldType()));
    }
    if (fieldType().hasDocValues()) {
        fields.add(new SortedNumericDocValuesField(fieldType().name(), value ? 1 : 0));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:BooleanFieldMapper.java

示例3: testScriptedMetricWithoutCombine

import org.apache.lucene.document.SortedNumericDocValuesField; //导入依赖的package包/类
/**
 * without combine script, the "_aggs" map should contain a list of the size of the number of documents matched
 */
@SuppressWarnings("unchecked")
public void testScriptedMetricWithoutCombine() throws IOException {
    try (Directory directory = newDirectory()) {
        int numDocs = randomInt(100);
        try (RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory)) {
            for (int i = 0; i < numDocs; i++) {
                indexWriter.addDocument(singleton(new SortedNumericDocValuesField("number", i)));
            }
        }
        try (IndexReader indexReader = DirectoryReader.open(directory)) {
            ScriptedMetricAggregationBuilder aggregationBuilder = new ScriptedMetricAggregationBuilder(AGG_NAME);
            aggregationBuilder.initScript(INIT_SCRIPT).mapScript(MAP_SCRIPT);
            ScriptedMetric scriptedMetric = search(newSearcher(indexReader, true, true), new MatchAllDocsQuery(), aggregationBuilder);
            assertEquals(AGG_NAME, scriptedMetric.getName());
            assertNotNull(scriptedMetric.aggregation());
            Map<String, Object> agg = (Map<String, Object>) scriptedMetric.aggregation();
            assertEquals(numDocs, ((List<Integer>) agg.get("collector")).size());
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:ScriptedMetricAggregatorTests.java

示例4: testScriptedMetricWithCombine

import org.apache.lucene.document.SortedNumericDocValuesField; //导入依赖的package包/类
/**
 * test that combine script sums the list produced by the "mapScript"
 */
public void testScriptedMetricWithCombine() throws IOException {
    try (Directory directory = newDirectory()) {
        Integer numDocs = randomInt(100);
        try (RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory)) {
            for (int i = 0; i < numDocs; i++) {
                indexWriter.addDocument(singleton(new SortedNumericDocValuesField("number", i)));
            }
        }
        try (IndexReader indexReader = DirectoryReader.open(directory)) {
            ScriptedMetricAggregationBuilder aggregationBuilder = new ScriptedMetricAggregationBuilder(AGG_NAME);
            aggregationBuilder.initScript(INIT_SCRIPT).mapScript(MAP_SCRIPT).combineScript(COMBINE_SCRIPT);
            ScriptedMetric scriptedMetric = search(newSearcher(indexReader, true, true), new MatchAllDocsQuery(), aggregationBuilder);
            assertEquals(AGG_NAME, scriptedMetric.getName());
            assertNotNull(scriptedMetric.aggregation());
            assertEquals(numDocs, scriptedMetric.aggregation());
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:ScriptedMetricAggregatorTests.java

示例5: testMinDocCount

import org.apache.lucene.document.SortedNumericDocValuesField; //导入依赖的package包/类
public void testMinDocCount() throws Exception {
    try (Directory dir = newDirectory();
            RandomIndexWriter w = new RandomIndexWriter(random(), dir)) {
        for (long value : new long[] {7, 3, -10, -6, 5, 50}) {
            Document doc = new Document();
            doc.add(new SortedNumericDocValuesField("field", value));
            w.addDocument(doc);
        }

        HistogramAggregationBuilder aggBuilder = new HistogramAggregationBuilder("my_agg")
                .field("field")
                .interval(10)
                .minDocCount(2);
        MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
        fieldType.setName("field");
        try (IndexReader reader = w.getReader()) {
            IndexSearcher searcher = new IndexSearcher(reader);
            Histogram histogram = searchAndReduce(searcher, new MatchAllDocsQuery(), aggBuilder, fieldType);
            assertEquals(2, histogram.getBuckets().size());
            assertEquals(-10d, histogram.getBuckets().get(0).getKey());
            assertEquals(2, histogram.getBuckets().get(0).getDocCount());
            assertEquals(0d, histogram.getBuckets().get(1).getKey());
            assertEquals(3, histogram.getBuckets().get(1).getDocCount());
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:HistogramAggregatorTests.java

示例6: testTermQuery

import org.apache.lucene.document.SortedNumericDocValuesField; //导入依赖的package包/类
public void testTermQuery() {
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).build();
    QueryShardContext context = new QueryShardContext(0,
            new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(),
                    indexSettings),
            null, null, null, null, null, xContentRegistry(), null, null, () -> nowInMillis);
    MappedFieldType ft = createDefaultFieldType();
    ft.setName("field");
    String date = "2015-10-12T14:10:55";
    long instant = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parser().parseDateTime(date).getMillis();
    ft.setIndexOptions(IndexOptions.DOCS);
    Query expected = new IndexOrDocValuesQuery(
            LongPoint.newRangeQuery("field", instant, instant + 999),
            SortedNumericDocValuesField.newRangeQuery("field", instant, instant + 999));
    assertEquals(expected, ft.termQuery(date, context));

    ft.setIndexOptions(IndexOptions.NONE);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
            () -> ft.termQuery(date, context));
    assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:DateFieldTypeTests.java

示例7: testRangeQuery

import org.apache.lucene.document.SortedNumericDocValuesField; //导入依赖的package包/类
public void testRangeQuery() throws IOException {
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).build();
    QueryShardContext context = new QueryShardContext(0,
            new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(), indexSettings),
            null, null, null, null, null, xContentRegistry(), null, null, () -> nowInMillis);
    MappedFieldType ft = createDefaultFieldType();
    ft.setName("field");
    String date1 = "2015-10-12T14:10:55";
    String date2 = "2016-04-28T11:33:52";
    long instant1 = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parser().parseDateTime(date1).getMillis();
    long instant2 = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parser().parseDateTime(date2).getMillis() + 999;
    ft.setIndexOptions(IndexOptions.DOCS);
    Query expected = new IndexOrDocValuesQuery(
            LongPoint.newRangeQuery("field", instant1, instant2),
            SortedNumericDocValuesField.newRangeQuery("field", instant1, instant2));
    assertEquals(expected,
            ft.rangeQuery(date1, date2, true, true, context).rewrite(new MultiReader()));

    ft.setIndexOptions(IndexOptions.NONE);
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
            () -> ft.rangeQuery(date1, date2, true, true, context));
    assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:DateFieldTypeTests.java

示例8: parseCreateField

import org.apache.lucene.document.SortedNumericDocValuesField; //导入依赖的package包/类
@Override
protected void parseCreateField(ParseContext context, List<IndexableField> fields)
        throws IOException {
    final Object value;
    if (context.externalValueSet()) {
        value = context.externalValue();
    } else {
        value = context.parser().textOrNull();
    }
    if (value != null) {
        final BytesRef bytes = new BytesRef(value.toString());
        final long hash = MurmurHash3.hash128(bytes.bytes, bytes.offset, bytes.length, 0, new MurmurHash3.Hash128()).h1;
        fields.add(new SortedNumericDocValuesField(fieldType().name(), hash));
        if (fieldType().stored()) {
            fields.add(new StoredField(name(), hash));
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:Murmur3FieldMapper.java

示例9: parseCreateField

import org.apache.lucene.document.SortedNumericDocValuesField; //导入依赖的package包/类
@Override
protected void parseCreateField(ParseContext context, List<Field> fields) throws IOException {
    if (fieldType().indexOptions() == IndexOptions.NONE && !fieldType().stored() && !fieldType().hasDocValues()) {
        return;
    }

    Boolean value = context.parseExternalValue(Boolean.class);
    if (value == null) {
        XContentParser.Token token = context.parser().currentToken();
        if (token == XContentParser.Token.VALUE_NULL) {
            if (fieldType().nullValue() != null) {
                value = fieldType().nullValue();
            }
        } else {
            value = context.parser().booleanValue();
        }
    }

    if (value == null) {
        return;
    }
    fields.add(new Field(fieldType().names().indexName(), value ? "T" : "F", fieldType()));
    if (fieldType().hasDocValues()) {
        fields.add(new SortedNumericDocValuesField(fieldType().names().indexName(), value ? 1 : 0));
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:27,代码来源:BooleanFieldMapper.java

示例10: testSingleton

import org.apache.lucene.document.SortedNumericDocValuesField; //导入依赖的package包/类
public void testSingleton() throws Exception {
  Directory dir = newDirectory();
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  doc.add(new SortedNumericDocValuesField("value", 5));
  doc.add(newStringField("id", "2", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new SortedNumericDocValuesField("value", 3));
  doc.add(newStringField("id", "1", Field.Store.YES));
  writer.addDocument(doc);
  IndexReader ir = writer.getReader();
  writer.close();
  
  IndexSearcher searcher = newSearcher(ir);
  Sort sort = new Sort(new SortedNumericSortField("value", SortField.Type.INT));

  TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
  assertEquals(2, td.totalHits);
  // 3 comes before 5
  assertEquals("1", searcher.doc(td.scoreDocs[0].doc).get("id"));
  assertEquals("2", searcher.doc(td.scoreDocs[1].doc).get("id"));

  ir.close();
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:TestSortedNumericSortField.java

示例11: rangeQuery

import org.apache.lucene.document.SortedNumericDocValuesField; //导入依赖的package包/类
@Override
Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
                 boolean includeLower, boolean includeUpper,
                 boolean hasDocValues) {
    float l = Float.NEGATIVE_INFINITY;
    float u = Float.POSITIVE_INFINITY;
    if (lowerTerm != null) {
        l = parse(lowerTerm, false);
        if (includeLower) {
            l = HalfFloatPoint.nextDown(l);
        }
        l = HalfFloatPoint.nextUp(l);
    }
    if (upperTerm != null) {
        u = parse(upperTerm, false);
        if (includeUpper) {
            u = HalfFloatPoint.nextUp(u);
        }
        u = HalfFloatPoint.nextDown(u);
    }
    Query query = HalfFloatPoint.newRangeQuery(field, l, u);
    if (hasDocValues) {
        Query dvQuery = SortedNumericDocValuesField.newRangeQuery(field,
                HalfFloatPoint.halfFloatToSortableShort(l),
                HalfFloatPoint.halfFloatToSortableShort(u));
        query = new IndexOrDocValuesQuery(query, dvQuery);
    }
    return query;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:NumberFieldMapper.java

示例12: innerRangeQuery

import org.apache.lucene.document.SortedNumericDocValuesField; //导入依赖的package包/类
Query innerRangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper,
        @Nullable DateTimeZone timeZone, @Nullable DateMathParser forcedDateParser, QueryShardContext context) {
    failIfNotIndexed();
    DateMathParser parser = forcedDateParser == null
            ? dateMathParser
            : forcedDateParser;
    long l, u;
    if (lowerTerm == null) {
        l = Long.MIN_VALUE;
    } else {
        l = parseToMilliseconds(lowerTerm, !includeLower, timeZone, parser, context);
        if (includeLower == false) {
            ++l;
        }
    }
    if (upperTerm == null) {
        u = Long.MAX_VALUE;
    } else {
        u = parseToMilliseconds(upperTerm, includeUpper, timeZone, parser, context);
        if (includeUpper == false) {
            --u;
        }
    }
    Query query = LongPoint.newRangeQuery(name(), l, u);
    if (hasDocValues()) {
        Query dvQuery = SortedNumericDocValuesField.newRangeQuery(name(), l, u);
        query = new IndexOrDocValuesQuery(query, dvQuery);
    }
    return query;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:DateFieldMapper.java

示例13: postParse

import org.apache.lucene.document.SortedNumericDocValuesField; //导入依赖的package包/类
@Override
public void postParse(ParseContext context) throws IOException {
    // In the case of nested docs, let's fill nested docs with seqNo=1 and
    // primaryTerm=0 so that Lucene doesn't write a Bitset for documents
    // that don't have the field. This is consistent with the default value
    // for efficiency.
    for (int i = 1; i < context.docs().size(); i++) {
        final Document doc = context.docs().get(i);
        doc.add(new LongPoint(NAME, 1));
        doc.add(new SortedNumericDocValuesField(NAME, 1L));
        doc.add(new NumericDocValuesField(PRIMARY_TERM_NAME, 0L));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:SeqNoFieldMapper.java

示例14: testRandomDoubles

import org.apache.lucene.document.SortedNumericDocValuesField; //导入依赖的package包/类
public void testRandomDoubles() throws IOException {
    MappedFieldType ft =
        new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE);
    ft.setName("field");
    final ExtendedSimpleStatsAggregator expected = new ExtendedSimpleStatsAggregator();
    testCase(ft,
        iw -> {
            int numDocs = randomIntBetween(10, 50);
            for (int i = 0; i < numDocs; i++) {
                Document doc = new Document();
                int numValues = randomIntBetween(1, 5);
                for (int j = 0; j < numValues; j++) {
                    double value = randomDoubleBetween(-100d, 100d, true);
                    long valueAsLong = NumericUtils.doubleToSortableLong(value);
                    doc.add(new SortedNumericDocValuesField("field", valueAsLong));
                    expected.add(value);
                }
                iw.addDocument(doc);
            }
        },
        stats -> {
            assertEquals(expected.count, stats.getCount(), 0);
            assertEquals(expected.sum, stats.getSum(), TOLERANCE);
            assertEquals(expected.min, stats.getMin(), 0);
            assertEquals(expected.max, stats.getMax(), 0);
            assertEquals(expected.sum / expected.count, stats.getAvg(), TOLERANCE);
            assertEquals(expected.sumOfSqrs, stats.getSumOfSquares(), TOLERANCE);
            assertEquals(expected.stdDev(), stats.getStdDeviation(), TOLERANCE);
            assertEquals(expected.variance(), stats.getVariance(), TOLERANCE);
            assertEquals(expected.stdDevBound(ExtendedStats.Bounds.LOWER, stats.getSigma()),
                stats.getStdDeviationBound(ExtendedStats.Bounds.LOWER), TOLERANCE);
            assertEquals(expected.stdDevBound(ExtendedStats.Bounds.UPPER, stats.getSigma()),
                stats.getStdDeviationBound(ExtendedStats.Bounds.UPPER), TOLERANCE);
        }
    );
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:37,代码来源:ExtendedStatsAggregatorTests.java

示例15: testRandomLongs

import org.apache.lucene.document.SortedNumericDocValuesField; //导入依赖的package包/类
public void testRandomLongs() throws IOException {
    MappedFieldType ft =
        new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
    ft.setName("field");
    final ExtendedSimpleStatsAggregator expected = new ExtendedSimpleStatsAggregator();
    testCase(ft,
        iw -> {
            int numDocs = randomIntBetween(10, 50);
            for (int i = 0; i < numDocs; i++) {
                Document doc = new Document();
                int numValues = randomIntBetween(1, 5);
                for (int j = 0; j < numValues; j++) {
                    long value = randomIntBetween(-100, 100);
                    doc.add(new SortedNumericDocValuesField("field", value));
                    expected.add(value);
                }
                iw.addDocument(doc);
            }
        },
        stats -> {
            assertEquals(expected.count, stats.getCount(), 0);
            assertEquals(expected.sum, stats.getSum(), TOLERANCE);
            assertEquals(expected.min, stats.getMin(), 0);
            assertEquals(expected.max, stats.getMax(), 0);
            assertEquals(expected.sum / expected.count, stats.getAvg(), TOLERANCE);
            assertEquals(expected.sumOfSqrs, stats.getSumOfSquares(), TOLERANCE);
            assertEquals(expected.stdDev(), stats.getStdDeviation(), TOLERANCE);
            assertEquals(expected.variance(), stats.getVariance(), TOLERANCE);
            assertEquals(expected.stdDevBound(ExtendedStats.Bounds.LOWER, stats.getSigma()),
                stats.getStdDeviationBound(ExtendedStats.Bounds.LOWER), TOLERANCE);
            assertEquals(expected.stdDevBound(ExtendedStats.Bounds.UPPER, stats.getSigma()),
                stats.getStdDeviationBound(ExtendedStats.Bounds.UPPER), TOLERANCE);
        }
    );
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:ExtendedStatsAggregatorTests.java


注:本文中的org.apache.lucene.document.SortedNumericDocValuesField类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。