Perdjesk commented on code in PR #780:
URL: 
https://github.com/apache/incubator-baremaps/pull/780#discussion_r1323138999


##########
baremaps-core/src/main/java/org/apache/baremaps/geocoderosm/GeocoderOSMDocumentMapper.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not 
use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+
+package org.apache.baremaps.geocoderosm;
+
+
+
+import java.util.function.Function;
+import org.apache.baremaps.openstreetmap.model.Element;
+import org.apache.baremaps.openstreetmap.model.Node;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.LatLonShape;
+import org.apache.lucene.document.NumericDocValuesField;
+import org.apache.lucene.document.StoredField;
+import org.apache.lucene.document.TextField;
+import org.apache.lucene.geo.Polygon;
+import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.io.geojson.GeoJsonWriter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class GeocoderOSMDocumentMapper implements Function<Element, Document> {
+  private static final Logger logger = 
LoggerFactory.getLogger(GeocoderOSMDocumentMapper.class);
+
+  @Override
+  public Document apply(Element element) {
+    var document = new Document();
+    document.add(new StoredField("osm_id", element.id()));
+    document.add(new StoredField("osm_type", 
element.getClass().getSimpleName()));
+
+    if (element.getTags().containsKey(OSMTags.NAME.key())) {
+      document.add(
+          new TextField(OSMTags.NAME.key(), 
element.getTags().get(OSMTags.NAME.key()).toString(),
+              Field.Store.YES));
+    }
+
+    if (element instanceof Node node) {
+      document.add(LatLonShape.createIndexableFields("polygon", node.getLat(), 
node.getLon())[0]);

Review Comment:
   I took a note in https://github.com/apache/incubator-baremaps/issues/762 to 
revisit this later.
   
   For this PR I would propose to leave as is. The motivation to check against 
the type of element instead of the geometry is that Node provides lat/long 
explicitly. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to