search.rs
Language Rust691 B19 lines
/// Turn what a person typed into a safe FTS5 query: every word quoted (so/// operators and punctuation cannot cause syntax errors) and the last word a/// prefix match, so results appear while typing.pub fn fts_query(input: &str) -> Option<String> {let words: Vec<String> = input.split(|c: char| !(c.is_alphanumeric() || c == '_' || c == '\'')).map(|w| w.trim_matches('\'')).filter(|w| !w.is_empty()).map(|w| format!("\"{}\"", w.replace('"', ""))).collect();let (last, rest) = words.split_last()?;let mut q = rest.join(" ");if !q.is_empty() {q.push(' ');}q.push_str(last);q.push('*');Some(q)}