Skip to content

Commit a7cefc0

Browse files
committed
Resolves #53 - Multiple search result entries with the same result geometry
1 parent f615e1f commit a7cefc0

File tree

1 file changed

+49
-11
lines changed

1 file changed

+49
-11
lines changed

src/main/java/il/org/osm/israelhiking/PlanetSearchProfile.java

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class PlanetSearchProfile implements Profile {
3737
public static final String POINTS_LAYER_NAME = "global_points";
3838

3939
private static final Map<String, MinWayIdFinder> Singles = new ConcurrentHashMap<>();
40+
private static final Map<String, MinWayIdFinder> NamedHighways = new ConcurrentHashMap<>();
4041
private static final Map<String, MinWayIdFinder> Waterways = new ConcurrentHashMap<>();
4142

4243
public PlanetSearchProfile(PlanetilerConfig config, ElasticsearchClient esClient, String pointsIndexName, String bboxIndexName, String[] supportedLnaguages) {
@@ -154,8 +155,22 @@ public void preprocessOsmWay(OsmElement.Way way) {
154155
Waterways.get(waterwayName).addWayId(way.id());
155156
}
156157
}
158+
return;
157159
}
158160

161+
if (way.hasTag("highway", "track", "path", "footway", "cycleway") && way.hasTag("name")) {
162+
String highwayName = way.getString("name");
163+
synchronized(highwayName.intern()) {
164+
if (!NamedHighways.containsKey(highwayName)) {
165+
var finder = new MinWayIdFinder();
166+
finder.addWayId(way.id());
167+
NamedHighways.put(highwayName, finder);
168+
} else {
169+
NamedHighways.get(highwayName).addWayId(way.id());
170+
}
171+
}
172+
return;
173+
}
159174
}
160175

161176
@Override
@@ -348,20 +363,43 @@ private boolean processHighwayFeautre(SourceFeature feature, FeatureCollector fe
348363
// Highways without a name should not be included in the search or POI layer.
349364
return true;
350365
}
351-
var point = GeoUtils.point(feature.worldGeometry().getCoordinate());
352-
var pointDocument = new PointDocument();
353-
convertTagsToDocument(pointDocument, feature);
354-
pointDocument.poiSource = "OSM";
355-
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
356-
pointDocument.location = new double[]{lngLatPoint.getX(), lngLatPoint.getY()};
357-
setIconColorCategory(pointDocument, feature);
358-
359-
if (pointDocument.poiIcon == "icon-search") {
366+
if (feature.isPoint()) {
367+
// We don't want to process highway nodes (bus stops, etc.) here.
368+
return false;
369+
}
370+
if (!feature.hasTag("highway", "track", "path", "footway", "cycleway")) {
371+
return true;
372+
}
373+
374+
String name = feature.getString("name");
375+
if (!NamedHighways.containsKey(name)) {
360376
return true;
361377
}
362378

363-
insertPointToElasticsearch(pointDocument, sourceFeatureToDocumentId(feature));
364-
return true;
379+
var highway = NamedHighways.get(name);
380+
synchronized(highway) {
381+
382+
highway.lineMerger.add(feature.worldGeometry());
383+
highway.ids.remove(feature.id());
384+
385+
if (highway.minId == feature.id()) {
386+
highway.representingFeature = feature;
387+
}
388+
if (!highway.ids.isEmpty()) {
389+
return true;
390+
}
391+
var minIdFeature = highway.representingFeature;
392+
var point = GeoUtils.point(((Geometry)highway.lineMerger.getMergedLineStrings().iterator().next()).getCoordinate());
393+
var pointDocument = new PointDocument();
394+
setIconColorCategory(pointDocument, minIdFeature);
395+
convertTagsToDocument(pointDocument, minIdFeature);
396+
pointDocument.poiSource = "OSM";
397+
var lngLatPoint = GeoUtils.worldToLatLonCoords(point).getCoordinate();
398+
pointDocument.location = new double[]{lngLatPoint.getX(), lngLatPoint.getY()};
399+
insertPointToElasticsearch(pointDocument, sourceFeatureToDocumentId(feature));
400+
401+
return true;
402+
}
365403
}
366404

367405
private boolean processOtherSourceFeature(SourceFeature feature, FeatureCollector features) throws GeometryException {

0 commit comments

Comments
 (0)