feat: Implement a better automaton builder

This new implementation only allows the last word of a query string to be a prefix.
This commit is contained in:
Clément Renault 2018-12-10 12:16:24 +01:00
parent 916b46c839
commit d8cfac914a
No known key found for this signature in database
GPG Key ID: 0151CDAB43460DAE

View File

@ -17,8 +17,12 @@ use crate::rank::Document;
fn split_whitespace_automatons(query: &str) -> Vec<DfaExt> { fn split_whitespace_automatons(query: &str) -> Vec<DfaExt> {
let mut automatons = Vec::new(); let mut automatons = Vec::new();
for query in query.split_whitespace().map(str::to_lowercase) { let mut words = query.split_whitespace().map(str::to_lowercase).peekable();
let lev = automaton::build_prefix_dfa(&query); while let Some(word) = words.next() {
let lev = match words.peek() {
Some(_) => automaton::build_dfa(&word),
None => automaton::build_prefix_dfa(&word),
};
automatons.push(lev); automatons.push(lev);
} }
automatons automatons