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


Java MatchAllDocsQuery类代码示例

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


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

示例1: testCreateMultiDocumentSearcher

import org.apache.lucene.search.MatchAllDocsQuery; //导入依赖的package包/类
public void testCreateMultiDocumentSearcher() throws Exception {
    int numDocs = randomIntBetween(2, 8);
    List<ParseContext.Document> docs = new ArrayList<>(numDocs);
    for (int i = 0; i < numDocs; i++) {
        docs.add(new ParseContext.Document());
    }

    Analyzer analyzer = new WhitespaceAnalyzer();
    ParsedDocument parsedDocument = new ParsedDocument(null, null, "_id", "_type", null, docs, null, null, null);
    IndexSearcher indexSearcher = PercolateQueryBuilder.createMultiDocumentSearcher(analyzer, parsedDocument);
    assertThat(indexSearcher.getIndexReader().numDocs(), equalTo(numDocs));

    // ensure that any query get modified so that the nested docs are never included as hits:
    Query query = new MatchAllDocsQuery();
    BooleanQuery result = (BooleanQuery) indexSearcher.createNormalizedWeight(query, true).getQuery();
    assertThat(result.clauses().size(), equalTo(2));
    assertThat(result.clauses().get(0).getQuery(), sameInstance(query));
    assertThat(result.clauses().get(0).getOccur(), equalTo(BooleanClause.Occur.MUST));
    assertThat(result.clauses().get(1).getOccur(), equalTo(BooleanClause.Occur.MUST_NOT));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:PercolateQueryBuilderTests.java

示例2: doToQuery

import org.apache.lucene.search.MatchAllDocsQuery; //导入依赖的package包/类
@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
    BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder();
    booleanQueryBuilder.setDisableCoord(disableCoord);
    addBooleanClauses(context, booleanQueryBuilder, mustClauses, BooleanClause.Occur.MUST);
    addBooleanClauses(context, booleanQueryBuilder, mustNotClauses, BooleanClause.Occur.MUST_NOT);
    addBooleanClauses(context, booleanQueryBuilder, shouldClauses, BooleanClause.Occur.SHOULD);
    addBooleanClauses(context, booleanQueryBuilder, filterClauses, BooleanClause.Occur.FILTER);
    BooleanQuery booleanQuery = booleanQueryBuilder.build();
    if (booleanQuery.clauses().isEmpty()) {
        return new MatchAllDocsQuery();
    }

    final String minimumShouldMatch;
    if (context.isFilter() && this.minimumShouldMatch == null && shouldClauses.size() > 0) {
        minimumShouldMatch = "1";
    } else {
        minimumShouldMatch = this.minimumShouldMatch;
    }
    Query query = Queries.applyMinimumShouldMatch(booleanQuery, minimumShouldMatch);
    return adjustPureNegative ? fixNegativeQueryIfNeeded(query) : query;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:BoolQueryBuilder.java

示例3: testNoDocs

import org.apache.lucene.search.MatchAllDocsQuery; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void testNoDocs() throws IOException {
    try (Directory directory = newDirectory()) {
        try (RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory)) {
            // intentionally not writing any docs
        }
        try (IndexReader indexReader = DirectoryReader.open(directory)) {
            ScriptedMetricAggregationBuilder aggregationBuilder = new ScriptedMetricAggregationBuilder(AGG_NAME);
            aggregationBuilder.mapScript(MAP_SCRIPT); // map script is mandatory, even if its not used in this case
            ScriptedMetric scriptedMetric = search(newSearcher(indexReader, true, true), new MatchAllDocsQuery(), aggregationBuilder);
            assertEquals(AGG_NAME, scriptedMetric.getName());
            assertNotNull(scriptedMetric.aggregation());
            assertEquals(0, ((HashMap<Object, String>) scriptedMetric.aggregation()).size());
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:ScriptedMetricAggregatorTests.java

示例4: testScriptedMetricWithoutCombine

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

示例5: testScriptedMetricWithCombine

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

示例6: testCase

import org.apache.lucene.search.MatchAllDocsQuery; //导入依赖的package包/类
public void testCase(MappedFieldType ft,
                     CheckedConsumer<RandomIndexWriter, IOException> buildIndex,
                     Consumer<InternalExtendedStats> verify) throws IOException {
    try (Directory directory = newDirectory();
         RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory)) {
        buildIndex.accept(indexWriter);
        try (IndexReader reader = indexWriter.getReader()) {
            IndexSearcher searcher = new IndexSearcher(reader);
            ExtendedStatsAggregationBuilder aggBuilder = new ExtendedStatsAggregationBuilder("my_agg")
                .field("field")
                .sigma(randomDoubleBetween(0, 10, true));
            InternalExtendedStats stats = search(searcher, new MatchAllDocsQuery(), aggBuilder, ft);
            verify.accept(stats);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:ExtendedStatsAggregatorTests.java

示例7: testEmpty

import org.apache.lucene.search.MatchAllDocsQuery; //导入依赖的package包/类
public void testEmpty() throws Exception {
    try (Directory dir = newDirectory();
         RandomIndexWriter w = new RandomIndexWriter(random(), dir)) {
        GeoBoundsAggregationBuilder aggBuilder = new GeoBoundsAggregationBuilder("my_agg")
            .field("field")
            .wrapLongitude(false);

        MappedFieldType fieldType = new GeoPointFieldMapper.GeoPointFieldType();
        fieldType.setHasDocValues(true);
        fieldType.setName("field");
        try (IndexReader reader = w.getReader()) {
            IndexSearcher searcher = new IndexSearcher(reader);
            InternalGeoBounds bounds = search(searcher, new MatchAllDocsQuery(), aggBuilder, fieldType);
            assertTrue(Double.isInfinite(bounds.top));
            assertTrue(Double.isInfinite(bounds.bottom));
            assertTrue(Double.isInfinite(bounds.posLeft));
            assertTrue(Double.isInfinite(bounds.posRight));
            assertTrue(Double.isInfinite(bounds.negLeft));
            assertTrue(Double.isInfinite(bounds.negRight));
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:GeoBoundsAggregatorTests.java

示例8: testTopLevel

import org.apache.lucene.search.MatchAllDocsQuery; //导入依赖的package包/类
public void testTopLevel() throws Exception {
    Aggregation result;
    if (randomBoolean()) {
        result = testCase(new MatchAllDocsQuery(), topHits("_name").sort("string", SortOrder.DESC));
    } else {
        Query query = new QueryParser("string", new KeywordAnalyzer()).parse("d^1000 c^100 b^10 a^1");
        result = testCase(query, topHits("_name"));
    }
    SearchHits searchHits = ((TopHits) result).getHits();
    assertEquals(3L, searchHits.getTotalHits());
    assertEquals("3", searchHits.getAt(0).getId());
    assertEquals("type", searchHits.getAt(0).getType());
    assertEquals("2", searchHits.getAt(1).getId());
    assertEquals("type", searchHits.getAt(1).getType());
    assertEquals("1", searchHits.getAt(2).getId());
    assertEquals("type", searchHits.getAt(2).getType());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:TopHitsAggregatorTests.java

示例9: testNumericDocValues

import org.apache.lucene.search.MatchAllDocsQuery; //导入依赖的package包/类
public void testNumericDocValues() throws IOException {
    testCase(new MatchAllDocsQuery(), iw -> {
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 1)));
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 2)));
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 1)));
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 2)));
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 1)));
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 2)));
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 1)));
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 2)));
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 1)));
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 2)));
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 1)));
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 2)));
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 1)));
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 2)));
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 1)));
        iw.addDocument(singleton(new NumericDocValuesField(FIELD_NAME, 2)));
    }, count -> assertEquals(24L, count.getValue(), 0d));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:SumAggregatorTests.java

示例10: testMinAggregator_noDocs

import org.apache.lucene.search.MatchAllDocsQuery; //导入依赖的package包/类
public void testMinAggregator_noDocs() throws Exception {
    Directory directory = newDirectory();
    RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
    indexWriter.close();

    IndexReader indexReader = DirectoryReader.open(directory);
    IndexSearcher indexSearcher = newSearcher(indexReader, true, true);

    MinAggregationBuilder aggregationBuilder = new MinAggregationBuilder("_name").field("number");
    MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
    fieldType.setName("number");
    try (MinAggregator aggregator = createAggregator(aggregationBuilder, indexSearcher, fieldType)) {
        aggregator.preCollection();
        indexSearcher.search(new MatchAllDocsQuery(), aggregator);
        aggregator.postCollection();
        InternalMin result = (InternalMin) aggregator.buildAggregation(0L);
        assertEquals(Double.POSITIVE_INFINITY, result.getValue(), 0);
    }
    indexReader.close();
    directory.close();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:MinAggregatorTests.java

示例11: testNoDocs

import org.apache.lucene.search.MatchAllDocsQuery; //导入依赖的package包/类
public void testNoDocs() throws IOException {
    Directory directory = newDirectory();

    RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
    // intentionally not writing any docs
    indexWriter.close();
    IndexReader indexReader = DirectoryReader.open(directory);

    testCase(new MatchAllDocsQuery(), newSearcher(indexReader, false, true), parentToChild -> {
        assertEquals(0, parentToChild.getDocCount());
        assertEquals(Double.POSITIVE_INFINITY, ((InternalMin) parentToChild.getAggregations().get("in_child")).getValue(),
                Double.MIN_VALUE);
    });
    indexReader.close();
    directory.close();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:ParentToChildrenAggregatorTests.java

示例12: testCase

import org.apache.lucene.search.MatchAllDocsQuery; //导入依赖的package包/类
private void testCase(IndexSearcher indexSearcher, MappedFieldType genreFieldType, String executionHint,
                      Consumer<InternalSampler> verify) throws IOException {
    MappedFieldType idFieldType = new KeywordFieldMapper.KeywordFieldType();
    idFieldType.setName("id");
    idFieldType.setHasDocValues(true);

    SortedNumericDVIndexFieldData fieldData = new SortedNumericDVIndexFieldData(new Index("index", "index"), "price",
            IndexNumericFieldData.NumericType.DOUBLE);
    FunctionScoreQuery query = new FunctionScoreQuery(new MatchAllDocsQuery(),
            new FieldValueFactorFunction("price", 1, FieldValueFactorFunction.Modifier.RECIPROCAL, null, fieldData));

    DiversifiedAggregationBuilder builder = new DiversifiedAggregationBuilder("_name")
            .field(genreFieldType.name())
            .executionHint(executionHint)
            .subAggregation(new TermsAggregationBuilder("terms", null).field("id"));

    InternalSampler result = search(indexSearcher, query, builder, genreFieldType, idFieldType);
    verify.accept(result);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:DiversifiedSamplerTests.java

示例13: testDiversifiedSampler_noDocs

import org.apache.lucene.search.MatchAllDocsQuery; //导入依赖的package包/类
public void testDiversifiedSampler_noDocs() throws Exception {
    Directory directory = newDirectory();
    RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
    indexWriter.close();
    IndexReader indexReader = DirectoryReader.open(directory);
    IndexSearcher indexSearcher = new IndexSearcher(indexReader);

    MappedFieldType idFieldType = new KeywordFieldMapper.KeywordFieldType();
    idFieldType.setName("id");
    idFieldType.setHasDocValues(true);

    MappedFieldType genreFieldType = new KeywordFieldMapper.KeywordFieldType();
    genreFieldType.setName("genre");
    genreFieldType.setHasDocValues(true);

    DiversifiedAggregationBuilder builder = new DiversifiedAggregationBuilder("_name")
            .field(genreFieldType.name())
            .subAggregation(new TermsAggregationBuilder("terms", null).field("id"));

    InternalSampler result = search(indexSearcher, new MatchAllDocsQuery(), builder, genreFieldType, idFieldType);
    Terms terms = result.getAggregations().get("terms");
    assertEquals(0, terms.getBuckets().size());
    indexReader.close();
    directory.close();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:DiversifiedSamplerTests.java

示例14: testEmpty

import org.apache.lucene.search.MatchAllDocsQuery; //导入依赖的package包/类
public void testEmpty() throws Exception {
    Directory directory = newDirectory();
    RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
    indexWriter.close();
    IndexReader indexReader = DirectoryReader.open(directory);
    IndexSearcher indexSearcher = newSearcher(indexReader, true, true);
    int numFilters = randomIntBetween(1, 10);
    QueryBuilder[] filters = new QueryBuilder[numFilters];
    for (int i = 0; i < filters.length; i++) {
        filters[i] = QueryBuilders.termQuery("field", randomAsciiOfLength(5));
    }
    FiltersAggregationBuilder builder = new FiltersAggregationBuilder("test", filters);
    builder.otherBucketKey("other");
    InternalFilters response = search(indexSearcher, new MatchAllDocsQuery(), builder, fieldType);
    assertEquals(response.getBuckets().size(), numFilters);
    for (InternalFilters.InternalBucket filter : response.getBuckets()) {
        assertEquals(filter.getDocCount(), 0);
    }
    indexReader.close();
    directory.close();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:FiltersAggregatorTests.java

示例15: testMatchAllDocs

import org.apache.lucene.search.MatchAllDocsQuery; //导入依赖的package包/类
public void testMatchAllDocs() throws IOException {
    Query query = new MatchAllDocsQuery();

    testSearchCase(query, dataset,
            aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.YEAR).field(DATE_FIELD),
            histogram -> assertEquals(6, histogram.getBuckets().size())
    );
    testSearchAndReduceCase(query, dataset,
            aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.YEAR).field(DATE_FIELD),
            histogram -> assertEquals(8, histogram.getBuckets().size())
    );
    testBothCases(query, dataset,
            aggregation -> aggregation.dateHistogramInterval(DateHistogramInterval.YEAR).field(DATE_FIELD).minDocCount(1L),
            histogram -> assertEquals(6, histogram.getBuckets().size())
    );
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:DateHistogramAggregatorTests.java


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