Search in sources :

Example 1 with SuggestionQueries

use of com.enonic.xp.query.suggester.SuggestionQueries in project xp by enonic.

the class SuggestionQueriesTest method testEmpty.

@Test
public void testEmpty() {
    final SuggestionQueries queries = SuggestionQueries.empty();
    assertTrue(queries.isEmpty());
}
Also used : SuggestionQueries(com.enonic.xp.query.suggester.SuggestionQueries) Test(org.junit.jupiter.api.Test)

Example 2 with SuggestionQueries

use of com.enonic.xp.query.suggester.SuggestionQueries in project xp by enonic.

the class SuggestionQueriesTest method testBuilder.

@Test
public void testBuilder() {
    final TermSuggestionQuery query = TermSuggestionQuery.create("queryName").field("category").text("value").analyzer("analyzer").size(1).maxEdits(2).prefixLength(3).minWordLength(4).maxInspections(5).minDocFreq(6f).maxTermFreq(7f).sort(TermSuggestionQuery.Sort.FREQUENCY).suggestMode(TermSuggestionQuery.SuggestMode.ALWAYS).stringDistance(TermSuggestionQuery.StringDistance.INTERNAL).build();
    final SuggestionQueries queries = SuggestionQueries.create().add(query).build();
    assertNotNull(queries);
    assertTrue(queries.isNotEmpty());
    assertTrue(queries.contains(query));
}
Also used : SuggestionQueries(com.enonic.xp.query.suggester.SuggestionQueries) TermSuggestionQuery(com.enonic.xp.query.suggester.TermSuggestionQuery) Test(org.junit.jupiter.api.Test)

Example 3 with SuggestionQueries

use of com.enonic.xp.query.suggester.SuggestionQueries in project xp by enonic.

the class QuerySuggestionParams method getSuggestions.

public SuggestionQueries getSuggestions(final Map<String, Object> suggestionsMap) {
    if (suggestionsMap == null) {
        return SuggestionQueries.empty();
    }
    final SuggestionQueries.Builder suggestionQueries = SuggestionQueries.create();
    suggestionsMap.forEach((name, suggestionQueryMap) -> {
        final SuggestionQuery suggestionQuery = suggestionQueryFromParams(name, (Map<String, Object>) suggestionQueryMap);
        if (suggestionQuery != null) {
            suggestionQueries.add(suggestionQuery);
        }
    });
    return suggestionQueries.build();
}
Also used : SuggestionQueries(com.enonic.xp.query.suggester.SuggestionQueries) TermSuggestionQuery(com.enonic.xp.query.suggester.TermSuggestionQuery) SuggestionQuery(com.enonic.xp.query.suggester.SuggestionQuery)

Example 4 with SuggestionQueries

use of com.enonic.xp.query.suggester.SuggestionQueries 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

SuggestionQueries (com.enonic.xp.query.suggester.SuggestionQueries)4 TermSuggestionQuery (com.enonic.xp.query.suggester.TermSuggestionQuery)2 Test (org.junit.jupiter.api.Test)2 AggregationQueries (com.enonic.xp.query.aggregation.AggregationQueries)1 QueryExpr (com.enonic.xp.query.expr.QueryExpr)1 Filters (com.enonic.xp.query.filter.Filters)1 HighlightQuery (com.enonic.xp.query.highlight.HighlightQuery)1 SuggestionQuery (com.enonic.xp.query.suggester.SuggestionQuery)1