Search in sources :

Example 6 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)

Example 7 with Filters

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

the class JsonToFilterMapperTest method ids_filter.

@Test
public void ids_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("values", values);
    value.put("ids", valueFilter);
    final Filters filters = com.enonic.xp.lib.common.JsonToFilterMapper.create(value);
    assertTrue(filters.get(0) instanceof IdFilter);
    assertEquals(3, ((IdFilter) filters.get(0)).getValues().size());
}
Also used : IdFilter(com.enonic.xp.query.filter.IdFilter) Filters(com.enonic.xp.query.filter.Filters) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 8 with Filters

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

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

Example 10 with Filters

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

the class AbstractFindNodesQueryHandler method createNodeQuery.

NodeQuery createNodeQuery() {
    final int start = valueOrDefault(this.start, 0);
    final int count = valueOrDefault(this.count, 10);
    final QueryExpr queryExpr = QueryExpr.from(buildConstraintExpr(), buildOrderExpr());
    final Filters filters = JsonToFilterMapper.create(this.filters);
    final AggregationQueries aggregations = new QueryAggregationParams().getAggregations(this.aggregations);
    final SuggestionQueries suggestions = new QuerySuggestionParams().getSuggestions(this.suggestions);
    final HighlightQuery highlight = new QueryHighlightParams().getHighlightQuery(this.highlight);
    return NodeQuery.create().from(start).size(count).addAggregationQueries(aggregations).addSuggestionQueries(suggestions).highlight(highlight).query(queryExpr).addQueryFilters(filters).explain(this.explain).build();
}
Also used : SuggestionQueries(com.enonic.xp.query.suggester.SuggestionQueries) Filters(com.enonic.xp.query.filter.Filters) QueryExpr(com.enonic.xp.query.expr.QueryExpr) AggregationQueries(com.enonic.xp.query.aggregation.AggregationQueries) HighlightQuery(com.enonic.xp.query.highlight.HighlightQuery)

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