Search in sources :

Example 11 with SearchIdResult

use of org.sonar.server.es.SearchIdResult in project sonarqube by SonarSource.

the class RuleIndexTest method search_by_any_of_severities.

@Test
public void search_by_any_of_severities() {
    indexRules(newDoc(RuleKey.of("java", "S001")).setSeverity(BLOCKER), newDoc(RuleKey.of("java", "S002")).setSeverity(INFO));
    RuleQuery query = new RuleQuery().setSeverities(asList(INFO, MINOR));
    SearchIdResult results = index.search(query, new SearchOptions());
    assertThat(results.getIds()).containsOnly(RuleKey.of("java", "S002"));
    // no results
    query = new RuleQuery().setSeverities(singletonList(MINOR));
    assertThat(index.search(query, new SearchOptions()).getIds()).isEmpty();
    // empty list => no filter
    query = new RuleQuery().setSeverities(Collections.emptyList());
    assertThat(index.search(query, new SearchOptions()).getIds()).hasSize(2);
    // null list => no filter
    query = new RuleQuery().setSeverities();
    assertThat(index.search(query, new SearchOptions()).getIds()).hasSize(2);
}
Also used : SearchOptions(org.sonar.server.es.SearchOptions) SearchIdResult(org.sonar.server.es.SearchIdResult) Test(org.junit.Test)

Aggregations

SearchIdResult (org.sonar.server.es.SearchIdResult)11 Test (org.junit.Test)9 SearchOptions (org.sonar.server.es.SearchOptions)9 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)2 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)2 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)2 HasParentQueryBuilder (org.elasticsearch.index.query.HasParentQueryBuilder)1 MatchQueryBuilder (org.elasticsearch.index.query.MatchQueryBuilder)1 SearchHit (org.elasticsearch.search.SearchHit)1 AbstractAggregationBuilder (org.elasticsearch.search.aggregations.AbstractAggregationBuilder)1