use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project fess by codelibs.
the class BsWebConfigToLabelCQ method bool.
public void bool(BoolCall<WebConfigToLabelCQ> boolLambda, ConditionOptionCall<BoolQueryBuilder> opLambda) {
WebConfigToLabelCQ mustQuery = new WebConfigToLabelCQ();
WebConfigToLabelCQ shouldQuery = new WebConfigToLabelCQ();
WebConfigToLabelCQ mustNotQuery = new WebConfigToLabelCQ();
WebConfigToLabelCQ filterQuery = new WebConfigToLabelCQ();
boolLambda.callback(mustQuery, shouldQuery, mustNotQuery, filterQuery);
if (mustQuery.hasQueries() || shouldQuery.hasQueries() || mustNotQuery.hasQueries() || filterQuery.hasQueries()) {
BoolQueryBuilder builder = regBoolCQ(mustQuery.getQueryBuilderList(), shouldQuery.getQueryBuilderList(), mustNotQuery.getQueryBuilderList(), filterQuery.getQueryBuilderList());
if (opLambda != null) {
opLambda.callback(builder);
}
}
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project fess by codelibs.
the class BsWebConfigToRoleCQ method bool.
public void bool(BoolCall<WebConfigToRoleCQ> boolLambda, ConditionOptionCall<BoolQueryBuilder> opLambda) {
WebConfigToRoleCQ mustQuery = new WebConfigToRoleCQ();
WebConfigToRoleCQ shouldQuery = new WebConfigToRoleCQ();
WebConfigToRoleCQ mustNotQuery = new WebConfigToRoleCQ();
WebConfigToRoleCQ filterQuery = new WebConfigToRoleCQ();
boolLambda.callback(mustQuery, shouldQuery, mustNotQuery, filterQuery);
if (mustQuery.hasQueries() || shouldQuery.hasQueries() || mustNotQuery.hasQueries() || filterQuery.hasQueries()) {
BoolQueryBuilder builder = regBoolCQ(mustQuery.getQueryBuilderList(), shouldQuery.getQueryBuilderList(), mustNotQuery.getQueryBuilderList(), filterQuery.getQueryBuilderList());
if (opLambda != null) {
opLambda.callback(builder);
}
}
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project fess by codelibs.
the class BsSearchFieldLogCQ method bool.
public void bool(BoolCall<SearchFieldLogCQ> boolLambda, ConditionOptionCall<BoolQueryBuilder> opLambda) {
SearchFieldLogCQ mustQuery = new SearchFieldLogCQ();
SearchFieldLogCQ shouldQuery = new SearchFieldLogCQ();
SearchFieldLogCQ mustNotQuery = new SearchFieldLogCQ();
SearchFieldLogCQ filterQuery = new SearchFieldLogCQ();
boolLambda.callback(mustQuery, shouldQuery, mustNotQuery, filterQuery);
if (mustQuery.hasQueries() || shouldQuery.hasQueries() || mustNotQuery.hasQueries() || filterQuery.hasQueries()) {
BoolQueryBuilder builder = regBoolCQ(mustQuery.getQueryBuilderList(), shouldQuery.getQueryBuilderList(), mustNotQuery.getQueryBuilderList(), filterQuery.getQueryBuilderList());
if (opLambda != null) {
opLambda.callback(builder);
}
}
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project fess by codelibs.
the class QueryHelper method buildRoleQuery.
protected void buildRoleQuery(final QueryContext queryContext, final SearchRequestType searchRequestType) {
if (roleQueryHelper != null && queryContext.roleQueryEnabled()) {
final Set<String> roleSet = roleQueryHelper.build(searchRequestType);
if (!roleSet.isEmpty()) {
queryContext.addQuery(boolQuery -> {
final BoolQueryBuilder roleQuery = QueryBuilders.boolQuery();
roleSet.stream().forEach(name -> {
roleQuery.should(QueryBuilders.termQuery(fessConfig.getIndexFieldRole(), name));
});
boolQuery.filter(roleQuery);
});
}
}
}
use of org.graylog.shaded.elasticsearch6.org.elasticsearch.index.query.BoolQueryBuilder in project chili-core by codingchili.
the class ElasticMap method query.
@Override
public QueryBuilder<Value> query(String field) {
return new AbstractQueryBuilder<Value>(this, field) {
List<BoolQueryBuilder> statements = new ArrayList<>();
BoolQueryBuilder builder = new BoolQueryBuilder();
@Override
public QueryBuilder<Value> and(String attribute) {
setAttribute(attribute);
return this;
}
@Override
public QueryBuilder<Value> or(String attribute) {
setAttribute(attribute);
statements.add(builder);
builder = new BoolQueryBuilder();
return this;
}
@Override
public QueryBuilder<Value> between(Long minimum, Long maximum) {
builder.must(QueryBuilders.rangeQuery(attribute()).gte(minimum).lte(maximum));
return this;
}
@Override
public QueryBuilder<Value> like(String text) {
text = Validator.toPlainText(text).toLowerCase();
builder.must(QueryBuilders.wildcardQuery(attribute(), "*" + text + "*"));
return this;
}
@Override
public QueryBuilder<Value> startsWith(String text) {
builder.must(QueryBuilders.matchPhrasePrefixQuery(attribute(), text));
return this;
}
@Override
public QueryBuilder<Value> in(Comparable... list) {
BoolQueryBuilder bool = new BoolQueryBuilder().minimumShouldMatch(1);
for (Comparable item : list) {
bool.should(QueryBuilders.matchPhraseQuery(attribute(), item));
}
builder.must(bool);
return this;
}
@Override
public QueryBuilder<Value> equalTo(Comparable match) {
builder.must(QueryBuilders.matchPhraseQuery(attribute(), match));
return this;
}
@Override
public QueryBuilder<Value> matches(String regex) {
if (regex.contains("^") || regex.contains("$")) {
// remove unsupported characters in ElasticSearch query.
regex = regex.replaceAll("[\\^$]", "");
}
builder.must(QueryBuilders.regexpQuery(attribute(), regex.toLowerCase()).flags(RegexpFlag.ALL));
return this;
}
@Override
public void execute(Handler<AsyncResult<Collection<Value>>> handler) {
if (!builder.equals(new BoolQueryBuilder())) {
statements.add(builder);
}
BoolQueryBuilder query = new BoolQueryBuilder().minimumShouldMatch(1);
for (BoolQueryBuilder statement : statements) {
query.should(statement);
}
getRequestWithOptions().setQuery(query).execute(new ElasticHandler<>(response -> {
handler.handle(result(listFrom(response.getHits().getHits())));
}, exception -> handler.handle(error(exception))));
}
private SearchRequestBuilder getRequestWithOptions() {
SearchRequestBuilder request = client.prepareSearch(context.database()).setTypes(context.collection());
if (isOrdered) {
switch(sortOrder) {
case ASCENDING:
request.addSort(getOrderByAttribute(), SortOrder.ASC);
break;
case DESCENDING:
request.addSort(getOrderByAttribute(), SortOrder.DESC);
}
}
request.setSize(pageSize);
request.setFrom(pageSize * page);
return request;
}
};
}
Aggregations