Skip to content

Commit ac0610d

Browse files
Merge pull request opentripplanner#7339 from ibi-group/remove-flex-geocoder
Remove flex locations from geocoder
2 parents 38afeeb + fb4e79b commit ac0610d

2 files changed

Lines changed: 40 additions & 55 deletions

File tree

application/src/ext-test/java/org/opentripplanner/ext/geocoder/LuceneIndexTest.java

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package org.opentripplanner.ext.geocoder;
22

3+
import static com.google.common.truth.Truth.assertThat;
34
import static org.junit.jupiter.api.Assertions.assertEquals;
4-
import static org.opentripplanner.transit.model._data.TimetableRepositoryForTest.id;
5+
import static org.opentripplanner.transit.model._data.FeedScopedIdForTestFactory.id;
56
import static org.opentripplanner.transit.model.basic.TransitMode.BUS;
67
import static org.opentripplanner.transit.model.basic.TransitMode.FERRY;
78

@@ -17,6 +18,7 @@
1718
import org.junit.jupiter.api.Test;
1819
import org.junit.jupiter.params.ParameterizedTest;
1920
import org.junit.jupiter.params.provider.ValueSource;
21+
import org.opentripplanner._support.geometry.Polygons;
2022
import org.opentripplanner.core.model.id.FeedScopedId;
2123
import org.opentripplanner.ext.stopconsolidation.internal.DefaultStopConsolidationRepository;
2224
import org.opentripplanner.ext.stopconsolidation.internal.DefaultStopConsolidationService;
@@ -25,6 +27,7 @@
2527
import org.opentripplanner.transit.model.basic.TransitMode;
2628
import org.opentripplanner.transit.model.network.Route;
2729
import org.opentripplanner.transit.model.organization.Agency;
30+
import org.opentripplanner.transit.model.site.AreaStop;
2831
import org.opentripplanner.transit.model.site.RegularStop;
2932
import org.opentripplanner.transit.model.site.Station;
3033
import org.opentripplanner.transit.model.site.StopLocation;
@@ -35,63 +38,70 @@ class LuceneIndexTest {
3538

3639
private static final TimetableRepositoryForTest TEST_MODEL = TimetableRepositoryForTest.of();
3740

38-
static final Agency BVG = Agency.of(id("bvg"))
41+
private static final Agency BVG = Agency.of(id("bvg"))
3942
.withName("BVG")
4043
.withTimezone("Europe/Berlin")
4144
.build();
4245

4346
// Berlin
44-
static final Station BERLIN_HAUPTBAHNHOF_STATION = TEST_MODEL.station("Hauptbahnhof")
47+
private static final Station BERLIN_HAUPTBAHNHOF_STATION = TEST_MODEL.station("Hauptbahnhof")
4548
.withCoordinate(52.52495, 13.36952)
4649
.build();
47-
static final Station ALEXANDERPLATZ_STATION = TEST_MODEL.station("Alexanderplatz")
50+
private static final Station ALEXANDERPLATZ_STATION = TEST_MODEL.station("Alexanderplatz")
4851
.withCoordinate(52.52277, 13.41046)
4952
.build();
5053

51-
static final RegularStop ALEXANDERPLATZ_BUS = TEST_MODEL.stop("Alexanderplatz Bus")
54+
private static final RegularStop ALEXANDERPLATZ_BUS = TEST_MODEL.stop("Alexanderplatz Bus")
5255
.withCoordinate(52.52277, 13.41046)
5356
.withVehicleType(BUS)
5457
.withParentStation(ALEXANDERPLATZ_STATION)
5558
.build();
5659

57-
static final RegularStop ALEXANDERPLATZ_RAIL = TEST_MODEL.stop("Alexanderplatz S-Bahn")
60+
private static final RegularStop ALEXANDERPLATZ_RAIL = TEST_MODEL.stop("Alexanderplatz S-Bahn")
5861
.withCoordinate(52.52157, 13.41123)
5962
.withVehicleType(TransitMode.RAIL)
6063
.withParentStation(ALEXANDERPLATZ_STATION)
6164
.build();
62-
static final RegularStop LICHTERFELDE_OST_1 = TEST_MODEL.stop("Lichterfelde Ost")
65+
private static final RegularStop LICHTERFELDE_OST_1 = TEST_MODEL.stop("Lichterfelde Ost")
6366
.withId(id("lichterfelde-gleis-1"))
6467
.withCoordinate(52.42986, 13.32808)
6568
.build();
66-
static final RegularStop LICHTERFELDE_OST_2 = TEST_MODEL.stop("Lichterfelde Ost")
69+
private static final RegularStop LICHTERFELDE_OST_2 = TEST_MODEL.stop("Lichterfelde Ost")
6770
.withId(id("lichterfelde-gleis-2"))
6871
.withCoordinate(52.42985, 13.32807)
6972
.build();
70-
static final RegularStop WESTHAFEN = TEST_MODEL.stop("Westhafen")
73+
private static final RegularStop WESTHAFEN = TEST_MODEL.stop("Westhafen")
7174
.withVehicleType(null)
7275
.withCoordinate(52.42985, 13.32807)
7376
.build();
7477

7578
// Atlanta
76-
static final Station FIVE_POINTS_STATION = TEST_MODEL.station("Five Points")
79+
private static final Station FIVE_POINTS_STATION = TEST_MODEL.station("Five Points")
7780
.withCoordinate(33.753899, -84.39156)
7881
.build();
7982

80-
static final RegularStop ARTS_CENTER = TEST_MODEL.stop("Arts Center")
83+
private static final RegularStop ARTS_CENTER = TEST_MODEL.stop("Arts Center")
8184
.withCode("4456")
8285
.withCoordinate(52.52277, 13.41046)
8386
.build();
84-
static final RegularStop ARTHUR = TEST_MODEL.stop("Arthur Langford Jr Pl SW at 220")
87+
private static final RegularStop ARTHUR = TEST_MODEL.stop("Arthur Langford Jr Pl SW at 220")
8588
.withCoordinate(52.52277, 13.41046)
8689
.build();
8790

88-
static final RegularStop MERIDIAN_AVE = TEST_MODEL.stop("Meridian Ave N & N 148th St").build();
89-
static final RegularStop MERIDIAN_N1 = TEST_MODEL.stop("Meridian N & Spencer").build();
90-
static final RegularStop MERIDIAN_N2 = TEST_MODEL.stop("N 205th St & Meridian Ave N").build();
91+
private static final RegularStop MERIDIAN_AVE = TEST_MODEL.stop(
92+
"Meridian Ave N & N 148th St"
93+
).build();
94+
private static final RegularStop MERIDIAN_N1 = TEST_MODEL.stop("Meridian N & Spencer").build();
95+
private static final RegularStop MERIDIAN_N2 = TEST_MODEL.stop(
96+
"N 205th St & Meridian Ave N"
97+
).build();
9198

92-
static LuceneIndex index;
99+
private static final String FLEX_ZONE_NAME = "CCCCC";
100+
private static final AreaStop FLEX_ZONE = TEST_MODEL.areaStop(FLEX_ZONE_NAME)
101+
.withGeometry(Polygons.BERLIN)
102+
.build();
93103

94-
static StopClusterMapper mapper;
104+
private static LuceneIndex index;
95105

96106
@BeforeAll
97107
static void setup() {
@@ -108,6 +118,7 @@ static void setup() {
108118
MERIDIAN_N2,
109119
MERIDIAN_AVE
110120
).forEach(siteRepository::withRegularStop);
121+
siteRepository.withAreaStop(FLEX_ZONE);
111122
List.of(ALEXANDERPLATZ_STATION, BERLIN_HAUPTBAHNHOF_STATION, FIVE_POINTS_STATION).forEach(
112123
siteRepository::withStation
113124
);
@@ -161,7 +172,6 @@ public FeedInfo getFeedInfo(String feedId) {
161172
timetableRepository
162173
);
163174
index = new LuceneIndex(transitService, stopConsolidationService);
164-
mapper = new StopClusterMapper(transitService, stopConsolidationService);
165175
}
166176

167177
@Nested
@@ -257,6 +267,12 @@ void modes() {
257267
assertEquals(List.of(FERRY.name(), BUS.name()), cluster.primary().modes());
258268
}
259269

270+
@Test
271+
void skipFlexZones() {
272+
var result = index.queryStopClusters(FLEX_ZONE_NAME, null);
273+
assertThat(result).isEmpty();
274+
}
275+
260276
@Test
261277
void agenciesAndFeedPublisher() {
262278
var cluster = index.queryStopClusters("alexanderplatz", null).toList().getFirst();

application/src/ext/java/org/opentripplanner/ext/geocoder/LuceneIndex.java

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.io.Serializable;
77
import java.util.Arrays;
88
import java.util.Collection;
9-
import java.util.List;
109
import java.util.Map;
1110
import java.util.Objects;
1211
import java.util.Set;
@@ -49,12 +48,10 @@
4948
import org.opentripplanner.core.model.id.FeedScopedId;
5049
import org.opentripplanner.ext.stopconsolidation.StopConsolidationService;
5150
import org.opentripplanner.street.geometry.WgsCoordinate;
52-
import org.opentripplanner.transit.model.site.StopLocation;
53-
import org.opentripplanner.transit.model.site.StopLocationsGroup;
51+
import org.opentripplanner.transit.model.site.StopType;
5452
import org.opentripplanner.transit.service.DefaultTransitService;
5553
import org.opentripplanner.transit.service.TimetableRepository;
5654
import org.opentripplanner.transit.service.TransitService;
57-
import org.opentripplanner.utils.collection.ListUtils;
5855

5956
public class LuceneIndex implements Serializable {
6057

@@ -114,41 +111,13 @@ public LuceneIndex(
114111
iwcWithSuggestField(analyzer, Set.of(SUGGEST))
115112
)
116113
) {
117-
transitService
114+
var regularStops = transitService
118115
.listStopLocations()
119-
.forEach(stopLocation ->
120-
addToIndex(
121-
directoryWriter,
122-
StopLocation.class,
123-
stopLocation.getId().toString(),
124-
List.of(),
125-
ListUtils.ofNullable(stopLocation.getName()),
126-
ListUtils.ofNullable(stopLocation.getCode()),
127-
stopLocation.getCoordinate().latitude(),
128-
stopLocation.getCoordinate().longitude()
129-
)
130-
);
131-
132-
transitService
133-
.listStopLocationGroups()
134-
.forEach(stopLocationsGroup ->
135-
addToIndex(
136-
directoryWriter,
137-
StopLocationsGroup.class,
138-
stopLocationsGroup.getId().toString(),
139-
List.of(),
140-
ListUtils.ofNullable(stopLocationsGroup.getName()),
141-
List.of(),
142-
stopLocationsGroup.getCoordinate().latitude(),
143-
stopLocationsGroup.getCoordinate().longitude()
144-
)
145-
);
146-
116+
.stream()
117+
.filter(stopLocation -> stopLocation.getStopType() == StopType.REGULAR)
118+
.toList();
147119
stopClusterMapper
148-
.generateStopClusters(
149-
transitService.listStopLocations(),
150-
transitService.listStopLocationGroups()
151-
)
120+
.generateStopClusters(regularStops, transitService.listStopLocationGroups())
152121
.forEach(stopCluster ->
153122
addToIndex(
154123
directoryWriter,

0 commit comments

Comments
 (0)