web search done right
don't spellcheck non-alphabetic words
Mikkel Denker02c799c51b3c
diff --git a/src/spell/spell_checker.rs b/src/spell/spell_checker.rsindex 389ac72a..a826a613 100644--- a/src/spell/spell_checker.rs+++ b/src/spell/spell_checker.rs@@ -33,6 +33,10 @@ impl<'a, T: EditStrategy, const DICT_N: usize> SpellChecker<'a, T, DICT_N> {pub fn correct_top(&self, term: &str, top_n: usize) -> Vec<String> {let mut res = Vec::new();+ if term.chars().any(|c| !c.is_alphabetic()) {+ return Vec::new();+ }+// this is sorted by increasing edit distancefor corrections in self.dict@@ -167,4 +171,22 @@ mod tests {vec!["the".to_string(), "he".to_string()]);}++ #[test]+ fn dont_correct_non_alphabet() {+ let mut dict = Dictionary::default();++ dict.insert("this");+ dict.insert("is");+ dict.insert("a");+ dict.insert("test");+ dict.insert("c");++ dict.commit().unwrap();++ let spell_checker = SpellChecker::new(&dict, MaxEdit::new(1));++ assert_eq!(spell_checker.correct("c++"), None);+ assert_eq!(spell_checker.correct("c#"), None);+ }}