partly ignore "Bahnhof " prefix added by bahnhof.de for user-input searches
This commit is contained in:
parent
b4d7481063
commit
a475248823
@ -202,7 +202,7 @@ impl Game {
|
|||||||
}) {
|
}) {
|
||||||
Ok(act?)
|
Ok(act?)
|
||||||
} else {
|
} else {
|
||||||
Err("no such station".into())
|
Err(format!("no such station ({location})").into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,6 +257,7 @@ impl StationsList {
|
|||||||
pub fn find_stations(&self, name: &str) -> Vec<(String, String)> {
|
pub fn find_stations(&self, name: &str) -> Vec<(String, String)> {
|
||||||
let stations = self.stations.blocking_lock();
|
let stations = self.stations.blocking_lock();
|
||||||
let name = name.to_lowercase();
|
let name = name.to_lowercase();
|
||||||
|
let name2 = format!("bahnhof {}", name);
|
||||||
if let Some(s) = stations.get(&name).and_then(|v| v.station.as_ref()) {
|
if let Some(s) = stations.get(&name).and_then(|v| v.station.as_ref()) {
|
||||||
vec![(name.to_owned(), s.name.clone())]
|
vec![(name.to_owned(), s.name.clone())]
|
||||||
} else {
|
} else {
|
||||||
@ -271,22 +272,50 @@ impl StationsList {
|
|||||||
if o.len() < 3 {
|
if o.len() < 3 {
|
||||||
for (id, station) in stations.iter() {
|
for (id, station) in stations.iter() {
|
||||||
if let Some(station) = &station.station {
|
if let Some(station) = &station.station {
|
||||||
if station.name.to_lowercase().starts_with(&name) {
|
if station.name.to_lowercase() == name2 {
|
||||||
o.insert(
|
o.insert(id.clone(), (station.name.clone(), 1));
|
||||||
id.clone(),
|
|
||||||
(
|
|
||||||
station.name.clone(),
|
|
||||||
station.name.len().saturating_sub(name.len()).min(100),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if o.len() < 3 {
|
if o.len() < 3 {
|
||||||
for (id, station) in stations.iter() {
|
for (id, station) in stations.iter() {
|
||||||
if let Some(station) = &station.station {
|
if let Some(station) = &station.station {
|
||||||
if let Some(pos) = station.name.to_lowercase().find(&name) {
|
if station.name.to_lowercase().starts_with(&name) {
|
||||||
o.insert(id.clone(), (station.name.clone(), (100 + pos).min(200)));
|
o.insert(
|
||||||
|
id.clone(),
|
||||||
|
(
|
||||||
|
station.name.clone(),
|
||||||
|
100 + station
|
||||||
|
.name
|
||||||
|
.len()
|
||||||
|
.saturating_sub(name.len())
|
||||||
|
.min(100),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else if station.name.to_lowercase().starts_with(&name2) {
|
||||||
|
o.insert(
|
||||||
|
id.clone(),
|
||||||
|
(
|
||||||
|
station.name.clone(),
|
||||||
|
100 + station
|
||||||
|
.name
|
||||||
|
.len()
|
||||||
|
.saturating_sub(name2.len())
|
||||||
|
.min(100),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if o.len() < 3 {
|
||||||
|
for (id, station) in stations.iter() {
|
||||||
|
if let Some(station) = &station.station {
|
||||||
|
if let Some(pos) = station.name.to_lowercase().find(&name) {
|
||||||
|
o.insert(
|
||||||
|
id.clone(),
|
||||||
|
(station.name.clone(), 200 + pos.min(100)),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user