use of ddf.catalog.solr.offlinegazetteer.GazetteerConstants.GAZETTEER_REQUEST_HANDLER in project ddf by codice.
the class GazetteerQueryOfflineSolr method getSuggestedNames.
@Override
public List<Suggestion> getSuggestedNames(String queryString, int maxResults) throws GeoEntryQueryException {
SolrQuery solrQuery = new SolrQuery();
solrQuery.setRequestHandler(GAZETTEER_REQUEST_HANDLER);
solrQuery.setParam(SUGGEST_Q_KEY, ClientUtils.escapeQueryChars(queryString));
solrQuery.setParam(SUGGEST_DICT_KEY, SUGGEST_DICT);
solrQuery.setParam(SUGGEST_COUNT_KEY, Integer.toString(Math.min(maxResults, MAX_RESULTS)));
QueryResponse response;
try {
response = client.query(solrQuery);
} catch (SolrServerException | IOException e) {
throw new GeoEntryQueryException("Error while querying", e);
}
return Optional.ofNullable(response).map(QueryResponse::getSuggesterResponse).map(SuggesterResponse::getSuggestions).map(suggestionsPerDict -> suggestionsPerDict.get(SUGGEST_DICT)).orElse(Collections.emptyList()).stream().map(suggestion -> new SuggestionImpl(suggestion.getPayload(), suggestion.getTerm())).collect(Collectors.toList());
}
Aggregations