Search in sources :

Example 6 with SortBuilder

use of org.elasticsearch.search.sort.SortBuilder in project sonarqube by SonarSource.

the class SortingTest method ascending_sort_on_single_field_with_missing_in_last_position.

@Test
public void ascending_sort_on_single_field_with_missing_in_last_position() throws Exception {
    Sorting sorting = new Sorting();
    sorting.add("updatedAt").missingLast();
    SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class), SearchAction.INSTANCE);
    sorting.fill(request, "updatedAt", true);
    List<SortBuilder> fields = fields(request);
    assertThat(fields).hasSize(1);
    expectField(fields.get(0), "updatedAt", "_last", SortOrder.ASC);
}
Also used : SortBuilder(org.elasticsearch.search.sort.SortBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) Client(org.elasticsearch.client.Client) Test(org.junit.Test)

Example 7 with SortBuilder

use of org.elasticsearch.search.sort.SortBuilder in project sonarqube by SonarSource.

the class SortingTest method default_sorting.

@Test
public void default_sorting() throws Exception {
    Sorting sorting = new Sorting();
    sorting.addDefault("file");
    SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class), SearchAction.INSTANCE);
    sorting.fillDefault(request);
    List<SortBuilder> fields = fields(request);
    assertThat(fields).hasSize(1);
}
Also used : SortBuilder(org.elasticsearch.search.sort.SortBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) Client(org.elasticsearch.client.Client) Test(org.junit.Test)

Example 8 with SortBuilder

use of org.elasticsearch.search.sort.SortBuilder in project sonarqube by SonarSource.

the class SortingTest method ascending_sort_on_single_field.

@Test
public void ascending_sort_on_single_field() throws Exception {
    Sorting sorting = new Sorting();
    sorting.add("updatedAt");
    SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class), SearchAction.INSTANCE);
    sorting.fill(request, "updatedAt", true);
    List<SortBuilder> fields = fields(request);
    assertThat(fields).hasSize(1);
    expectField(fields.get(0), "updatedAt", "_first", SortOrder.ASC);
}
Also used : SortBuilder(org.elasticsearch.search.sort.SortBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) Client(org.elasticsearch.client.Client) Test(org.junit.Test)

Example 9 with SortBuilder

use of org.elasticsearch.search.sort.SortBuilder in project sonarqube by SonarSource.

the class SortingTest method sort_on_multiple_fields.

@Test
public void sort_on_multiple_fields() throws Exception {
    // asc => file asc, line asc, severity desc, key asc
    Sorting sorting = new Sorting();
    sorting.add("fileLine", "file");
    sorting.add("fileLine", "line");
    sorting.add("fileLine", "severity").reverse();
    sorting.add("fileLine", "key").missingLast();
    SearchRequestBuilder request = new SearchRequestBuilder(mock(Client.class), SearchAction.INSTANCE);
    sorting.fill(request, "fileLine", true);
    List<SortBuilder> fields = fields(request);
    assertThat(fields).hasSize(4);
    expectField(fields.get(0), "file", "_first", SortOrder.ASC);
    expectField(fields.get(1), "line", "_first", SortOrder.ASC);
    expectField(fields.get(2), "severity", "_first", SortOrder.DESC);
    expectField(fields.get(3), "key", "_last", SortOrder.ASC);
}
Also used : SortBuilder(org.elasticsearch.search.sort.SortBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) Client(org.elasticsearch.client.Client) Test(org.junit.Test)

Aggregations

SortBuilder (org.elasticsearch.search.sort.SortBuilder)9 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)6 Client (org.elasticsearch.client.Client)6 Test (org.junit.Test)6 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 ArrayList (java.util.ArrayList)1 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)1 SearchType (org.elasticsearch.action.search.SearchType)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 SearchHit (org.elasticsearch.search.SearchHit)1 SearchHits (org.elasticsearch.search.SearchHits)1 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)1 FetchSourceContext (org.elasticsearch.search.fetch.subphase.FetchSourceContext)1 HighlightBuilderTests (org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilderTests)1