Search in sources :

Example 1 with Filters

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

the class JsonToFilterMapperTest method array_on_root.

@Test
public void array_on_root() throws Exception {
    final List<Map<String, Object>> existsFilters = new ArrayList<>();
    existsFilters.add(createExistsFilter());
    existsFilters.add(createExistsFilter());
    existsFilters.add(createExistsFilter());
    final Filters filters = com.enonic.xp.lib.common.JsonToFilterMapper.create(existsFilters);
    assertTrue(filters.get(0) instanceof BooleanFilter);
    final ImmutableSet<Filter> mustFilters = ((BooleanFilter) filters.get(0)).getMust();
    assertEquals(3, mustFilters.size());
}
Also used : BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) Filters(com.enonic.xp.query.filter.Filters) 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) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 2 with Filters

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

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

the class JsonToFilterMapperTest method values_filter.

@Test
public void values_filter() throws Exception {
    Map<String, Object> value = new HashMap<>();
    List<String> values = List.of("fisk", "ost", "løk");
    final HashMap<String, Object> valueFilter = new HashMap<>();
    valueFilter.put("field", "myField");
    valueFilter.put("values", values);
    value.put("hasValue", valueFilter);
    final Filters filters = com.enonic.xp.lib.common.JsonToFilterMapper.create(value);
    assertTrue(filters.get(0) instanceof ValueFilter);
    assertEquals("myField", ((ValueFilter) filters.get(0)).getFieldName());
    assertEquals(3, ((ValueFilter) filters.get(0)).getValues().size());
}
Also used : Filters(com.enonic.xp.query.filter.Filters) HashMap(java.util.HashMap) ValueFilter(com.enonic.xp.query.filter.ValueFilter) Test(org.junit.jupiter.api.Test)

Example 4 with Filters

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

the class MultiRepoSearchSourceAdaptorTest method multiple_repos.

@Test
public void multiple_repos() throws Exception {
    final ESSource source = MultiRepoSearchSourceAdaptor.adapt(MultiRepoSearchSource.create().add(SingleRepoSearchSource.create().repositoryId(RepositoryId.from("repo1")).branch(Branch.from("branch1")).acl(PrincipalKeys.from(PrincipalKey.ofAnonymous())).build()).add(SingleRepoSearchSource.create().repositoryId(RepositoryId.from("repo2")).branch(Branch.from("branch2")).acl(PrincipalKeys.from(PrincipalKey.ofAnonymous())).build()).build());
    assertTrue(source.getIndexNames().containsAll(Arrays.asList("search-repo1", "search-repo2")));
    assertTrue(source.getIndexTypes().containsAll(Arrays.asList("branch1", "branch2")));
    final Filters filters = source.getFilters();
    assertEquals(1, filters.getSize());
    final Filter allFilters = filters.get(0);
    assert (allFilters instanceof BooleanFilter);
    final ImmutableSet<Filter> shouldFilters = ((BooleanFilter) allFilters).getMust();
    assertEquals(2, shouldFilters.size());
}
Also used : BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) Filters(com.enonic.xp.query.filter.Filters) BooleanFilter(com.enonic.xp.query.filter.BooleanFilter) Filter(com.enonic.xp.query.filter.Filter) Test(org.junit.jupiter.api.Test)

Example 5 with Filters

use of com.enonic.xp.query.filter.Filters 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)

Aggregations

Filters (com.enonic.xp.query.filter.Filters)10 Test (org.junit.jupiter.api.Test)8 HashMap (java.util.HashMap)6 ExistsFilter (com.enonic.xp.query.filter.ExistsFilter)5 Filter (com.enonic.xp.query.filter.Filter)5 BooleanFilter (com.enonic.xp.query.filter.BooleanFilter)4 IdFilter (com.enonic.xp.query.filter.IdFilter)4 ValueFilter (com.enonic.xp.query.filter.ValueFilter)4 QueryExpr (com.enonic.xp.query.expr.QueryExpr)2 HighlightQuery (com.enonic.xp.query.highlight.HighlightQuery)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ContentQuery (com.enonic.xp.content.ContentQuery)1 FindContentIdsByQueryResult (com.enonic.xp.content.FindContentIdsByQueryResult)1 AggregationQueries (com.enonic.xp.query.aggregation.AggregationQueries)1 AggregationQuery (com.enonic.xp.query.aggregation.AggregationQuery)1 SuggestionQueries (com.enonic.xp.query.suggester.SuggestionQueries)1 ContentTypeNames (com.enonic.xp.schema.content.ContentTypeNames)1