use of org.codice.ddf.spatial.geocoding.Suggestion 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());
}
use of org.codice.ddf.spatial.geocoding.Suggestion in project ddf by codice.
the class SuggestionImplTest method testConstructor.
@Test
public void testConstructor() {
Suggestion suggestion = new SuggestionImpl("id1", "name1");
assertThat(suggestion.getId(), is("id1"));
assertThat(suggestion.getName(), is("name1"));
}
Aggregations