Small fixes

This commit is contained in:
Andras Schmelczer 2026-06-14 14:52:44 +01:00
parent 54fbcb1ea6
commit 083f8a982e
24 changed files with 1505 additions and 79 deletions

View file

@ -161,7 +161,7 @@ pub fn normalize_search_text(text: &str) -> String {
let mut last_was_space = true;
for ch in text.chars() {
if ch == '\'' || ch == '' || ch == '`' {
if super::is_apostrophe(ch) {
continue;
}
@ -769,6 +769,26 @@ impl PlaceData {
mod tests {
use super::*;
#[test]
fn normalize_search_text_elides_every_apostrophe_variant() {
// Whatever glyph the keyboard / autocorrect / paste produced for the apostrophe, the
// normalized form must be identical — otherwise "King's Cross" tokenizes as `king s cross`
// and matching breaks. See is_apostrophe for the full set.
let expected = "kings cross";
for q in [
"King's Cross", // U+0027 straight
"Kings Cross", // U+2019 right single quote
"Kings Cross", // U+2018 left single quote
"King´s Cross", // U+00B4 acute accent
"Kingʼs Cross", // U+02BC modifier letter apostrophe
"Kings Cross", // U+2032 prime
"King`s Cross", // U+0060 grave accent
"Kingʻs Cross", // U+02BB modifier letter turned comma
] {
assert_eq!(normalize_search_text(q), expected, "failed for {q:?}");
}
}
#[test]
fn place_index_tokens_dedup_and_min_length() {
// "a" is too short; aliases split on " | ".

View file

@ -37,7 +37,7 @@ fn tokenize_address_text(text: &str) -> Vec<String> {
for ch in text.chars() {
if ch.is_ascii_alphanumeric() {
current.push(ch.to_ascii_lowercase());
} else if matches!(ch, '\'' | '' | '`') {
} else if crate::data::is_apostrophe(ch) {
continue;
} else if !current.is_empty() {
tokens.push(std::mem::take(&mut current));
@ -784,6 +784,24 @@ impl PropertyData {
mod tests {
use super::*;
#[test]
fn tokenize_address_text_elides_every_apostrophe_variant() {
// The query and the index both run through this tokenizer, so any apostrophe glyph must
// join the word ("O'Brien" -> "obrien") rather than split it; otherwise the same address
// tokenizes differently depending on which quote glyph was typed.
let expected = vec!["obrien".to_string(), "road".to_string()];
for addr in [
"O'Brien Road", // U+0027 straight
"OBrien Road", // U+2019 right single quote
"OBrien Road", // U+2018 left single quote
"O´Brien Road", // U+00B4 acute accent
"OʼBrien Road", // U+02BC modifier letter apostrophe
"OBrien Road", // U+2032 prime
] {
assert_eq!(tokenize_address_text(addr), expected, "failed for {addr:?}");
}
}
#[test]
fn full_postcode_detection_accepts_common_formats() {
assert!(is_full_postcode_compact("SW1A1AA"));