use of org.codice.ddf.spatial.geocoding.context.impl.SuggestionImpl in project ddf by codice.
the class GazetteerQueryCatalog method getSuggestedNames.
@Override
public List<Suggestion> getSuggestedNames(String queryString, int maxResults) throws GeoEntryQueryException {
Map<String, Serializable> suggestProps = new HashMap<>();
suggestProps.put(SUGGESTION_QUERY_KEY, queryString);
suggestProps.put(SUGGESTION_CONTEXT_KEY, GAZETTEER_METACARD_TAG);
suggestProps.put(SUGGESTION_DICT_KEY, SUGGEST_PLACE_KEY);
Query suggestionQuery = new QueryImpl(filterBuilder.attribute(Core.TITLE).text(queryString));
QueryRequest suggestionRequest = new QueryRequestImpl(suggestionQuery, suggestProps);
try {
QueryResponse suggestionResponse = catalogFramework.query(suggestionRequest);
if (suggestionResponse.getPropertyValue(SUGGESTION_RESULT_KEY) instanceof List) {
List<Map.Entry<String, String>> suggestions = (List<Map.Entry<String, String>>) suggestionResponse.getPropertyValue(SUGGESTION_RESULT_KEY);
return suggestions.stream().map(suggestion -> new SuggestionImpl(suggestion.getKey(), suggestion.getValue())).limit(maxResults).collect(Collectors.toList());
}
} catch (SourceUnavailableException | FederationException | UnsupportedQueryException e) {
throw new GeoEntryQueryException("Failed to execute suggestion query", e);
}
return Collections.emptyList();
}
Aggregations