Search in sources :

Example 1 with GAZETTEER_REQUEST_HANDLER

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());
}
Also used : COLLECTION_NAME(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.COLLECTION_NAME) WKTReader(org.locationtech.jts.io.WKTReader) JtsGeometry(org.locationtech.spatial4j.shape.jts.JtsGeometry) SolrClient(org.codice.solr.client.solrj.SolrClient) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) SolrServerException(org.apache.solr.client.solrj.SolrServerException) WKTWriter(org.locationtech.jts.io.WKTWriter) Map(java.util.Map) GeoEntry(org.codice.ddf.spatial.geocoding.GeoEntry) COUNTRY_CODE(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.COUNTRY_CODE) ParseException(java.text.ParseException) NearbyLocation(org.codice.ddf.spatial.geocoding.context.NearbyLocation) GAZETTEER_REQUEST_HANDLER(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.GAZETTEER_REQUEST_HANDLER) GeoEntryQueryException(org.codice.ddf.spatial.geocoding.GeoEntryQueryException) ImmutableMap(com.google.common.collect.ImmutableMap) Point(org.locationtech.jts.geom.Point) GeoCodingConstants(org.codice.ddf.spatial.geocoding.GeoCodingConstants) Shape(org.locationtech.spatial4j.shape.Shape) Collectors(java.util.stream.Collectors) Suggestion(org.codice.ddf.spatial.geocoding.Suggestion) Objects(java.util.Objects) List(java.util.List) InvalidShapeException(org.locationtech.spatial4j.exception.InvalidShapeException) FEATURE_CODE(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.FEATURE_CODE) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Optional(java.util.Optional) Geometry(org.locationtech.jts.geom.Geometry) LOCATION(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.LOCATION) ClientUtils(org.apache.solr.client.solrj.util.ClientUtils) SpatialContext(org.locationtech.spatial4j.context.SpatialContext) SUGGEST_DICT(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SUGGEST_DICT) ValidationRule(org.locationtech.spatial4j.context.jts.ValidationRule) SolrClientFactory(org.codice.solr.factory.SolrClientFactory) SUGGEST_DICT_KEY(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SUGGEST_DICT_KEY) METHOD(org.apache.solr.client.solrj.SolrRequest.METHOD) SUGGEST_Q_KEY(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SUGGEST_Q_KEY) GeoEntryQueryable(org.codice.ddf.spatial.geocoding.GeoEntryQueryable) SuggesterResponse(org.apache.solr.client.solrj.response.SuggesterResponse) JtsSpatialContextFactory(org.locationtech.spatial4j.context.jts.JtsSpatialContextFactory) Logger(org.slf4j.Logger) NAME(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.NAME) SORT_VALUE(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SORT_VALUE) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) IOException(java.io.IOException) SpatialContextFactory(org.locationtech.spatial4j.context.SpatialContextFactory) SolrDocument(org.apache.solr.common.SolrDocument) SUGGEST_COUNT_KEY(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SUGGEST_COUNT_KEY) POPULATION(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.POPULATION) ID(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.ID) Collections(java.util.Collections) GeoEntryQueryException(org.codice.ddf.spatial.geocoding.GeoEntryQueryException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 COLLECTION_NAME (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.COLLECTION_NAME)1 COUNTRY_CODE (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.COUNTRY_CODE)1 FEATURE_CODE (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.FEATURE_CODE)1 GAZETTEER_REQUEST_HANDLER (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.GAZETTEER_REQUEST_HANDLER)1 ID (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.ID)1 LOCATION (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.LOCATION)1 NAME (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.NAME)1 POPULATION (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.POPULATION)1 SORT_VALUE (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SORT_VALUE)1 SUGGEST_COUNT_KEY (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SUGGEST_COUNT_KEY)1 SUGGEST_DICT (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SUGGEST_DICT)1 SUGGEST_DICT_KEY (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SUGGEST_DICT_KEY)1 SUGGEST_Q_KEY (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SUGGEST_Q_KEY)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1