Search in sources :

Example 1 with SuggestionImpl

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();
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) Serializable(java.io.Serializable) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) HashMap(java.util.HashMap) GeoEntryQueryException(org.codice.ddf.spatial.geocoding.GeoEntryQueryException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) QueryImpl(ddf.catalog.operation.impl.QueryImpl) GeoEntry(org.codice.ddf.spatial.geocoding.GeoEntry) SuggestionImpl(org.codice.ddf.spatial.geocoding.context.impl.SuggestionImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

FederationException (ddf.catalog.federation.FederationException)1 Query (ddf.catalog.operation.Query)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 QueryResponse (ddf.catalog.operation.QueryResponse)1 QueryImpl (ddf.catalog.operation.impl.QueryImpl)1 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)1 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)1 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 GeoEntry (org.codice.ddf.spatial.geocoding.GeoEntry)1 GeoEntryQueryException (org.codice.ddf.spatial.geocoding.GeoEntryQueryException)1 SuggestionImpl (org.codice.ddf.spatial.geocoding.context.impl.SuggestionImpl)1