Search in sources :

Example 11 with MultiValueMode

use of org.opensearch.search.MultiValueMode in project OpenSearch by opensearch-project.

the class FloatNestedSortingTests method assertAvgScoreMode.

protected void assertAvgScoreMode(Query parentFilter, IndexSearcher searcher, IndexFieldData.XFieldComparatorSource innerFieldComparator) 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.value, equalTo(7L));
    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.opensearch.index.fielddata.IndexFieldData.XFieldComparatorSource) MultiValueMode(org.opensearch.search.MultiValueMode)

Aggregations

MultiValueMode (org.opensearch.search.MultiValueMode)11 SortField (org.apache.lucene.search.SortField)7 Sort (org.apache.lucene.search.Sort)6 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)5 Query (org.apache.lucene.search.Query)5 QueryBitSetProducer (org.apache.lucene.search.join.QueryBitSetProducer)5 ToParentBlockJoinQuery (org.apache.lucene.search.join.ToParentBlockJoinQuery)5 TopDocs (org.apache.lucene.search.TopDocs)4 XFieldComparatorSource (org.opensearch.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 OpenSearchDirectoryReader (org.opensearch.common.lucene.index.OpenSearchDirectoryReader)3 Nested (org.opensearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested)3 ShardId (org.opensearch.index.shard.ShardId)3 Term (org.apache.lucene.index.Term)2 TopFieldDocs (org.apache.lucene.search.TopFieldDocs)2