use of org.elasticsearch.index.query.BoolQueryBuilder in project sonarqube by SonarSource.
the class IssueIndex method selectIssuesForBatch.
/**
* Return non closed issues for a given project, module, or file. Other kind of components are not allowed.
* Only fields needed for the batch are returned.
*/
public Iterator<IssueDoc> selectIssuesForBatch(ComponentDto component) {
BoolQueryBuilder filter = boolQuery().must(createAuthorizationFilter(true)).mustNot(termsQuery(IssueIndexDefinition.FIELD_ISSUE_STATUS, Issue.STATUS_CLOSED));
switch(component.scope()) {
case Scopes.PROJECT:
filter.must(termsQuery(IssueIndexDefinition.FIELD_ISSUE_MODULE_PATH, component.uuid()));
break;
case Scopes.FILE:
filter.must(termsQuery(IssueIndexDefinition.FIELD_ISSUE_COMPONENT_UUID, component.uuid()));
break;
default:
throw new IllegalStateException(format("Component of scope '%s' is not allowed", component.scope()));
}
SearchRequestBuilder requestBuilder = getClient().prepareSearch(IssueIndexDefinition.INDEX_TYPE_ISSUE).setSearchType(SearchType.SCAN).setScroll(TimeValue.timeValueMinutes(EsUtils.SCROLL_TIME_IN_MINUTES)).setSize(10_000).setFetchSource(new String[] { IssueIndexDefinition.FIELD_ISSUE_KEY, IssueIndexDefinition.FIELD_ISSUE_RULE_KEY, IssueIndexDefinition.FIELD_ISSUE_MODULE_UUID, IssueIndexDefinition.FIELD_ISSUE_FILE_PATH, IssueIndexDefinition.FIELD_ISSUE_SEVERITY, IssueIndexDefinition.FIELD_ISSUE_MANUAL_SEVERITY, IssueIndexDefinition.FIELD_ISSUE_RESOLUTION, IssueIndexDefinition.FIELD_ISSUE_STATUS, IssueIndexDefinition.FIELD_ISSUE_ASSIGNEE, IssueIndexDefinition.FIELD_ISSUE_LINE, IssueIndexDefinition.FIELD_ISSUE_MESSAGE, IssueIndexDefinition.FIELD_ISSUE_CHECKSUM, IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT }, null).setQuery(boolQuery().must(matchAllQuery()).filter(filter));
SearchResponse response = requestBuilder.get();
return EsUtils.scroll(getClient(), response.getScrollId(), DOC_CONVERTER);
}
use of org.elasticsearch.index.query.BoolQueryBuilder in project sonarqube by SonarSource.
the class StickyFacetBuilder method buildStickyFacet.
public AggregationBuilder buildStickyFacet(String fieldName, String facetName, int size, Object... selected) {
BoolQueryBuilder facetFilter = getStickyFacetFilter(fieldName);
FilterAggregationBuilder facetTopAggregation = buildTopFacetAggregation(fieldName, facetName, facetFilter, size);
facetTopAggregation = addSelectedItemsToFacet(fieldName, facetName, facetTopAggregation, selected);
return AggregationBuilders.global(facetName).subAggregation(facetTopAggregation);
}
use of org.elasticsearch.index.query.BoolQueryBuilder in project sonarqube by SonarSource.
the class ComponentTextSearchQueryFactory method createQuery.
public static QueryBuilder createQuery(ComponentTextSearchQuery query, ComponentTextSearchFeature... features) {
checkArgument(features.length > 0, "features cannot be empty");
BoolQueryBuilder featureQuery = boolQuery();
Arrays.stream(features).map(f -> f.getQuery(query)).forEach(featureQuery::should);
return featureQuery;
}
use of org.elasticsearch.index.query.BoolQueryBuilder in project sonarqube by SonarSource.
the class IssueIndex method addAssignedToMeFacetIfNeeded.
private void addAssignedToMeFacetIfNeeded(SearchRequestBuilder builder, SearchOptions options, IssueQuery query, Map<String, QueryBuilder> filters, QueryBuilder queryBuilder) {
String login = userSession.getLogin();
if (!options.getFacets().contains(FACET_ASSIGNED_TO_ME) || StringUtils.isEmpty(login)) {
return;
}
String fieldName = IssueIndexDefinition.FIELD_ISSUE_ASSIGNEE;
String facetName = FACET_ASSIGNED_TO_ME;
// Same as in super.stickyFacetBuilder
StickyFacetBuilder assignedToMeFacetBuilder = newStickyFacetBuilder(query, filters, queryBuilder);
BoolQueryBuilder facetFilter = assignedToMeFacetBuilder.getStickyFacetFilter(IS_ASSIGNED_FILTER, fieldName);
FilterAggregationBuilder facetTopAggregation = AggregationBuilders.filter(facetName + "__filter").filter(facetFilter).subAggregation(addEffortAggregationIfNeeded(query, AggregationBuilders.terms(facetName + "__terms").field(fieldName).include(escapeSpecialRegexChars(login))));
builder.addAggregation(AggregationBuilders.global(facetName).subAggregation(facetTopAggregation));
}
use of org.elasticsearch.index.query.BoolQueryBuilder in project sonarqube by SonarSource.
the class IssueIndex method search.
public SearchResult<IssueDoc> search(IssueQuery query, SearchOptions options) {
SearchRequestBuilder requestBuilder = getClient().prepareSearch(IssueIndexDefinition.INDEX_TYPE_ISSUE);
configureSorting(query, requestBuilder);
configurePagination(options, requestBuilder);
configureRouting(query, options, requestBuilder);
QueryBuilder esQuery = matchAllQuery();
BoolQueryBuilder esFilter = boolQuery();
Map<String, QueryBuilder> filters = createFilters(query);
for (QueryBuilder filter : filters.values()) {
if (filter != null) {
esFilter.must(filter);
}
}
if (esFilter.hasClauses()) {
requestBuilder.setQuery(boolQuery().must(esQuery).filter(esFilter));
} else {
requestBuilder.setQuery(esQuery);
}
configureStickyFacets(query, options, filters, esQuery, requestBuilder);
return new SearchResult<>(requestBuilder.get(), DOC_CONVERTER);
}
Aggregations