Search in sources :

Example 6 with SortedNumericDocValuesField

use of org.apache.lucene.document.SortedNumericDocValuesField in project elasticsearch by elastic.

the class MaxAggregatorTests method testSomeMatchesSortedNumericDocValues.

public void testSomeMatchesSortedNumericDocValues() throws IOException {
    testCase(new FieldValueQuery("number"), iw -> {
        iw.addDocument(singleton(new SortedNumericDocValuesField("number", 7)));
        iw.addDocument(singleton(new SortedNumericDocValuesField("number", 1)));
    }, max -> {
        assertEquals(7, max.getValue(), 0);
    });
}
Also used : SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) FieldValueQuery(org.apache.lucene.search.FieldValueQuery)

Example 7 with SortedNumericDocValuesField

use of org.apache.lucene.document.SortedNumericDocValuesField in project elasticsearch by elastic.

the class StatsAggregatorTests method testRandomLongs.

public void testRandomLongs() throws IOException {
    MappedFieldType ft = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
    ft.setName("field");
    final SimpleStatsAggregator expected = new SimpleStatsAggregator();
    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);
    });
}
Also used : SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) Document(org.apache.lucene.document.Document)

Example 8 with SortedNumericDocValuesField

use of org.apache.lucene.document.SortedNumericDocValuesField in project elasticsearch by elastic.

the class AvgAggregatorTests method testSomeMatchesSortedNumericDocValues.

public void testSomeMatchesSortedNumericDocValues() throws IOException {
    testCase(new FieldValueQuery("number"), iw -> {
        iw.addDocument(singleton(new SortedNumericDocValuesField("number", 7)));
        iw.addDocument(singleton(new SortedNumericDocValuesField("number", 2)));
        iw.addDocument(singleton(new SortedNumericDocValuesField("number", 3)));
    }, avg -> {
        assertEquals(4, avg.getValue(), 0);
    });
}
Also used : SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) FieldValueQuery(org.apache.lucene.search.FieldValueQuery)

Example 9 with SortedNumericDocValuesField

use of org.apache.lucene.document.SortedNumericDocValuesField in project elasticsearch by elastic.

the class ValueCountAggregatorTests method testSomeMatchesSortedNumericDocValues.

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

Example 10 with SortedNumericDocValuesField

use of org.apache.lucene.document.SortedNumericDocValuesField 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)

Aggregations

SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)104 Document (org.apache.lucene.document.Document)86 Directory (org.apache.lucene.store.Directory)72 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)44 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)40 IndexReader (org.apache.lucene.index.IndexReader)35 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)27 BytesRef (org.apache.lucene.util.BytesRef)21 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)19 SortedNumericSortField (org.apache.lucene.search.SortedNumericSortField)19 SortedDocValuesField (org.apache.lucene.document.SortedDocValuesField)18 StringField (org.apache.lucene.document.StringField)18 IndexSearcher (org.apache.lucene.search.IndexSearcher)18 SortedSetDocValuesField (org.apache.lucene.document.SortedSetDocValuesField)16 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)16 Sort (org.apache.lucene.search.Sort)15 SortField (org.apache.lucene.search.SortField)14 SortedSetSortField (org.apache.lucene.search.SortedSetSortField)13 BinaryDocValuesField (org.apache.lucene.document.BinaryDocValuesField)12 StoredField (org.apache.lucene.document.StoredField)12