Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/nearby-bus-stops.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ async fn get_nearby_bus_lines(&self, ref_lat: f64, ref_lon: f64) -> Result<Vec<L

## 注意事項

- バス路線検索は最大50件のバス停候補を取得し、その中から300m以内のものをフィルタリング
- バス路線検索は300m以内のバス停を近い順に見て、有効な路線を持つものを最大50件採用
- 鉄道駅の `lines` 配列に近傍バス路線が追加されるのは、未指定または `transportType: RailAndBus` の場合
2 changes: 1 addition & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ fn by_distance_then_station_cd(
/// 「上位 N 件」ではなく半径で切る用途 (駅の近傍バス停) 向け。最寄り N 件を
/// 作ってから半径で捨てると、採用されない駅の分まで組み立てることになる。
/// `nearest` と違い、路線を引けるかどうかは見ない (呼び出し側が
/// 件数を確定させてから路線で絞るため)。
/// 路線で絞ってから件数を確定させるため)。
pub fn within_radius(
lat: f64,
lon: f64,
Expand Down
30 changes: 14 additions & 16 deletions src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,9 @@ impl StationRepository for MemStationRepository {
.collect())
}

/// 各座標につき半径以内のバス停を近い順に N 件取り、そのあと有効な路線を
/// 持つものだけに絞る。先に路線で絞ると件数が変わるため、この順序を保つ。
/// 各座標につき半径以内のバス停を近い順に見て、有効な路線を持つものだけを
/// N 件まで採る。上限を先に掛けると、路線を引けないバス停や廃止路線の
/// バス停が枠を埋めたぶんだけ件数が減るため、絞り込みを先に行う。
/// 並びは指定された座標の順、その中では距離順。
async fn get_bus_stops_near_stations(
&self,
Expand All @@ -337,20 +338,17 @@ impl StationRepository for MemStationRepository {
let mut out = Vec::new();

for &(source_g_cd, lat, lon) in coords {
let mut hits = index::within_radius(lat, lon, radius_km, want);
hits.truncate(limit);
for (record, _distance) in hits {
let Some(line) = index::line_by_cd(record.line_cd) else {
continue;
};
if line.e_status != 0 {
continue;
}
let mut station = record.to_entity(Some(line));
station.line_group_cd = index::first_line_group_cd(record.station_cd);
station.has_train_types = station.line_group_cd.is_some();
out.push((source_g_cd, station));
}
let hits = index::within_radius(lat, lon, radius_km, want)
.into_iter()
.filter_map(|(record, _distance)| {
let line = index::line_by_cd(record.line_cd).filter(|l| l.e_status == 0)?;
let mut station = record.to_entity(Some(line));
station.line_group_cd = index::first_line_group_cd(record.station_cd);
station.has_train_types = station.line_group_cd.is_some();
Some((source_g_cd, station))
})
.take(limit);
out.extend(hits);
}
Ok(out)
}
Expand Down
Loading