Search in sources :

Example 1 with NativeSearchQuery

use of org.springframework.data.elasticsearch.core.query.NativeSearchQuery in project xm-ms-entity by xm-online.

the class XmEntityPermittedSearchRepository method searchByQueryAndTypeKey.

/**
 * Search for XmEntity by type key and query.
 * @param query the query
 * @param typeKey the type key
 * @param pageable the page info
 * @param privilegeKey the privilege key
 * @return permitted entities
 */
public Page<XmEntity> searchByQueryAndTypeKey(String query, String typeKey, Pageable pageable, String privilegeKey) {
    String permittedQuery = buildPermittedQuery(query, privilegeKey);
    // TODO disable elastic analized to field "typeKey" and fix this
    val prefix = (typeKey + ".").toLowerCase();
    val typeKeyQuery = boolQuery().should(matchQuery(TYPE_KEY, typeKey)).should(prefixQuery(TYPE_KEY, prefix)).minimumNumberShouldMatch(1);
    val esQuery = isEmpty(permittedQuery) ? boolQuery().must(typeKeyQuery) : typeKeyQuery.must(simpleQueryStringQuery(permittedQuery));
    log.debug("Executing DSL '{}'", esQuery);
    NativeSearchQuery queryBuilder = new NativeSearchQueryBuilder().withQuery(esQuery).withPageable(pageable).build();
    return getElasticsearchTemplate().queryForPage(queryBuilder, XmEntity.class);
}
Also used : lombok.val(lombok.val) NativeSearchQueryBuilder(org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder) NativeSearchQuery(org.springframework.data.elasticsearch.core.query.NativeSearchQuery)

Aggregations

lombok.val (lombok.val)1 NativeSearchQuery (org.springframework.data.elasticsearch.core.query.NativeSearchQuery)1 NativeSearchQueryBuilder (org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder)1