use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder in project sonarqube by SonarSource.
the class ComponentIndex method search.
public SearchIdResult<String> search(ComponentQuery query, SearchOptions searchOptions) {
SearchSourceBuilder source = new SearchSourceBuilder().fetchSource(false).trackTotalHits(true).from(searchOptions.getOffset()).size(searchOptions.getLimit());
BoolQueryBuilder esQuery = boolQuery();
esQuery.filter(authorizationTypeSupport.createQueryFilter());
setNullable(query.getQuery(), q -> {
ComponentTextSearchQuery componentTextSearchQuery = ComponentTextSearchQuery.builder().setQueryText(q).setFieldKey(FIELD_KEY).setFieldName(FIELD_NAME).build();
esQuery.must(ComponentTextSearchQueryFactory.createQuery(componentTextSearchQuery, ComponentTextSearchFeatureRepertoire.values()));
});
setEmptiable(query.getQualifiers(), q -> esQuery.must(termsQuery(FIELD_QUALIFIER, q)));
source.sort(SORTABLE_ANALYZER.subField(FIELD_NAME), SortOrder.ASC);
source.query(esQuery);
SearchRequest request = EsClient.prepareSearch(TYPE_COMPONENT.getMainType()).source(source);
return new SearchIdResult<>(client.search(request), id -> id, system2.getDefaultTimeZone().toZoneId());
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder in project sonarqube by SonarSource.
the class ProjectMeasuresIndexerTest method assertThatProjectHasTag.
private void assertThatProjectHasTag(ComponentDto project, String expectedTag) {
SearchRequest request = prepareSearch(TYPE_PROJECT_MEASURES.getMainType()).source(new SearchSourceBuilder().query(boolQuery().filter(termQuery(FIELD_INDEX_TYPE, TYPE_PROJECT_MEASURES.getName())).filter(termQuery(FIELD_TAGS, expectedTag))));
assertThat(es.client().search(request).getHits().getHits()).extracting(SearchHit::getId).contains(project.uuid());
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder in project sonarqube by SonarSource.
the class ProjectMeasuresIndexerTest method assertThatQualifierIs.
private void assertThatQualifierIs(String qualifier, String... componentsUuid) {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(boolQuery().filter(termQuery(FIELD_INDEX_TYPE, TYPE_PROJECT_MEASURES.getName())).filter(termQuery(FIELD_QUALIFIER, qualifier)).filter(termsQuery(FIELD_UUID, componentsUuid)));
SearchRequest request = prepareSearch(TYPE_PROJECT_MEASURES.getMainType()).source(searchSourceBuilder);
assertThat(es.client().search(request).getHits().getHits()).extracting(SearchHit::getId).containsExactlyInAnyOrder(componentsUuid);
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder in project sonarqube by SonarSource.
the class IssueIndex method addAssigneesFacetIfNeeded.
private static void addAssigneesFacetIfNeeded(SearchOptions options, IssueQuery query, TopAggregationHelper aggregationHelper, SearchSourceBuilder esRequest) {
if (!options.getFacets().contains(PARAM_ASSIGNEES)) {
return;
}
Consumer<FilterAggregationBuilder> assigneeAggregations = t -> {
// optional second aggregation to return the issue count for selected assignees (if any)
Object[] assignees = query.assignees().toArray();
aggregationHelper.getSubAggregationHelper().buildSelectedItemsAggregation(ASSIGNEES.getName(), ASSIGNEES.getTopAggregationDef(), assignees).ifPresent(t::subAggregation);
// third aggregation to always return the count of unassigned in the assignee facet
t.subAggregation(addEffortAggregationIfNeeded(query, AggregationBuilders.missing(ASSIGNEES.getName() + FACET_SUFFIX_MISSING).field(ASSIGNEES.getFieldName())));
};
AggregationBuilder aggregation = aggregationHelper.buildTermTopAggregation(ASSIGNEES.getName(), ASSIGNEES.getTopAggregationDef(), ASSIGNEES.getNumberOfTerms(), NO_EXTRA_FILTER, assigneeAggregations);
esRequest.aggregation(aggregation);
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder in project sonarqube by SonarSource.
the class ProjectMeasuresIndex method searchTags.
public List<String> searchTags(@Nullable String textQuery, int page, int size) {
int maxPageSize = 100;
int maxPage = 20;
checkArgument(size <= maxPageSize, "Page size must be lower than or equals to " + maxPageSize);
checkArgument(page > 0 && page <= maxPage, "Page must be between 0 and " + maxPage);
if (size <= 0) {
return emptyList();
}
TermsAggregationBuilder tagFacet = AggregationBuilders.terms(FIELD_TAGS).field(FIELD_TAGS).size(size * page).minDocCount(1).order(BucketOrder.key(true));
if (textQuery != null) {
tagFacet.includeExclude(new IncludeExclude(".*" + escapeSpecialRegexChars(textQuery) + ".*", null));
}
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(authorizationTypeSupport.createQueryFilter()).fetchSource(false).aggregation(tagFacet);
SearchResponse response = client.search(EsClient.prepareSearch(TYPE_PROJECT_MEASURES.getMainType()).source(searchSourceBuilder));
Terms aggregation = response.getAggregations().get(FIELD_TAGS);
return aggregation.getBuckets().stream().skip((page - 1) * size).map(Bucket::getKeyAsString).collect(MoreCollectors.toList());
}
Aggregations