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


Java LongPoint类代码示例

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


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

示例1: indexDoc

import org.apache.lucene.document.LongPoint; //导入依赖的package包/类
static void indexDoc(IndexWriter writer, Path file, long lastModified) throws IOException {
	try (InputStream stream = Files.newInputStream(file)) {
		Document doc = new Document();
		Field pathField = new StringField("path", file.toString(), Field.Store.YES);
		doc.add(pathField);
		doc.add(new LongPoint("modified", lastModified));
		doc.add(new TextField("contents", new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))));

		if (writer.getConfig().getOpenMode() == OpenMode.CREATE) {
			System.out.println("adding " + file);
			writer.addDocument(doc);
		} else {
			System.out.println("updating " + file);
			writer.updateDocument(new Term("path", file.toString()), doc);
		}
	}
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:18,代码来源:IndexFiles.java

示例2: termsQuery

import org.apache.lucene.document.LongPoint; //导入依赖的package包/类
@Override
Query termsQuery(String field, List<Object> values) {
    long[] v = new long[values.size()];
    int upTo = 0;

    for (int i = 0; i < values.size(); i++) {
        Object value = values.get(i);
        if (!hasDecimalPart(value)) {
            v[upTo++] = parse(value, true);
        }
    }

    if (upTo == 0) {
        return Queries.newMatchNoDocsQuery("All values have a decimal part");
    }
    if (upTo != v.length) {
        v = Arrays.copyOf(v, upTo);
    }
    return LongPoint.newSetQuery(field, v);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:NumberFieldMapper.java

示例3: stats

import org.apache.lucene.document.LongPoint; //导入依赖的package包/类
@Override
FieldStats.Long stats(IndexReader reader, String fieldName,
                      boolean isSearchable, boolean isAggregatable) throws IOException {
    FieldInfo fi = org.apache.lucene.index.MultiFields.getMergedFieldInfos(reader).fieldInfo(fieldName);
    if (fi == null) {
        return null;
    }
    long size = PointValues.size(reader, fieldName);
    if (size == 0) {
        return new FieldStats.Long(reader.maxDoc(), 0, -1, -1, isSearchable, isAggregatable);
    }
    int docCount = PointValues.getDocCount(reader, fieldName);
    byte[] min = PointValues.getMinPackedValue(reader, fieldName);
    byte[] max = PointValues.getMaxPackedValue(reader, fieldName);
    return new FieldStats.Long(reader.maxDoc(),docCount, -1L, size,
        isSearchable, isAggregatable,
        LongPoint.decodeDimension(min, 0), LongPoint.decodeDimension(max, 0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:NumberFieldMapper.java

示例4: stats

import org.apache.lucene.document.LongPoint; //导入依赖的package包/类
@Override
public FieldStats.Date stats(IndexReader reader) throws IOException {
    String field = name();
    FieldInfo fi = org.apache.lucene.index.MultiFields.getMergedFieldInfos(reader).fieldInfo(name());
    if (fi == null) {
        return null;
    }
    long size = PointValues.size(reader, field);
    if (size == 0) {
        return new FieldStats.Date(reader.maxDoc(), 0, -1, -1, isSearchable(), isAggregatable());
    }
    int docCount = PointValues.getDocCount(reader, field);
    byte[] min = PointValues.getMinPackedValue(reader, field);
    byte[] max = PointValues.getMaxPackedValue(reader, field);
    return new FieldStats.Date(reader.maxDoc(),docCount, -1L, size,
        isSearchable(), isAggregatable(),
        dateTimeFormatter(), LongPoint.decodeDimension(min, 0), LongPoint.decodeDimension(max, 0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:DateFieldMapper.java

示例5: rangeQuery

import org.apache.lucene.document.LongPoint; //导入依赖的package包/类
@Override
public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower,
                        boolean includeUpper, QueryShardContext context) {
    long l = Long.MIN_VALUE;
    long u = Long.MAX_VALUE;
    if (lowerTerm != null) {
        l = parse(lowerTerm);
        if (includeLower == false) {
            if (l == Long.MAX_VALUE) {
                return new MatchNoDocsQuery();
            }
            ++l;
        }
    }
    if (upperTerm != null) {
        u = parse(upperTerm);
        if (includeUpper == false) {
            if (u == Long.MIN_VALUE) {
                return new MatchNoDocsQuery();
            }
            --u;
        }
    }
    return LongPoint.newRangeQuery(name(), l, u);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:SeqNoFieldMapper.java

示例6: testIntervalYear

import org.apache.lucene.document.LongPoint; //导入依赖的package包/类
public void testIntervalYear() throws IOException {
    testBothCases(LongPoint.newRangeQuery(INSTANT_FIELD, asLong("2015-01-01"), asLong("2017-12-31")), dataset,
            aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.YEAR).field(DATE_FIELD),
            histogram -> {
                List<Histogram.Bucket> buckets = histogram.getBuckets();
                assertEquals(3, buckets.size());

                Histogram.Bucket bucket = buckets.get(0);
                assertEquals("2015-01-01T00:00:00.000Z", bucket.getKeyAsString());
                assertEquals(3, bucket.getDocCount());

                bucket = buckets.get(1);
                assertEquals("2016-01-01T00:00:00.000Z", bucket.getKeyAsString());
                assertEquals(1, bucket.getDocCount());

                bucket = buckets.get(2);
                assertEquals("2017-01-01T00:00:00.000Z", bucket.getKeyAsString());
                assertEquals(1, bucket.getDocCount());
            }
    );
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:DateHistogramAggregatorTests.java

示例7: testTermQuery

import org.apache.lucene.document.LongPoint; //导入依赖的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

示例8: testRangeQuery

import org.apache.lucene.document.LongPoint; //导入依赖的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

示例9: testLongRangeQuery

import org.apache.lucene.document.LongPoint; //导入依赖的package包/类
@Test
public void testLongRangeQuery() {
    JsonObject json = Json.createObjectBuilder()
            .add("query", Json.createObjectBuilder()
                .add("type", "RangeQuery")
                .add("rangeType", "Long")
                .add("field", "field")
                .add("lowerTerm", 1L)
                .add("upperTerm", 5L)
                .add("includeLower", JsonValue.FALSE)
                .add("includeUpper", JsonValue.TRUE))
            .build();
    QueryData q = new QueryData(new StringReader(json.toString()), queryConverter);
    Query query = LongPoint.newRangeQuery("field", 2L, 5L);
    assertEquals(query, q.query);
}
 
开发者ID:seecr,项目名称:meresco-lucene,代码行数:17,代码来源:JsonQueryConverterTest.java

示例10: testLongRangeQueryWithNoBounds

import org.apache.lucene.document.LongPoint; //导入依赖的package包/类
@Test
public void testLongRangeQueryWithNoBounds() {
    JsonObject json = Json.createObjectBuilder()
            .add("query", Json.createObjectBuilder()
                .add("type", "RangeQuery")
                .add("rangeType", "Long")
                .add("field", "field")
                .add("lowerTerm", JsonValue.NULL)
                .add("upperTerm", JsonValue.NULL)
                .add("includeLower", JsonValue.FALSE)
                .add("includeUpper", JsonValue.TRUE))
            .build();
    QueryData q = new QueryData(new StringReader(json.toString()), queryConverter);
    Query query = LongPoint.newRangeQuery("field", Long.MIN_VALUE + 1, Long.MAX_VALUE);
    assertEquals(query, q.query);
}
 
开发者ID:seecr,项目名称:meresco-lucene,代码行数:17,代码来源:JsonQueryConverterTest.java

示例11: testCreateCandidateQuery

import org.apache.lucene.document.LongPoint; //导入依赖的package包/类
public void testCreateCandidateQuery() throws Exception {
    addQueryMapping();

    MemoryIndex memoryIndex = new MemoryIndex(false);
    memoryIndex.addField("field1", "the quick brown fox jumps over the lazy dog", new WhitespaceAnalyzer());
    memoryIndex.addField("field2", "some more text", new WhitespaceAnalyzer());
    memoryIndex.addField("_field3", "unhide me", new WhitespaceAnalyzer());
    memoryIndex.addField("field4", "123", new WhitespaceAnalyzer());
    memoryIndex.addField(new LongPoint("number_field", 10L), new WhitespaceAnalyzer());

    IndexReader indexReader = memoryIndex.createSearcher().getIndexReader();

    BooleanQuery candidateQuery = (BooleanQuery) fieldType.createCandidateQuery(indexReader);
    assertEquals(2, candidateQuery.clauses().size());
    assertEquals(Occur.SHOULD, candidateQuery.clauses().get(0).getOccur());
    TermInSetQuery termsQuery = (TermInSetQuery) candidateQuery.clauses().get(0).getQuery();

    PrefixCodedTerms terms = termsQuery.getTermData();
    assertThat(terms.size(), equalTo(14L));
    PrefixCodedTerms.TermIterator termIterator = terms.iterator();
    assertTermIterator(termIterator, "_field3\u0000me", fieldType.queryTermsField.name());
    assertTermIterator(termIterator, "_field3\u0000unhide", fieldType.queryTermsField.name());
    assertTermIterator(termIterator, "field1\u0000brown", fieldType.queryTermsField.name());
    assertTermIterator(termIterator, "field1\u0000dog", fieldType.queryTermsField.name());
    assertTermIterator(termIterator, "field1\u0000fox", fieldType.queryTermsField.name());
    assertTermIterator(termIterator, "field1\u0000jumps", fieldType.queryTermsField.name());
    assertTermIterator(termIterator, "field1\u0000lazy", fieldType.queryTermsField.name());
    assertTermIterator(termIterator, "field1\u0000over", fieldType.queryTermsField.name());
    assertTermIterator(termIterator, "field1\u0000quick", fieldType.queryTermsField.name());
    assertTermIterator(termIterator, "field1\u0000the", fieldType.queryTermsField.name());
    assertTermIterator(termIterator, "field2\u0000more", fieldType.queryTermsField.name());
    assertTermIterator(termIterator, "field2\u0000some", fieldType.queryTermsField.name());
    assertTermIterator(termIterator, "field2\u0000text", fieldType.queryTermsField.name());
    assertTermIterator(termIterator, "field4\u0000123", fieldType.queryTermsField.name());

    assertEquals(Occur.SHOULD, candidateQuery.clauses().get(1).getOccur());
    assertEquals(new TermQuery(new Term(fieldType.extractionResultField.name(), EXTRACTION_FAILED)),
            candidateQuery.clauses().get(1).getQuery());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:40,代码来源:PercolatorFieldMapperTests.java

示例12: termQuery

import org.apache.lucene.document.LongPoint; //导入依赖的package包/类
@Override
Query termQuery(String field, Object value) {
    if (hasDecimalPart(value)) {
        return Queries.newMatchNoDocsQuery("Value [" + value + "] has a decimal part");
    }
    long v = parse(value, true);
    return LongPoint.newExactQuery(field, v);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:NumberFieldMapper.java

示例13: rangeQuery

import org.apache.lucene.document.LongPoint; //导入依赖的package包/类
@Override
Query rangeQuery(String field, Object lowerTerm, Object upperTerm,
                 boolean includeLower, boolean includeUpper,
                 boolean hasDocValues) {
    long l = Long.MIN_VALUE;
    long u = Long.MAX_VALUE;
    if (lowerTerm != null) {
        l = parse(lowerTerm, true);
        // if the lower bound is decimal:
        // - if the bound is positive then we increment it:
        //      if lowerTerm=1.5 then the (inclusive) bound becomes 2
        // - if the bound is negative then we leave it as is:
        //      if lowerTerm=-1.5 then the (inclusive) bound becomes -1 due to the call to longValue
        boolean lowerTermHasDecimalPart = hasDecimalPart(lowerTerm);
        if ((lowerTermHasDecimalPart == false && includeLower == false) ||
                (lowerTermHasDecimalPart && signum(lowerTerm) > 0)) {
            if (l == Long.MAX_VALUE) {
                return new MatchNoDocsQuery();
            }
            ++l;
        }
    }
    if (upperTerm != null) {
        u = parse(upperTerm, true);
        boolean upperTermHasDecimalPart = hasDecimalPart(upperTerm);
        if ((upperTermHasDecimalPart == false && includeUpper == false) ||
                (upperTermHasDecimalPart && signum(upperTerm) < 0)) {
            if (u == Long.MIN_VALUE) {
                return new MatchNoDocsQuery();
            }
            --u;
        }
    }
    Query query = LongPoint.newRangeQuery(field, l, u);
    if (hasDocValues) {
        Query dvQuery = SortedNumericDocValuesField.newRangeQuery(field, l, u);
        query = new IndexOrDocValuesQuery(query, dvQuery);
    }
    return query;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:NumberFieldMapper.java

示例14: createFields

import org.apache.lucene.document.LongPoint; //导入依赖的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 LongPoint(name, value.longValue()));
    }
    if (docValued) {
        fields.add(new SortedNumericDocValuesField(name, value.longValue()));
    }
    if (stored) {
        fields.add(new StoredField(name, value.longValue()));
    }
    return fields;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:NumberFieldMapper.java

示例15: innerRangeQuery

import org.apache.lucene.document.LongPoint; //导入依赖的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


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