Search in sources :

Example 16 with MatchAllDocsQuery

use of org.apache.lucene.search.MatchAllDocsQuery in project elasticsearch by elastic.

the class TermsAggregatorTests method buildInternalAggregation.

private InternalAggregation buildInternalAggregation(TermsAggregationBuilder builder, MappedFieldType fieldType, IndexSearcher searcher) throws IOException {
    try (TermsAggregator aggregator = createAggregator(builder, searcher, fieldType)) {
        aggregator.preCollection();
        searcher.search(new MatchAllDocsQuery(), aggregator);
        aggregator.postCollection();
        return aggregator.buildAggregation(0L);
    }
}
Also used : MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Example 17 with MatchAllDocsQuery

use of org.apache.lucene.search.MatchAllDocsQuery in project elasticsearch by elastic.

the class StatsAggregatorTests method testCase.

public void testCase(MappedFieldType ft, CheckedConsumer<RandomIndexWriter, IOException> buildIndex, Consumer<InternalStats> 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);
            StatsAggregationBuilder aggBuilder = new StatsAggregationBuilder("my_agg").field("field");
            InternalStats stats = search(searcher, new MatchAllDocsQuery(), aggBuilder, ft);
            verify.accept(stats);
        }
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) StatsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.stats.StatsAggregationBuilder) InternalStats(org.elasticsearch.search.aggregations.metrics.stats.InternalStats) IndexReader(org.apache.lucene.index.IndexReader) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory)

Example 18 with MatchAllDocsQuery

use of org.apache.lucene.search.MatchAllDocsQuery in project elasticsearch by elastic.

the class ValueCountAggregatorTests method testNoMatchingField.

public void testNoMatchingField() throws IOException {
    testCase(new MatchAllDocsQuery(), ValueType.LONG, iw -> {
        iw.addDocument(singleton(new SortedNumericDocValuesField("wrong_number", 7)));
        iw.addDocument(singleton(new SortedNumericDocValuesField("wrong_number", 1)));
    }, count -> assertEquals(0L, count.getValue()));
}
Also used : SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Example 19 with MatchAllDocsQuery

use of org.apache.lucene.search.MatchAllDocsQuery in project elasticsearch by elastic.

the class HDRPercentileRanksAggregatorTests method testEmpty.

public void testEmpty() throws IOException {
    PercentileRanksAggregationBuilder aggBuilder = new PercentileRanksAggregationBuilder("my_agg").field("field").method(PercentilesMethod.HDR).values(0.5);
    MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE);
    fieldType.setName("field");
    try (IndexReader reader = new MultiReader()) {
        IndexSearcher searcher = new IndexSearcher(reader);
        PercentileRanks ranks = search(searcher, new MatchAllDocsQuery(), aggBuilder, fieldType);
        Percentile rank = ranks.iterator().next();
        assertEquals(Double.NaN, rank.getPercent(), 0d);
        assertEquals(0.5, rank.getValue(), 0d);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Percentile(org.elasticsearch.search.aggregations.metrics.percentiles.Percentile) PercentileRanksAggregationBuilder(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksAggregationBuilder) MultiReader(org.apache.lucene.index.MultiReader) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) IndexReader(org.apache.lucene.index.IndexReader) PercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Example 20 with MatchAllDocsQuery

use of org.apache.lucene.search.MatchAllDocsQuery in project elasticsearch by elastic.

the class HDRPercentileRanksAggregatorTests method testSimple.

public void testSimple() throws IOException {
    try (Directory dir = newDirectory();
        RandomIndexWriter w = new RandomIndexWriter(random(), dir)) {
        for (double value : new double[] { 3, 0.2, 10 }) {
            Document doc = new Document();
            doc.add(new SortedNumericDocValuesField("field", NumericUtils.doubleToSortableLong(value)));
            w.addDocument(doc);
        }
        PercentileRanksAggregationBuilder aggBuilder = new PercentileRanksAggregationBuilder("my_agg").field("field").method(PercentilesMethod.HDR).values(0.1, 0.5, 12);
        MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.DOUBLE);
        fieldType.setName("field");
        try (IndexReader reader = w.getReader()) {
            IndexSearcher searcher = new IndexSearcher(reader);
            PercentileRanks ranks = search(searcher, new MatchAllDocsQuery(), aggBuilder, fieldType);
            Iterator<Percentile> rankIterator = ranks.iterator();
            Percentile rank = rankIterator.next();
            assertEquals(0.1, rank.getValue(), 0d);
            assertThat(rank.getPercent(), Matchers.equalTo(0d));
            rank = rankIterator.next();
            assertEquals(0.5, rank.getValue(), 0d);
            assertThat(rank.getPercent(), Matchers.greaterThan(0d));
            assertThat(rank.getPercent(), Matchers.lessThan(100d));
            rank = rankIterator.next();
            assertEquals(12, rank.getValue(), 0d);
            assertThat(rank.getPercent(), Matchers.equalTo(100d));
            assertFalse(rankIterator.hasNext());
        }
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) Percentile(org.elasticsearch.search.aggregations.metrics.percentiles.Percentile) PercentileRanksAggregationBuilder(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksAggregationBuilder) Document(org.apache.lucene.document.Document) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) IndexReader(org.apache.lucene.index.IndexReader) PercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanks) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory)

Aggregations

MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)282 IndexSearcher (org.apache.lucene.search.IndexSearcher)168 Directory (org.apache.lucene.store.Directory)133 Document (org.apache.lucene.document.Document)122 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)122 IndexReader (org.apache.lucene.index.IndexReader)118 TopDocs (org.apache.lucene.search.TopDocs)91 Sort (org.apache.lucene.search.Sort)71 SortField (org.apache.lucene.search.SortField)64 Query (org.apache.lucene.search.Query)52 BooleanQuery (org.apache.lucene.search.BooleanQuery)49 TermQuery (org.apache.lucene.search.TermQuery)48 FacetsCollector (org.apache.lucene.facet.FacetsCollector)40 Facets (org.apache.lucene.facet.Facets)34 Term (org.apache.lucene.index.Term)33 DirectoryReader (org.apache.lucene.index.DirectoryReader)30 ArrayList (java.util.ArrayList)29 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)28 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)23 FacetResult (org.apache.lucene.facet.FacetResult)22