use of org.elasticsearch.index.query.DisMaxQueryBuilder in project elasticsearch by elastic.
the class RandomQueryGenerator method randomDisMaxQuery.
private static QueryBuilder randomDisMaxQuery(List<String> stringFields, List<String> numericFields, int numDocs, int depth) {
QueryBuilder q = QueryBuilders.disMaxQuery();
int numClauses = randomIntBetween(1, 10);
for (int i = 0; i < numClauses; i++) {
((DisMaxQueryBuilder) q).add(randomQueryBuilder(stringFields, numericFields, numDocs, depth - 1));
}
if (randomBoolean()) {
((DisMaxQueryBuilder) q).boost(randomFloat());
}
if (randomBoolean()) {
((DisMaxQueryBuilder) q).tieBreaker(randomFloat());
}
return q;
}
use of org.elasticsearch.index.query.DisMaxQueryBuilder in project syncope by apache.
the class ElasticsearchAnySearchDAO method adminRealmsFilter.
private Pair<DisMaxQueryBuilder, Set<String>> adminRealmsFilter(final Set<String> adminRealms) {
DisMaxQueryBuilder builder = QueryBuilders.disMaxQuery();
Set<String> dynRealmKeys = new HashSet<>();
RealmUtils.normalize(adminRealms).forEach(realmPath -> {
if (realmPath.startsWith("/")) {
Realm realm = realmDAO.findByFullPath(realmPath);
if (realm == null) {
SyncopeClientException noRealm = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
noRealm.getElements().add("Invalid realm specified: " + realmPath);
throw noRealm;
} else {
realmDAO.findDescendants(realm).forEach(descendant -> {
builder.add(QueryBuilders.termQuery("realm", descendant.getFullPath()));
});
}
} else {
DynRealm dynRealm = dynRealmDAO.find(realmPath);
if (dynRealm == null) {
LOG.warn("Ignoring invalid dynamic realm {}", realmPath);
} else {
dynRealmKeys.add(dynRealm.getKey());
builder.add(QueryBuilders.termQuery("dynRealm", dynRealm.getKey()));
}
}
});
if (!dynRealmKeys.isEmpty()) {
realmDAO.findAll().forEach(descendant -> {
builder.add(QueryBuilders.termQuery("realm", descendant.getFullPath()));
});
}
return Pair.of(builder, dynRealmKeys);
}
use of org.elasticsearch.index.query.DisMaxQueryBuilder in project syncope by apache.
the class ElasticsearchAnySearchDAO method getQueryBuilder.
private QueryBuilder getQueryBuilder(final AssignableCond cond) {
Realm realm;
try {
realm = check(cond);
} catch (IllegalArgumentException e) {
return EMPTY_QUERY_BUILDER;
}
DisMaxQueryBuilder builder = QueryBuilders.disMaxQuery();
if (cond.isFromGroup()) {
realmDAO.findDescendants(realm).forEach(current -> {
builder.add(QueryBuilders.termQuery("realm", current.getFullPath()));
});
} else {
for (Realm current = realm; current.getParent() != null; current = current.getParent()) {
builder.add(QueryBuilders.termQuery("realm", current.getFullPath()));
}
builder.add(QueryBuilders.termQuery("realm", realmDAO.getRoot().getFullPath()));
}
return builder;
}
Aggregations