Search in sources :

Example 1 with SuggestionQuery

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

the class SuggestionQueryBuilderFactory method doCreate.

private Set<SuggestBuilder.SuggestionBuilder> doCreate(final SuggestionQueries suggestionQueries) {
    Set<SuggestBuilder.SuggestionBuilder> suggestionBuilders = new HashSet<>();
    for (final SuggestionQuery suggestionQuery : suggestionQueries) {
        final SuggestBuilder.SuggestionBuilder suggestionBuilder;
        if (suggestionQuery instanceof TermSuggestionQuery) {
            suggestionBuilder = new TermSuggestionQueryBuilderFactory(fieldNameResolver).create((TermSuggestionQuery) suggestionQuery);
        } else {
            throw new IllegalArgumentException("Unexpected suggestion type: " + suggestionQuery.getClass());
        }
        suggestionBuilders.add(suggestionBuilder);
    }
    return suggestionBuilders;
}
Also used : SuggestBuilder(org.elasticsearch.search.suggest.SuggestBuilder) TermSuggestionQuery(com.enonic.xp.query.suggester.TermSuggestionQuery) SuggestionQuery(com.enonic.xp.query.suggester.SuggestionQuery) TermSuggestionQuery(com.enonic.xp.query.suggester.TermSuggestionQuery) HashSet(java.util.HashSet)

Example 2 with SuggestionQuery

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

Aggregations

SuggestionQuery (com.enonic.xp.query.suggester.SuggestionQuery)2 TermSuggestionQuery (com.enonic.xp.query.suggester.TermSuggestionQuery)2 SuggestionQueries (com.enonic.xp.query.suggester.SuggestionQueries)1 HashSet (java.util.HashSet)1 SuggestBuilder (org.elasticsearch.search.suggest.SuggestBuilder)1