use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project vertigo by KleeGroup.
the class ESSearchRequestBuilder method appendSearchQuery.
private static void appendSearchQuery(final SearchQuery searchQuery, final SearchRequestBuilder searchRequestBuilder, final boolean useHighlight) {
final BoolQueryBuilder filterBoolQueryBuilder = QueryBuilders.boolQuery();
final BoolQueryBuilder postFilterBoolQueryBuilder = QueryBuilders.boolQuery();
// on ajoute les critères de la recherche AVEC impact sur le score
final QueryBuilder queryBuilder = appendSearchQuery(searchQuery, filterBoolQueryBuilder);
// on ajoute les filtres de sécurité SANS impact sur le score
appendSecurityFilter(searchQuery.getSecurityListFilter(), filterBoolQueryBuilder);
// on ajoute les filtres des facettes SANS impact sur le score
appendSelectedFacetValues(searchQuery.getFacetedQuery(), filterBoolQueryBuilder, postFilterBoolQueryBuilder);
final QueryBuilder requestQueryBuilder;
if (searchQuery.isBoostMostRecent()) {
requestQueryBuilder = appendBoostMostRecent(searchQuery, queryBuilder);
} else {
requestQueryBuilder = filterBoolQueryBuilder;
}
searchRequestBuilder.setQuery(requestQueryBuilder).setPostFilter(postFilterBoolQueryBuilder);
if (useHighlight) {
// .setHighlighterFilter(true) //We don't highlight the security filter
// .addHighlightedField("*"); HOW TO ?
searchRequestBuilder.highlighter(new HighlightBuilder().numOfFragments(3));
}
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project vertigo by KleeGroup.
the class ESSearchRequestBuilder method appendSecurityFilter.
private static void appendSecurityFilter(final Optional<ListFilter> securityListFilter, final BoolQueryBuilder filterBoolQueryBuilder) {
if (securityListFilter.isPresent()) {
final QueryBuilder securityFilterBuilder = translateToQueryBuilder(securityListFilter.get());
filterBoolQueryBuilder.filter(securityFilterBuilder);
// use filteredQuery instead of PostFilter in order to filter aggregations too.
}
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project main by JohnPeng739.
the class ElasticAccessorRest method search.
private <T extends Base> SearchResponse search(List<GeneralAccessor.ConditionTuple> tuples, Class<T> clazz, Pagination pagination) throws UserInterfaceDalErrorException {
SearchSourceBuilder builder = new SearchSourceBuilder();
if (tuples == null || tuples.isEmpty()) {
builder.query(QueryBuilders.matchAllQuery());
} else {
BoolQueryBuilder query = QueryBuilders.boolQuery();
tuples.forEach(tuple -> query.must(QueryBuilders.termQuery(tuple.field, tuple.value)));
builder.query(query);
}
if (pagination != null) {
builder.from((pagination.getPage() - 1) * pagination.getSize());
builder.size(pagination.getSize());
}
SearchRequest request = new SearchRequest(index);
request.types(clazz.getName());
request.source(builder);
try {
SearchResponse response = client.search(request);
return response;
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("Search fail from elastic.", ex);
}
throw new UserInterfaceDalErrorException(UserInterfaceDalErrorException.DalErrors.DB_OPERATE_FAIL);
}
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project api-core by ca-cwds.
the class ElasticsearchDaoTest method buildBoolQueryFromMoreThanNineDigitSsnBuildsQueryWithNoClauses.
@Test
public void buildBoolQueryFromMoreThanNineDigitSsnBuildsQueryWithNoClauses() {
BoolQueryBuilder actualQuery = target.buildBoolQueryFromSearchTerms("111223333111 ");
assertThat(actualQuery.hasClauses(), is(equalTo(false)));
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project api-core by ca-cwds.
the class ElasticsearchDaoTest method buildBoolQueryFromTwoSsnBuildsQueryWithTwoSsnClauses.
@Test
public void buildBoolQueryFromTwoSsnBuildsQueryWithTwoSsnClauses() {
BoolQueryBuilder actualQuery = target.buildBoolQueryFromSearchTerms("123456789 111223333 ");
QueryBuilder expectedQuery = QueryBuilders.boolQuery().should(QueryBuilders.prefixQuery(ESColumn.SSN.getCol(), "123456789")).should(QueryBuilders.prefixQuery(ESColumn.SSN.getCol(), "111223333"));
assertThat(actualQuery.toString(), is(equalTo(expectedQuery.toString())));
}
Aggregations