use of org.elasticsearch.index.query.BoolQueryBuilder in project sonarqube by SonarSource.
the class RuleIndex method buildQuery.
/* Build main query (search based) */
private static QueryBuilder buildQuery(RuleQuery query) {
// No contextual query case
String queryText = query.getQueryText();
if (StringUtils.isEmpty(queryText)) {
return matchAllQuery();
}
// Build RuleBased contextual query
BoolQueryBuilder qb = boolQuery();
String queryString = query.getQueryText();
// Human readable type of querying
qb.should(simpleQueryStringQuery(query.getQueryText()).field(SEARCH_WORDS_ANALYZER.subField(FIELD_RULE_NAME), 20f).field(FIELD_RULE_HTML_DESCRIPTION, 3f).defaultOperator(SimpleQueryStringBuilder.Operator.AND)).boost(20f);
// Match and partial Match queries
// Search by key uses the "sortable" sub-field as it requires to be case-insensitive (lower-case filtering)
qb.should(matchQuery(SORTABLE_ANALYZER.subField(FIELD_RULE_KEY), queryString).operator(MatchQueryBuilder.Operator.AND).boost(30f));
qb.should(matchQuery(SORTABLE_ANALYZER.subField(FIELD_RULE_RULE_KEY), queryString).operator(MatchQueryBuilder.Operator.AND).boost(15f));
qb.should(termQuery(FIELD_RULE_LANGUAGE, queryString, 3f));
qb.should(termQuery(FIELD_RULE_ALL_TAGS, queryString, 10f));
qb.should(termAnyQuery(FIELD_RULE_ALL_TAGS, queryString, 1f));
return qb;
}
use of org.elasticsearch.index.query.BoolQueryBuilder in project sonarqube by SonarSource.
the class RuleIndex method searchAll.
/**
* Return all keys matching the search query, without pagination nor facets
*/
public Iterator<RuleKey> searchAll(RuleQuery query) {
SearchRequestBuilder esSearch = getClient().prepareSearch(INDEX_TYPE_RULE).setSearchType(SearchType.SCAN).setScroll(TimeValue.timeValueMinutes(SCROLL_TIME_IN_MINUTES));
QueryBuilder qb = buildQuery(query);
Map<String, QueryBuilder> filters = buildFilters(query);
setSorting(query, esSearch);
BoolQueryBuilder fb = boolQuery();
for (QueryBuilder filterBuilder : filters.values()) {
fb.must(filterBuilder);
}
esSearch.setQuery(boolQuery().must(qb).filter(fb));
SearchResponse response = esSearch.get();
return scrollIds(getClient(), response.getScrollId(), ToRuleKey.INSTANCE);
}
use of org.elasticsearch.index.query.BoolQueryBuilder in project sonarqube by SonarSource.
the class RuleIndex method addTermFilter.
private static BoolQueryBuilder addTermFilter(BoolQueryBuilder filter, String field, @Nullable Collection<String> values) {
if (isNotEmpty(values)) {
BoolQueryBuilder valuesFilter = boolQuery();
for (String value : values) {
QueryBuilder valueFilter = QueryBuilders.termQuery(field, value);
valuesFilter.should(valueFilter);
}
filter.must(valuesFilter);
}
return filter;
}
use of org.elasticsearch.index.query.BoolQueryBuilder in project sonarqube by SonarSource.
the class RuleIndex method addStatusFacetIfNeeded.
private static void addStatusFacetIfNeeded(SearchOptions options, Map<String, AbstractAggregationBuilder> aggregations, StickyFacetBuilder stickyFacetBuilder) {
if (options.getFacets().contains(FACET_STATUSES)) {
BoolQueryBuilder facetFilter = stickyFacetBuilder.getStickyFacetFilter(FIELD_RULE_STATUS);
AbstractAggregationBuilder statuses = AggregationBuilders.filter(FACET_STATUSES + "_filter").filter(facetFilter).subAggregation(AggregationBuilders.terms(FACET_STATUSES).field(FIELD_RULE_STATUS).include(Joiner.on('|').join(ALL_STATUSES_EXCEPT_REMOVED)).exclude(RuleStatus.REMOVED.toString()).size(ALL_STATUSES_EXCEPT_REMOVED.size()));
aggregations.put(FACET_STATUSES, AggregationBuilders.global(FACET_STATUSES).subAggregation(statuses));
}
}
use of org.elasticsearch.index.query.BoolQueryBuilder in project sonarqube by SonarSource.
the class ComponentIndex method createQuery.
private QueryBuilder createQuery(ComponentIndexQuery query, ComponentTextSearchFeature... features) {
BoolQueryBuilder esQuery = boolQuery();
esQuery.filter(authorizationTypeSupport.createQueryFilter());
ComponentTextSearchQuery componentTextSearchQuery = ComponentTextSearchQuery.builder().setQueryText(query.getQuery()).setFieldKey(FIELD_KEY).setFieldName(FIELD_NAME).build();
return esQuery.must(ComponentTextSearchQueryFactory.createQuery(componentTextSearchQuery, features));
}
Aggregations