Search in sources :

Example 16 with SearchQueryFieldNameResolver

use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.

the class TermExpressionBuilderTest method compare_eq_datetime.

@Test
public void compare_eq_datetime() throws Exception {
    final String expected = load("compare_eq_datetime.json");
    final QueryBuilder query = TermExpressionBuilder.build(CompareExpr.eq(FieldExpr.from("myField"), ValueExpr.instant("2013-11-29T09:42:00Z")), new SearchQueryFieldNameResolver());
    assertEquals(cleanString(expected), cleanString(query.toString()));
}
Also used : QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) Test(org.junit.jupiter.api.Test)

Example 17 with SearchQueryFieldNameResolver

use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.

the class IndexNodeIndexPathResolverTest method testResolve.

@ParameterizedTest
@MethodSource("testParams")
public void testResolve(final String field, final ValueExpr valueExpr, final String resolvedFieldName) {
    final String result = new SearchQueryFieldNameResolver().resolve(CompareExpr.eq(FieldExpr.from(field), valueExpr));
    assertEquals(resolvedFieldName, result);
}
Also used : SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 18 with SearchQueryFieldNameResolver

use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.

the class CopyExecutor method createQuery.

private ElasticsearchQuery createQuery() {
    final IdFilter idFilter = IdFilter.create().fieldName(NodeIndexPath.ID.getPath()).values(copyRequest.getNodeIds()).build();
    final QueryBuilder idFilterBuilder = new FilterBuilderFactory(new SearchQueryFieldNameResolver()).create(Filters.from(idFilter));
    QueryBuilder query = QueryBuilders.matchAllQuery();
    return ElasticsearchQuery.create().query(QueryBuilders.filteredQuery(query, idFilterBuilder)).addIndexName(copyRequest.getStorageSource().getStorageName().getName()).addIndexType(copyRequest.getStorageSource().getStorageType().getName()).size(copyRequest.getNodeIds().getSize()).batchSize(BATCH_SIZE).from(0).setReturnFields(ReturnFields.from(NodeIndexPath.SOURCE)).build();
}
Also used : IdFilter(com.enonic.xp.query.filter.IdFilter) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) FilterBuilderFactory(com.enonic.xp.repo.impl.elasticsearch.query.translator.factory.FilterBuilderFactory)

Example 19 with SearchQueryFieldNameResolver

use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.

the class FilterBuilderFactoryTest method createExistsFilter.

@Test
public void createExistsFilter() throws Exception {
    final ExistsFilter queryFilter = ExistsFilter.create().fieldName("myField").build();
    final String expected = load("filter_exists.json");
    final QueryBuilder filterBuilder = new FilterBuilderFactory(new SearchQueryFieldNameResolver()).create(Filters.from(queryFilter));
    assertEquals(cleanString(expected), cleanString(filterBuilder.toString()));
}
Also used : ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) Test(org.junit.jupiter.api.Test)

Example 20 with SearchQueryFieldNameResolver

use of com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver in project xp by enonic.

the class SortBuilderFactoryTest method createGeoDistance.

@Test
public void createGeoDistance() {
    final Set<OrderExpr> orderExprs = new HashSet<>();
    orderExprs.add(new DynamicOrderExpr(new FunctionExpr("geoDistance", List.of(ValueExpr.string("myField"), ValueExpr.geoPoint("-50,40"), ValueExpr.string("km"))), OrderExpr.Direction.ASC));
    final List<SortBuilder> sortBuilders = new SortQueryBuilderFactory(new SearchQueryFieldNameResolver()).create(orderExprs);
    assertEquals(1, sortBuilders.size());
    assertTrue(sortBuilders.iterator().next() instanceof GeoDistanceSortBuilder);
}
Also used : FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) GeoDistanceSortBuilder(org.elasticsearch.search.sort.GeoDistanceSortBuilder) SortBuilder(org.elasticsearch.search.sort.SortBuilder) FunctionExpr(com.enonic.xp.query.expr.FunctionExpr) DynamicOrderExpr(com.enonic.xp.query.expr.DynamicOrderExpr) OrderExpr(com.enonic.xp.query.expr.OrderExpr) DslOrderExpr(com.enonic.xp.query.expr.DslOrderExpr) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) DynamicOrderExpr(com.enonic.xp.query.expr.DynamicOrderExpr) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) HashSet(java.util.HashSet) GeoDistanceSortBuilder(org.elasticsearch.search.sort.GeoDistanceSortBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

SearchQueryFieldNameResolver (com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver)28 Test (org.junit.jupiter.api.Test)24 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)18 GeoDistanceSortBuilder (org.elasticsearch.search.sort.GeoDistanceSortBuilder)8 DslOrderExpr (com.enonic.xp.query.expr.DslOrderExpr)7 FieldSortBuilder (org.elasticsearch.search.sort.FieldSortBuilder)6 SortBuilder (org.elasticsearch.search.sort.SortBuilder)6 DynamicOrderExpr (com.enonic.xp.query.expr.DynamicOrderExpr)5 FieldOrderExpr (com.enonic.xp.query.expr.FieldOrderExpr)5 OrderExpr (com.enonic.xp.query.expr.OrderExpr)5 HashSet (java.util.HashSet)5 FunctionExpr (com.enonic.xp.query.expr.FunctionExpr)3 ValueFilter (com.enonic.xp.query.filter.ValueFilter)3 PropertyTree (com.enonic.xp.data.PropertyTree)2 PropertySet (com.enonic.xp.data.PropertySet)1 CompareExpr (com.enonic.xp.query.expr.CompareExpr)1 QueryExpr (com.enonic.xp.query.expr.QueryExpr)1 BooleanFilter (com.enonic.xp.query.filter.BooleanFilter)1 ExistsFilter (com.enonic.xp.query.filter.ExistsFilter)1 IdFilter (com.enonic.xp.query.filter.IdFilter)1