Search in sources :

Example 11 with MultiValueMode

use of org.elasticsearch.search.MultiValueMode in project elasticsearch by elastic.

the class DoubleNestedSortingTests method assertAvgScoreMode.

@Override
protected void assertAvgScoreMode(Query parentFilter, IndexSearcher searcher) throws IOException {
    MultiValueMode sortMode = MultiValueMode.AVG;
    Query childFilter = Queries.not(parentFilter);
    XFieldComparatorSource nestedComparatorSource = createFieldComparator("field2", sortMode, -127, createNested(searcher, parentFilter, childFilter));
    Query query = new ToParentBlockJoinQuery(new ConstantScoreQuery(childFilter), new QueryBitSetProducer(parentFilter), ScoreMode.None);
    Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
    TopDocs topDocs = searcher.search(query, 5, sort);
    assertThat(topDocs.totalHits, equalTo(7));
    assertThat(topDocs.scoreDocs.length, equalTo(5));
    assertThat(topDocs.scoreDocs[0].doc, equalTo(11));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[1].doc, equalTo(7));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[1]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[2].doc, equalTo(3));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[2]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[3].doc, equalTo(15));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[3]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[4].doc, equalTo(19));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[4]).fields[0]).intValue(), equalTo(3));
}
Also used : TopDocs(org.apache.lucene.search.TopDocs) Query(org.apache.lucene.search.Query) ToParentBlockJoinQuery(org.apache.lucene.search.join.ToParentBlockJoinQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) ToParentBlockJoinQuery(org.apache.lucene.search.join.ToParentBlockJoinQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) QueryBitSetProducer(org.apache.lucene.search.join.QueryBitSetProducer) Sort(org.apache.lucene.search.Sort) SortField(org.apache.lucene.search.SortField) XFieldComparatorSource(org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource) MultiValueMode(org.elasticsearch.search.MultiValueMode)

Aggregations

MultiValueMode (org.elasticsearch.search.MultiValueMode)11 SortField (org.apache.lucene.search.SortField)9 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)5 Query (org.apache.lucene.search.Query)5 Sort (org.apache.lucene.search.Sort)5 QueryBitSetProducer (org.apache.lucene.search.join.QueryBitSetProducer)5 ToParentBlockJoinQuery (org.apache.lucene.search.join.ToParentBlockJoinQuery)5 TopDocs (org.apache.lucene.search.TopDocs)4 IndexFieldData (org.elasticsearch.index.fielddata.IndexFieldData)4 XFieldComparatorSource (org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource)4 ArrayList (java.util.ArrayList)3 Document (org.apache.lucene.document.Document)3 StringField (org.apache.lucene.document.StringField)3 DirectoryReader (org.apache.lucene.index.DirectoryReader)3 IndexSearcher (org.apache.lucene.search.IndexSearcher)3 TermQuery (org.apache.lucene.search.TermQuery)3 ElasticsearchDirectoryReader (org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader)3 Nested (org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested)3 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)3 ShardId (org.elasticsearch.index.shard.ShardId)3