diff --git a/src/ext/java/org/opentripplanner/ext/geocoder/LuceneIndex.java b/src/ext/java/org/opentripplanner/ext/geocoder/LuceneIndex.java index c39d18d6c22..689b7419122 100644 --- a/src/ext/java/org/opentripplanner/ext/geocoder/LuceneIndex.java +++ b/src/ext/java/org/opentripplanner/ext/geocoder/LuceneIndex.java @@ -40,7 +40,6 @@ import org.apache.lucene.search.suggest.document.FuzzyCompletionQuery; import org.apache.lucene.search.suggest.document.SuggestIndexSearcher; import org.apache.lucene.store.ByteBuffersDirectory; -import org.opentripplanner.ext.geocoder.StopCluster.Coordinate; import org.opentripplanner.framework.collection.ListUtils; import org.opentripplanner.framework.i18n.I18NString; import org.opentripplanner.standalone.api.OtpServerRequestContext; @@ -186,53 +185,11 @@ public Stream queryStopClusters(String query) { private StopCluster toStopCluster(Document document) { var primaryId = FeedScopedId.parse(document.get(ID)); - var primary = toLocation(primaryId); + var primary = stopClusterMapper.toLocation(primaryId); return new StopCluster(primary, List.of()); } - private StopCluster.Location toLocation(FeedScopedId id) { - var loc = transitService.getStopLocation(id); - if (loc != null) { - var feedPublisher = StopClusterMapper.toFeedPublisher( - transitService.getFeedInfo(id.getFeedId()) - ); - var agencies = stopClusterMapper - .agenciesForStopLocation(loc) - .stream() - .map(StopClusterMapper::toAgency) - .toList(); - return new StopCluster.Location( - loc.getId(), - loc.getCode(), - loc.getName().toString(), - new Coordinate(loc.getLat(), loc.getLon()), - List.of(), - agencies, - feedPublisher - ); - } else { - var group = transitService.getStopLocationsGroup(id); - var feedPublisher = StopClusterMapper.toFeedPublisher( - transitService.getFeedInfo(id.getFeedId()) - ); - var agencies = stopClusterMapper - .agenciesForStopLocationsGroup(group) - .stream() - .map(StopClusterMapper::toAgency) - .toList(); - return new StopCluster.Location( - group.getId(), - group.getCode(), - group.getName().toString(), - new Coordinate(group.getLat(), group.getLon()), - List.of(), - agencies, - feedPublisher - ); - } - } - static IndexWriterConfig iwcWithSuggestField(Analyzer analyzer, final Set suggestFields) { IndexWriterConfig iwc = new IndexWriterConfig(analyzer); Codec filterCodec = new Lucene99Codec() { diff --git a/src/ext/java/org/opentripplanner/ext/geocoder/StopClusterMapper.java b/src/ext/java/org/opentripplanner/ext/geocoder/StopClusterMapper.java index 2c5e4e1aa29..543f06949ff 100644 --- a/src/ext/java/org/opentripplanner/ext/geocoder/StopClusterMapper.java +++ b/src/ext/java/org/opentripplanner/ext/geocoder/StopClusterMapper.java @@ -9,6 +9,7 @@ import org.opentripplanner.framework.geometry.WgsCoordinate; import org.opentripplanner.framework.i18n.I18NString; import org.opentripplanner.model.FeedInfo; +import org.opentripplanner.transit.model.framework.FeedScopedId; import org.opentripplanner.transit.model.network.Route; import org.opentripplanner.transit.model.organization.Agency; import org.opentripplanner.transit.model.site.StopLocation; @@ -127,5 +128,47 @@ static StopCluster.FeedPublisher toFeedPublisher(FeedInfo fi) { } } + StopCluster.Location toLocation(FeedScopedId id) { + var loc = transitService.getStopLocation(id); + if (loc != null) { + var feedPublisher = toFeedPublisher( + transitService.getFeedInfo(id.getFeedId()) + ); + var modes = transitService.getModesOfStopLocation(loc).stream().map(Enum::name).toList(); + var agencies = agenciesForStopLocation(loc) + .stream() + .map(StopClusterMapper::toAgency) + .toList(); + return new StopCluster.Location( + loc.getId(), + loc.getCode(), + loc.getName().toString(), + new StopCluster.Coordinate(loc.getLat(), loc.getLon()), + modes, + agencies, + feedPublisher + ); + } else { + var group = transitService.getStopLocationsGroup(id); + var feedPublisher = toFeedPublisher( + transitService.getFeedInfo(id.getFeedId()) + ); + var modes = transitService.getModesOfStopLocationsGroup(group).stream().map(Enum::name).toList(); + var agencies = agenciesForStopLocationsGroup(group) + .stream() + .map(StopClusterMapper::toAgency) + .toList(); + return new StopCluster.Location( + group.getId(), + group.getCode(), + group.getName().toString(), + new StopCluster.Coordinate(group.getLat(), group.getLon()), + modes, + agencies, + feedPublisher + ); + } + } + private record DeduplicationKey(I18NString name, WgsCoordinate coordinate) {} }