Search in sources :

Example 1 with DisMaxQueryBuilder

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;
}
Also used : DisMaxQueryBuilder(org.elasticsearch.index.query.DisMaxQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) IdsQueryBuilder(org.elasticsearch.index.query.IdsQueryBuilder) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) DisMaxQueryBuilder(org.elasticsearch.index.query.DisMaxQueryBuilder) CommonTermsQueryBuilder(org.elasticsearch.index.query.CommonTermsQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) FuzzyQueryBuilder(org.elasticsearch.index.query.FuzzyQueryBuilder)

Example 2 with DisMaxQueryBuilder

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);
}
Also used : DisMaxQueryBuilder(org.elasticsearch.index.query.DisMaxQueryBuilder) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) DynRealm(org.apache.syncope.core.persistence.api.entity.DynRealm) HashSet(java.util.HashSet) DynRealm(org.apache.syncope.core.persistence.api.entity.DynRealm)

Example 3 with DisMaxQueryBuilder

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;
}
Also used : DisMaxQueryBuilder(org.elasticsearch.index.query.DisMaxQueryBuilder) Realm(org.apache.syncope.core.persistence.api.entity.Realm) DynRealm(org.apache.syncope.core.persistence.api.entity.DynRealm)

Aggregations

DisMaxQueryBuilder (org.elasticsearch.index.query.DisMaxQueryBuilder)3 DynRealm (org.apache.syncope.core.persistence.api.entity.DynRealm)2 Realm (org.apache.syncope.core.persistence.api.entity.Realm)2 HashSet (java.util.HashSet)1 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)1 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1 CommonTermsQueryBuilder (org.elasticsearch.index.query.CommonTermsQueryBuilder)1 FuzzyQueryBuilder (org.elasticsearch.index.query.FuzzyQueryBuilder)1 IdsQueryBuilder (org.elasticsearch.index.query.IdsQueryBuilder)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)1