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);
}
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;
}
Aggregations