Search in sources :

Example 1 with ExistsFilter

use of com.enonic.xp.query.filter.ExistsFilter in project xp by enonic.

the class JsonToFilterMapperTest method boolean_filter.

@SuppressWarnings("unchecked")
@Test
public void boolean_filter() throws Exception {
    Map<String, Object> filter = new HashMap<>();
    final Map<String, Object> boolFilter = new HashMap<>();
    boolFilter.put("must", List.of(createExistsFilter(), createExistsFilter()));
    boolFilter.put("mustNot", List.of(createExistsFilter()));
    boolFilter.put("should", List.of(createExistsFilter(), createExistsFilter(), createExistsFilter()));
    filter.put("boolean", boolFilter);
    final Filters filters = com.enonic.xp.lib.common.JsonToFilterMapper.create(filter);
    assertTrue(filters.get(0) instanceof BooleanFilter);
    final BooleanFilter booleanFilter = (BooleanFilter) filters.get(0);
    final ImmutableSet<Filter> mustFilters = booleanFilter.getMust();
    assertEquals(2, mustFilters.size());
    assertTrue(mustFilters.iterator().next() instanceof ExistsFilter);
    assertTrue(mustFilters.iterator().next() instanceof ExistsFilter);
    final ImmutableSet<Filter> mustNotFilters = booleanFilter.getMustNot();
    assertEquals(1, mustNotFilters.size());
    final ImmutableSet<Filter> shouldFilters = booleanFilter.getShould();
    assertEquals(3, shouldFilters.size());
}
Also used : BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) Filters(com.enonic.xp.query.filter.Filters) HashMap(java.util.HashMap) IdFilter(com.enonic.xp.query.filter.IdFilter) ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) ValueFilter(com.enonic.xp.query.filter.ValueFilter) BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) Filter(com.enonic.xp.query.filter.Filter) Test(org.junit.jupiter.api.Test)

Example 2 with ExistsFilter

use of com.enonic.xp.query.filter.ExistsFilter 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 3 with ExistsFilter

use of com.enonic.xp.query.filter.ExistsFilter in project xp by enonic.

the class JsonToFilterMapperTest method array_on_root_single.

@Test
public void array_on_root_single() throws Exception {
    final List<Map<String, Object>> existsFilters = new ArrayList<>();
    existsFilters.add(createExistsFilter());
    final Filters filters = com.enonic.xp.lib.common.JsonToFilterMapper.create(existsFilters);
    assertTrue(filters.get(0) instanceof ExistsFilter);
}
Also used : ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) Filters(com.enonic.xp.query.filter.Filters) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 4 with ExistsFilter

use of com.enonic.xp.query.filter.ExistsFilter in project xp by enonic.

the class JsonToFilterMapperTest method exists_filter.

@Test
public void exists_filter() throws Exception {
    final Map<String, Object> existsFilter = createExistsFilter();
    final Filters filters = com.enonic.xp.lib.common.JsonToFilterMapper.create(existsFilter);
    assertTrue(filters.get(0) instanceof ExistsFilter);
    assertEquals("myField", ((ExistsFilter) filters.get(0)).getFieldName());
}
Also used : ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) Filters(com.enonic.xp.query.filter.Filters) Test(org.junit.jupiter.api.Test)

Example 5 with ExistsFilter

use of com.enonic.xp.query.filter.ExistsFilter in project xp by enonic.

the class JsonToFilterMapperTest method notExists_filter.

@Test
public void notExists_filter() throws Exception {
    Map<String, Object> value = new HashMap<>();
    final HashMap<String, Object> notExistsFilter = new HashMap<>();
    notExistsFilter.put("field", "myField");
    value.put("notExists", notExistsFilter);
    final Filters filters = com.enonic.xp.lib.common.JsonToFilterMapper.create(value);
    assertTrue(filters.get(0) instanceof BooleanFilter);
    final BooleanFilter booleanFilter = (BooleanFilter) filters.get(0);
    final ImmutableSet<Filter> mustNotFilters = booleanFilter.getMustNot();
    assertEquals(1, mustNotFilters.size());
    final Filter mustNotFilter = mustNotFilters.iterator().next();
    assertTrue(mustNotFilter instanceof ExistsFilter);
}
Also used : BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) Filters(com.enonic.xp.query.filter.Filters) HashMap(java.util.HashMap) IdFilter(com.enonic.xp.query.filter.IdFilter) ExistsFilter(com.enonic.xp.query.filter.ExistsFilter) ValueFilter(com.enonic.xp.query.filter.ValueFilter) BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) Filter(com.enonic.xp.query.filter.Filter) Test(org.junit.jupiter.api.Test)

Aggregations

ExistsFilter (com.enonic.xp.query.filter.ExistsFilter)5 Test (org.junit.jupiter.api.Test)5 Filters (com.enonic.xp.query.filter.Filters)4 HashMap (java.util.HashMap)3 BooleanFilter (com.enonic.xp.query.filter.BooleanFilter)2 Filter (com.enonic.xp.query.filter.Filter)2 IdFilter (com.enonic.xp.query.filter.IdFilter)2 ValueFilter (com.enonic.xp.query.filter.ValueFilter)2 SearchQueryFieldNameResolver (com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1