Search in sources :

Example 1 with NAME

use of ddf.catalog.solr.offlinegazetteer.GazetteerConstants.NAME in project ddf by codice.

the class GazetteerQueryOfflineSolr method convert.

private NearbyLocation convert(SolrDocument doc, Geometry originalLocation) {
    String location = getField(doc, LOCATION, String.class);
    String title = Optional.ofNullable(getField(doc, NAME, String.class)).filter(Objects::nonNull).filter(s -> !s.isEmpty()).orElse("NO TITLE");
    String cardinalDirection = "";
    double distance = 0;
    try {
        Geometry geo = WKT_READER_THREAD_LOCAL.get().read(location);
        cardinalDirection = bearingToCardinalDirection(getBearing(originalLocation.getCentroid(), geo.getCentroid()));
        distance = convertDegreeToKilometer(originalLocation.distance(geo.getCentroid()));
    } catch (org.locationtech.jts.io.ParseException e) {
        LOGGER.debug("Could not parse location for item (object: {})", doc, e);
    }
    return new NearbyLocationImpl(title, cardinalDirection, distance);
}
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) JtsGeometry(org.locationtech.spatial4j.shape.jts.JtsGeometry) Geometry(org.locationtech.jts.geom.Geometry) Objects(java.util.Objects)

Example 2 with NAME

use of ddf.catalog.solr.offlinegazetteer.GazetteerConstants.NAME in project ddf by codice.

the class CatalogGazetteerForwardingPlugin method convert.

protected static SolrInputDocument convert(Metacard metacard) {
    SolrInputDocument solrDoc = new SolrInputDocument();
    Consumer<String> getAttrAndAdd = (attributeName) -> Optional.ofNullable(getStringAttribute(metacard, attributeName)).ifPresent(attributeValue -> solrDoc.addField(GAZETTEER_TO_CATALOG.inverse().get(attributeName), attributeValue));
    getAttrAndAdd.accept(GAZETTEER_TO_CATALOG.get(DESCRIPTION));
    getAttrAndAdd.accept(GAZETTEER_TO_CATALOG.get(FEATURE_CODE));
    getAttrAndAdd.accept(GAZETTEER_TO_CATALOG.get(NAME));
    getAttrAndAdd.accept(GAZETTEER_TO_CATALOG.get(ID));
    getAttrAndAdd.accept(GAZETTEER_TO_CATALOG.get(COUNTRY_CODE));
    Optional.of(metacard).map(m -> getStringAttribute(m, GAZETTEER_TO_CATALOG.get(LOCATION))).ifPresent(v -> solrDoc.addField(LOCATION, v));
    Optional.of(metacard).map(m -> m.getAttribute(GAZETTEER_TO_CATALOG.get(POPULATION))).map(Attribute::getValue).filter(Long.class::isInstance).map(Long.class::cast).ifPresent(v -> solrDoc.addField(POPULATION, v));
    Optional.of(metacard).map(m -> m.getAttribute(GAZETTEER_TO_CATALOG.get(SORT_VALUE))).map(Attribute::getValue).filter(Integer.class::isInstance).map(Integer.class::cast).ifPresent(v -> solrDoc.addField(SORT_VALUE, v));
    return solrDoc;
}
Also used : COLLECTION_NAME(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.COLLECTION_NAME) PreQueryPlugin(ddf.catalog.plugin.PreQueryPlugin) SolrClient(org.codice.solr.client.solrj.SolrClient) SolrClientFactory(org.codice.solr.factory.SolrClientFactory) LoggerFactory(org.slf4j.LoggerFactory) DESCRIPTION(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.DESCRIPTION) DeleteResponse(ddf.catalog.operation.DeleteResponse) SUGGEST_DICT_KEY(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SUGGEST_DICT_KEY) Update(ddf.catalog.operation.Update) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) PostIngestPlugin(ddf.catalog.plugin.PostIngestPlugin) SolrServerException(org.apache.solr.client.solrj.SolrServerException) CreateResponse(ddf.catalog.operation.CreateResponse) Metacard(ddf.catalog.data.Metacard) SUGGEST_Q_KEY(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SUGGEST_Q_KEY) QueryRequest(ddf.catalog.operation.QueryRequest) COUNTRY_CODE(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.COUNTRY_CODE) Nullable(javax.annotation.Nullable) GAZETTEER_REQUEST_HANDLER(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.GAZETTEER_REQUEST_HANDLER) GAZETTEER_METACARD_TAG(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.GAZETTEER_METACARD_TAG) Logger(org.slf4j.Logger) NAME(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.NAME) SORT_VALUE(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SORT_VALUE) SUGGEST_BUILD_KEY(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SUGGEST_BUILD_KEY) StopProcessingException(ddf.catalog.plugin.StopProcessingException) IOException(java.io.IOException) GAZETTEER_TO_CATALOG(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.GAZETTEER_TO_CATALOG) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) Consumer(java.util.function.Consumer) SUGGESTION_BUILD_KEY(ddf.catalog.Constants.SUGGESTION_BUILD_KEY) List(java.util.List) Attribute(ddf.catalog.data.Attribute) FEATURE_CODE(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.FEATURE_CODE) SolrQuery(org.apache.solr.client.solrj.SolrQuery) POPULATION(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.POPULATION) Optional(java.util.Optional) LOCATION(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.LOCATION) ID(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.ID) UpdateResponse(ddf.catalog.operation.UpdateResponse) SUGGEST_DICT(ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SUGGEST_DICT) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrInputDocument(org.apache.solr.common.SolrInputDocument)

Aggregations

COLLECTION_NAME (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.COLLECTION_NAME)2 COUNTRY_CODE (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.COUNTRY_CODE)2 FEATURE_CODE (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.FEATURE_CODE)2 GAZETTEER_REQUEST_HANDLER (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.GAZETTEER_REQUEST_HANDLER)2 ID (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.ID)2 LOCATION (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.LOCATION)2 NAME (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.NAME)2 POPULATION (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.POPULATION)2 SORT_VALUE (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SORT_VALUE)2 SUGGEST_DICT (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SUGGEST_DICT)2 SUGGEST_DICT_KEY (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SUGGEST_DICT_KEY)2 SUGGEST_Q_KEY (ddf.catalog.solr.offlinegazetteer.GazetteerConstants.SUGGEST_Q_KEY)2 IOException (java.io.IOException)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 SolrQuery (org.apache.solr.client.solrj.SolrQuery)2 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2 SolrClient (org.codice.solr.client.solrj.SolrClient)2 SolrClientFactory (org.codice.solr.factory.SolrClientFactory)2