feat: Process automatons in the order they were sort

This commit is contained in:
Clément Renault 2019-08-16 12:25:35 +02:00
parent 81d44a0854
commit bb0a79c577
No known key found for this signature in database
GPG Key ID: 0151CDAB43460DAE

View File

@ -319,27 +319,20 @@ where S: Store,
{ {
fn query_all(&self, query: &str) -> Result<Vec<RawDocument>, S::Error> { fn query_all(&self, query: &str) -> Result<Vec<RawDocument>, S::Error> {
let (automatons, query_enhancer) = generate_automatons(query, &self.store)?; let (automatons, query_enhancer) = generate_automatons(query, &self.store)?;
let words = self.store.words()?.as_fst(); let words = self.store.words()?;
let searchables = self.searchable_attrs.as_ref(); let searchables = self.searchable_attrs.as_ref();
let mut stream = {
let mut op_builder = fst::raw::OpBuilder::new();
for Automaton { dfa, .. } in &automatons {
let stream = words.search(dfa);
op_builder.push(stream);
}
op_builder.r#union()
};
let mut matches = Vec::new(); let mut matches = Vec::new();
let mut highlights = Vec::new(); let mut highlights = Vec::new();
let mut query_db = std::time::Duration::default(); let mut query_db = std::time::Duration::default();
let start = Instant::now(); let start = Instant::now();
while let Some((input, indexed_values)) = stream.next() {
for iv in indexed_values { for automaton in automatons {
let Automaton { index, is_exact, query_len, ref dfa, .. } = automatons[iv.index]; let Automaton { index, is_exact, query_len, dfa, .. } = automaton;
let mut stream = words.search(&dfa).into_stream();
while let Some(input) = stream.next() {
let distance = dfa.eval(input).to_u8(); let distance = dfa.eval(input).to_u8();
let is_exact = is_exact && distance == 0 && input.len() == query_len; let is_exact = is_exact && distance == 0 && input.len() == query_len;
@ -374,8 +367,8 @@ where S: Store,
} }
} }
} }
info!("main query all took {:.2?} (get indexes {:.2?})", start.elapsed(), query_db);
info!("main query all took {:.2?} (get indexes {:.2?})", start.elapsed(), query_db);
info!("{} total matches to rewrite", matches.len()); info!("{} total matches to rewrite", matches.len());
let start = Instant::now(); let start = Instant::now();