Skip to content

Commit

Permalink
Move mapping code
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed May 22, 2024
1 parent 8443af2 commit 09c5e47
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 44 deletions.
45 changes: 1 addition & 44 deletions src/ext/java/org/opentripplanner/ext/geocoder/LuceneIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -186,53 +185,11 @@ public Stream<StopCluster> 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<String> suggestFields) {
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
Codec filterCodec = new Lucene99Codec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {}
}

0 comments on commit 09c5e47

Please sign in to comment.