use of org.sonar.server.es.SearchResult in project sonarqube by SonarSource.
the class UserIndex method search.
public SearchResult<UserDoc> search(@Nullable String searchText, SearchOptions options) {
SearchRequestBuilder request = esClient.prepareSearch(UserIndexDefinition.INDEX_TYPE_USER).setSize(options.getLimit()).setFrom(options.getOffset()).addSort(FIELD_NAME, SortOrder.ASC);
BoolQueryBuilder filter = boolQuery().must(termQuery(FIELD_ACTIVE, true));
QueryBuilder query;
if (StringUtils.isEmpty(searchText)) {
query = matchAllQuery();
} else {
query = QueryBuilders.multiMatchQuery(searchText, FIELD_LOGIN, USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_LOGIN), FIELD_NAME, USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_NAME), FIELD_EMAIL, USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_EMAIL)).operator(MatchQueryBuilder.Operator.AND);
}
request.setQuery(boolQuery().must(query).filter(filter));
return new SearchResult<>(request.get(), DOC_CONVERTER);
}
use of org.sonar.server.es.SearchResult in project sonarqube by SonarSource.
the class UserIndex method search.
public SearchResult<UserDoc> search(UserQuery userQuery, SearchOptions options) {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(options.getLimit()).from(options.getOffset()).sort(FIELD_NAME, SortOrder.ASC);
BoolQueryBuilder filter = boolQuery().must(termQuery(FIELD_ACTIVE, true));
QueryBuilder esQuery = matchAllQuery();
Optional<String> textQuery = userQuery.getTextQuery();
if (textQuery.isPresent()) {
esQuery = QueryBuilders.multiMatchQuery(textQuery.get(), FIELD_LOGIN, USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_LOGIN), FIELD_NAME, USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_NAME), FIELD_EMAIL, USER_SEARCH_GRAMS_ANALYZER.subField(FIELD_EMAIL)).operator(Operator.AND);
}
SearchRequest request = EsClient.prepareSearch(UserIndexDefinition.TYPE_USER).source(searchSourceBuilder.query(boolQuery().must(esQuery).filter(filter)));
return new SearchResult<>(esClient.search(request), UserDoc::new, system2.getDefaultTimeZone().toZoneId());
}
Aggregations