use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder in project sonarqube by SonarSource.
the class RuleIndexDefinitionTest method support_long_html_description.
@Test
public void support_long_html_description() {
String longText = StringUtils.repeat("The quick brown fox jumps over the lazy dog ", 700);
List<AnalyzeResponse.AnalyzeToken> tokens = analyzeIndexedTokens(longText);
assertThat(tokens).extracting(AnalyzeResponse.AnalyzeToken::getTerm).containsOnly("quick", "brown", "fox", "jump", "over", "lazi", "dog");
// the following method fails if PUT fails
tester.putDocuments(TYPE_RULE, new RuleDoc(ImmutableMap.of(FIELD_RULE_UUID, "123", FIELD_RULE_HTML_DESCRIPTION, longText, FIELD_RULE_REPOSITORY, "squid", FIELD_RULE_KEY, "squid:S001")));
assertThat(tester.countDocuments(TYPE_RULE)).isOne();
assertThat(tester.client().search(EsClient.prepareSearch(TYPE_RULE).source(new SearchSourceBuilder().query(matchQuery(ENGLISH_HTML_ANALYZER.subField(FIELD_RULE_HTML_DESCRIPTION), "brown fox jumps lazy")))).getHits().getTotalHits()).isEqualTo(new TotalHits(1, TotalHits.Relation.EQUAL_TO));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder in project sonarqube by SonarSource.
the class IssueIndex method getMinCreatedAt.
private OptionalLong getMinCreatedAt(AllFilters filters) {
String facetNameAndField = CREATED_AT.getFieldName();
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder().size(0);
BoolQueryBuilder esFilter = boolQuery();
filters.stream().filter(Objects::nonNull).forEach(esFilter::must);
if (esFilter.hasClauses()) {
sourceBuilder.query(QueryBuilders.boolQuery().filter(esFilter));
}
sourceBuilder.aggregation(AggregationBuilders.min(facetNameAndField).field(facetNameAndField));
SearchRequest request = EsClient.prepareSearch(TYPE_ISSUE.getMainType()).source(sourceBuilder);
Min minValue = client.search(request).getAggregations().get(facetNameAndField);
double actualValue = minValue.getValue();
if (Double.isInfinite(actualValue)) {
return OptionalLong.empty();
}
return OptionalLong.of((long) actualValue);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder in project sonarqube by SonarSource.
the class IssueIndex method getSonarSourceReport.
public List<SecurityStandardCategoryStatistics> getSonarSourceReport(String projectUuid, boolean isViewOrApp, boolean includeCwe) {
SearchSourceBuilder request = prepareNonClosedVulnerabilitiesAndHotspotSearch(projectUuid, isViewOrApp);
Arrays.stream(SQCategory.values()).forEach(sonarsourceCategory -> request.aggregation(newSecurityReportSubAggregations(AggregationBuilders.filter(sonarsourceCategory.getKey(), boolQuery().filter(termQuery(FIELD_ISSUE_SQ_SECURITY_CATEGORY, sonarsourceCategory.getKey()))), includeCwe, SecurityStandards.CWES_BY_SQ_CATEGORY.get(sonarsourceCategory))));
return processSecurityReportSearchResults(request, includeCwe);
}
use of org.graylog.shaded.elasticsearch7.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.elasticsearch7.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());
}
Aggregations