Skip to content

Commit a5729c8

Browse files
committed
Sort the candidate edges by score before returning them from the API.
1 parent 7565254 commit a5729c8

File tree

1 file changed

+13
-5
lines changed
  • opentripplanner-api-thrift/src/main/java/org/opentripplanner/api/thrift/impl

1 file changed

+13
-5
lines changed

opentripplanner-api-thrift/src/main/java/org/opentripplanner/api/thrift/impl/OTPServiceImpl.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.ArrayList;
44
import java.util.Collection;
5+
import java.util.Collections;
56
import java.util.HashSet;
67
import java.util.List;
78
import java.util.Set;
@@ -24,6 +25,7 @@
2425
import org.opentripplanner.api.thrift.definition.GraphVertex;
2526
import org.opentripplanner.api.thrift.definition.GraphVerticesRequest;
2627
import org.opentripplanner.api.thrift.definition.GraphVerticesResponse;
28+
import org.opentripplanner.api.thrift.definition.Location;
2729
import org.opentripplanner.api.thrift.definition.OTPService;
2830
import org.opentripplanner.api.thrift.definition.PathOptions;
2931
import org.opentripplanner.api.thrift.definition.TripParameters;
@@ -44,6 +46,7 @@
4446
import org.opentripplanner.routing.graph.Graph;
4547
import org.opentripplanner.routing.graph.Vertex;
4648
import org.opentripplanner.routing.impl.CandidateEdge;
49+
import org.opentripplanner.routing.impl.CandidateEdge.CandidateEdgeScoreComparator;
4750
import org.opentripplanner.routing.impl.CandidateEdgeBundle;
4851
import org.opentripplanner.routing.services.GraphService;
4952
import org.opentripplanner.routing.services.PathService;
@@ -184,23 +187,28 @@ public FindNearestVertexResponse FindNearestVertex(FindNearestVertexRequest req)
184187

185188
@Override
186189
public FindNearestEdgesResponse FindNearestEdges(FindNearestEdgesRequest req) throws TException {
187-
LOG.info("FindNearestEdges called");
190+
LOG.info("FindNearestEdges called with query {}", req.getLocation());
188191
long startTime = System.currentTimeMillis();
189192

190193
// Set up the TraversalRequirements.
191194
TraversalRequirements requirements = new TraversalRequirements();
192195
requirements.setModes(new TravelModeSet(req.getAllowed_modes()).toTraverseModeSet());
193-
194-
// Set up the LocationObservation.
195-
GenericLocation loc = new LatLngExtension(req.getLocation().getLat_lng()).toGenericLocation();
196-
if (req.isSetHeading()) loc.setHeading(req.getHeading());
197196

197+
// Set up the LocationObservation.
198+
Location queryLoc = req.getLocation();
199+
GenericLocation loc = new LatLngExtension(queryLoc.getLat_lng()).toGenericLocation();
200+
if (queryLoc.isSetHeading()) loc.setHeading(queryLoc.getHeading());
201+
198202
// Find the candidate edges.
199203
// NOTE(flamholz): for now this will return at smallish number of edges because of
200204
// the internal binning that's going on. I'd rather get more edges just in case...
201205
StreetVertexIndexService streetVertexIndex = getStreetIndex();
202206
CandidateEdgeBundle edges = streetVertexIndex.getClosestEdges(loc, requirements);
203207

208+
// Sort them by score.
209+
CandidateEdgeScoreComparator comp = new CandidateEdgeScoreComparator();
210+
Collections.sort(edges, comp);
211+
204212
// Add matches to the response.
205213
FindNearestEdgesResponse res = new FindNearestEdgesResponse();
206214
int maxEdges = req.getMax_edges();

0 commit comments

Comments
 (0)