Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev-2.x' into upgrade-protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Jan 9, 2025
2 parents fb9bad6 + 0fb152d commit 665a2d2
Show file tree
Hide file tree
Showing 32 changed files with 322 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.codecs.lucene912.Lucene912Codec;
import org.apache.lucene.codecs.lucene101.Lucene101Codec;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.document.StoredField;
Expand All @@ -34,7 +34,7 @@
import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.suggest.document.Completion912PostingsFormat;
import org.apache.lucene.search.suggest.document.Completion101PostingsFormat;
import org.apache.lucene.search.suggest.document.CompletionAnalyzer;
import org.apache.lucene.search.suggest.document.ContextQuery;
import org.apache.lucene.search.suggest.document.ContextSuggestField;
Expand Down Expand Up @@ -203,8 +203,8 @@ private StopCluster toStopCluster(Document document) {

static IndexWriterConfig iwcWithSuggestField(Analyzer analyzer, final Set<String> suggestFields) {
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
Codec filterCodec = new Lucene912Codec() {
final PostingsFormat postingsFormat = new Completion912PostingsFormat();
Codec filterCodec = new Lucene101Codec() {
final PostingsFormat postingsFormat = new Completion101PostingsFormat();

@Override
public PostingsFormat getPostingsFormatForField(String field) {
Expand Down Expand Up @@ -285,7 +285,7 @@ private Stream<Document> matchingDocuments(
.stream(topDocs.scoreDocs)
.map(scoreDoc -> {
try {
return searcher.doc(scoreDoc.doc);
return searcher.storedFields().document(scoreDoc.doc);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -330,7 +330,7 @@ private Stream<Document> matchingDocuments(
.stream(topDocs.scoreDocs)
.map(scoreDoc -> {
try {
return searcher.doc(scoreDoc.doc);
return searcher.storedFields().document(scoreDoc.doc);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ParkAndRideResource(
// - serverContext.graphFinder(). This needs at least a comment!
// - This can be replaced with a search done with the SiteRepository
// - if we have a radius search there.
this.graphFinder = new DirectGraphFinder(serverContext.transitService()::findRegularStops);
this.graphFinder = new DirectGraphFinder(serverContext.transitService()::findRegularStopsByBoundingBox);
}

/** Envelopes are in latitude, longitude format */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public List<ApiStopShort> getStopsInRadius(

radius = Math.min(radius, MAX_STOP_SEARCH_RADIUS);

return new DirectGraphFinder(serverContext.transitService()::findRegularStops)
return new DirectGraphFinder(serverContext.transitService()::findRegularStopsByBoundingBox)
.findClosestStops(new Coordinate(lon, lat), radius)
.stream()
.map(it -> StopMapper.mapToApiShort(it.stop, it.distance))
Expand All @@ -221,10 +221,9 @@ public List<ApiStopShort> getStopsInRadius(
new Coordinate(maxLon, maxLat)
);

var stops = transitService().findRegularStops(envelope);
var stops = transitService().findRegularStopsByBoundingBox(envelope);
return stops
.stream()
.filter(stop -> envelope.contains(stop.getCoordinate().asJtsCoordinate()))
.map(StopMapper::mapToApiShort)
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public StopsLayerBuilder(

protected List<Geometry> getGeometries(Envelope query) {
return transitService
.findRegularStops(query)
.findRegularStopsByBoundingBox(query)
.stream()
.filter(filter)
.map(stop -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,9 +752,8 @@ public DataFetcher<Iterable<Object>> stopsByBbox() {
);

Stream<RegularStop> stopStream = getTransitService(environment)
.findRegularStops(envelope)
.stream()
.filter(stop -> envelope.contains(stop.getCoordinate().asJtsCoordinate()));
.findRegularStopsByBoundingBox(envelope)
.stream();

if (args.getGraphQLFeeds() != null) {
List<String> feedIds = args.getGraphQLFeeds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.lang.Boolean.TRUE;
import static java.util.Collections.emptyList;
import static org.opentripplanner.apis.transmodel.mapping.SeverityMapper.getTransmodelSeverity;
import static org.opentripplanner.apis.transmodel.mapping.TransitIdMapper.mapIDToDomain;
import static org.opentripplanner.apis.transmodel.mapping.TransitIdMapper.mapIDsToDomainNullSafe;
import static org.opentripplanner.apis.transmodel.model.EnumTypes.FILTER_PLACE_TYPE_ENUM;
import static org.opentripplanner.apis.transmodel.model.EnumTypes.MULTI_MODAL_MODE;
Expand Down Expand Up @@ -115,6 +116,7 @@
import org.opentripplanner.routing.graphfinder.PlaceType;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace;
import org.opentripplanner.transit.api.model.FilterValues;
import org.opentripplanner.transit.api.request.FindRegularStopsByBoundingBoxRequest;
import org.opentripplanner.transit.api.request.TripRequest;
import org.opentripplanner.transit.model.basic.TransitMode;
import org.opentripplanner.transit.model.framework.FeedScopedId;
Expand Down Expand Up @@ -439,10 +441,7 @@ private GraphQLSchema create() {
.build()
)
.dataFetcher(env ->
StopPlaceType.fetchStopPlaceById(
TransitIdMapper.mapIDToDomain(env.getArgument("id")),
env
)
StopPlaceType.fetchStopPlaceById(mapIDToDomain(env.getArgument("id")), env)
)
.build()
)
Expand Down Expand Up @@ -576,7 +575,7 @@ private GraphQLSchema create() {
.dataFetcher(environment ->
GqlUtil
.getTransitService(environment)
.getStopLocation(TransitIdMapper.mapIDToDomain(environment.getArgument("id")))
.getStopLocation(mapIDToDomain(environment.getArgument("id")))
)
.build()
)
Expand Down Expand Up @@ -610,7 +609,7 @@ private GraphQLSchema create() {
}
TransitService transitService = GqlUtil.getTransitService(environment);
return ((List<String>) environment.getArgument("ids")).stream()
.map(id -> transitService.getStopLocation(TransitIdMapper.mapIDToDomain(id)))
.map(id -> transitService.getStopLocation(mapIDToDomain(id)))
.collect(Collectors.toList());
}
if (environment.getArgument("name") == null) {
Expand Down Expand Up @@ -661,15 +660,22 @@ private GraphQLSchema create() {
.build()
)
.argument(
GraphQLArgument.newArgument().name("authority").type(Scalars.GraphQLString).build()
GraphQLArgument
.newArgument()
.name("authority")
.deprecate(
"This is the Transmodel namespace or the GTFS feedID - avoid using this. Request a new field if necessary."
)
.type(Scalars.GraphQLString)
.build()
)
.argument(
GraphQLArgument
.newArgument()
.name("filterByInUse")
.description("If true only quays with at least one visiting line are included.")
.type(Scalars.GraphQLBoolean)
.defaultValue(Boolean.FALSE)
.defaultValueProgrammatic(Boolean.FALSE)
.build()
)
.dataFetcher(environment -> {
Expand All @@ -683,24 +689,19 @@ private GraphQLSchema create() {
environment.getArgument("maximumLatitude")
)
);

var authority = environment.<String>getArgument("authority");
var filterInUse = environment.<Boolean>getArgument("filterByInUse");

FindRegularStopsByBoundingBoxRequest findRegularStopsByBoundingBoxRequest = FindRegularStopsByBoundingBoxRequest
.of(envelope)
.withFeedId(authority)
.filterByInUse(filterInUse)
.build();

return GqlUtil
.getTransitService(environment)
.findRegularStops(envelope)
.stream()
.filter(stop -> envelope.contains(stop.getCoordinate().asJtsCoordinate()))
.filter(stop ->
environment.getArgument("authority") == null ||
stop.getId().getFeedId().equalsIgnoreCase(environment.getArgument("authority"))
)
.filter(stop -> {
boolean filterByInUse = TRUE.equals(environment.getArgument("filterByInUse"));
boolean inUse = !GqlUtil
.getTransitService(environment)
.findPatterns(stop, true)
.isEmpty();
return !filterByInUse || inUse;
})
.collect(Collectors.toList());
.findRegularStopsByBoundingBox(findRegularStopsByBoundingBoxRequest);
})
.build()
)
Expand Down Expand Up @@ -1438,7 +1439,7 @@ private GraphQLSchema create() {
.build()
)
.dataFetcher(environment -> {
var bikeParkId = TransitIdMapper.mapIDToDomain(environment.getArgument("id"));
var bikeParkId = mapIDToDomain(environment.getArgument("id"));
return GqlUtil
.getVehicleParkingService(environment)
.listBikeParks()
Expand Down Expand Up @@ -1573,7 +1574,7 @@ private GraphQLSchema create() {
return GqlUtil
.getTransitService(environment)
.getTransitAlertService()
.getAlertById(TransitIdMapper.mapIDToDomain(situationNumber));
.getAlertById(mapIDToDomain(situationNumber));
})
.build()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,8 @@ public static Collection<MonoOrMultiModalStation> fetchStopPlaces(
);

Stream<Station> stations = transitService
.findRegularStops(envelope)
.findRegularStopsByBoundingBox(envelope)
.stream()
.filter(stop -> envelope.contains(stop.getCoordinate().asJtsCoordinate()))
.map(StopLocation::getParentStation)
.filter(Objects::nonNull)
.distinct();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private static LayerBuilder<?> createLayerBuilder(
case RegularStop -> new StopLayerBuilder<>(
layerParameters,
locale,
e -> context.transitService().findRegularStops(e)
e -> context.transitService().findRegularStopsByBoundingBox(e)
);
case AreaStop -> new StopLayerBuilder<>(
layerParameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public StraightLineNearbyStopFinder(TransitService transitService, Duration dura
// We need to accommodate straight line distance (in meters) but when streets are present we
// use an earliest arrival search, which optimizes on time. Ideally we'd specify in meters,
// but we don't have much of a choice here. Use the default walking speed to convert.
this.directGraphFinder = new DirectGraphFinder(transitService::findRegularStops);
this.directGraphFinder = new DirectGraphFinder(transitService::findRegularStopsByBoundingBox);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public interface OtpServerRequestContext {
TraverseVisitor<State, Edge> traverseVisitor();

default GraphFinder graphFinder() {
return GraphFinder.getInstance(graph(), transitService()::findRegularStops);
return GraphFinder.getInstance(graph(), transitService()::findRegularStopsByBoundingBox);
}

FlexParameters flexParameters();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.opentripplanner.transit.api.model;

import com.beust.jcommander.internal.Nullable;
import java.util.Collection;
import java.util.NoSuchElementException;
import javax.annotation.Nullable;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.service.TransitService;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.opentripplanner.transit.api.request;

import javax.annotation.Nullable;
import org.locationtech.jts.geom.Envelope;
import org.opentripplanner.transit.model.site.RegularStop;

/**
* A request for {@link RegularStop}s within a bounding box.
* <p/>
* This request is used to retrieve {@link RegularStop}s that are within a provided bounding box and
* match the other criteria.
*/
public class FindRegularStopsByBoundingBoxRequest {

private final Envelope envelope;

@Nullable
private final String feedId;

private final boolean filterByInUse;

FindRegularStopsByBoundingBoxRequest(
Envelope envelope,
@Nullable String feedId,
boolean filterByInUse
) {
this.envelope = envelope;
this.feedId = feedId;
this.filterByInUse = filterByInUse;
}

public static FindRegularStopsByBoundingBoxRequestBuilder of(Envelope envelope) {
return new FindRegularStopsByBoundingBoxRequestBuilder(envelope);
}

public Envelope envelope() {
return envelope;
}

@Nullable
public String feedId() {
return feedId;
}

public boolean filterByInUse() {
return filterByInUse;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.opentripplanner.transit.api.request;

import javax.annotation.Nullable;
import org.locationtech.jts.geom.Envelope;

public class FindRegularStopsByBoundingBoxRequestBuilder {

private final Envelope envelope;

@Nullable
private String feedId;

private boolean filterByInUse = false;

FindRegularStopsByBoundingBoxRequestBuilder(Envelope envelope) {
this.envelope = envelope;
}

public FindRegularStopsByBoundingBoxRequestBuilder withFeedId(@Nullable String feedId) {
this.feedId = feedId;
return this;
}

public FindRegularStopsByBoundingBoxRequestBuilder filterByInUse(boolean filterByInUse) {
this.filterByInUse = filterByInUse;
return this;
}

public FindRegularStopsByBoundingBoxRequest build() {
return new FindRegularStopsByBoundingBoxRequest(envelope, feedId, filterByInUse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TripOnServiceDateRequest {
private final FilterValues<String> netexInternalPlanningCodes;
private final FilterValues<TripAlteration> alterations;

protected TripOnServiceDateRequest(
TripOnServiceDateRequest(
RequiredFilterValues<LocalDate> serviceDates,
FilterValues<FeedScopedId> agencies,
FilterValues<FeedScopedId> routes,
Expand All @@ -41,7 +41,7 @@ protected TripOnServiceDateRequest(
this.alterations = alterations;
}

public static TripOnServiceDateRequestBuilder of(RequiredFilterValues serviceDates) {
public static TripOnServiceDateRequestBuilder of(RequiredFilterValues<LocalDate> serviceDates) {
return new TripOnServiceDateRequestBuilder(serviceDates);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public class TripOnServiceDateRequestBuilder {
"alterations",
List.of()
);
private RequiredFilterValues<LocalDate> serviceDates;
private final RequiredFilterValues<LocalDate> serviceDates;

protected TripOnServiceDateRequestBuilder(RequiredFilterValues serviceDates) {
TripOnServiceDateRequestBuilder(RequiredFilterValues<LocalDate> serviceDates) {
this.serviceDates = serviceDates;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class TripRequest {
private final FilterValues<String> netexInternalPlanningCodes;
private final FilterValues<LocalDate> serviceDates;

protected TripRequest(
TripRequest(
FilterValues<FeedScopedId> agencies,
FilterValues<FeedScopedId> routes,
FilterValues<String> netexInternalPlanningCodes,
Expand Down
Loading

0 comments on commit 665a2d2

Please sign in to comment.