From 81d44a0854f850cce15623e5afe7498ac86012c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Fri, 16 Aug 2019 12:17:23 +0200 Subject: [PATCH] feat: Order automatons by importance --- meilidb-core/src/query_builder.rs | 35 +++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/meilidb-core/src/query_builder.rs b/meilidb-core/src/query_builder.rs index 7c3183ff4..d88e293b7 100644 --- a/meilidb-core/src/query_builder.rs +++ b/meilidb-core/src/query_builder.rs @@ -2,7 +2,7 @@ use std::hash::Hash; use std::ops::Range; use std::rc::Rc; use std::time::Instant; -use std::{cmp, mem}; +use std::{mem, cmp, cmp::Reverse}; use fst::{Streamer, IntoStreamer}; use hashbrown::HashMap; @@ -24,30 +24,38 @@ use crate::{TmpMatch, Highlight, DocumentId, Store, RawDocument, Document}; const NGRAMS: usize = 3; struct Automaton { + index: usize, + ngram: usize, query_len: usize, is_exact: bool, dfa: DFA, } impl Automaton { - fn exact(query: &str) -> Automaton { + fn exact(index: usize, ngram: usize, query: &str) -> Automaton { Automaton { + index, + ngram, query_len: query.len(), is_exact: true, dfa: build_dfa(query), } } - fn prefix_exact(query: &str) -> Automaton { + fn prefix_exact(index: usize, ngram: usize, query: &str) -> Automaton { Automaton { + index, + ngram, query_len: query.len(), is_exact: true, dfa: build_prefix_dfa(query), } } - fn non_exact(query: &str) -> Automaton { + fn non_exact(index: usize, ngram: usize, query: &str) -> Automaton { Automaton { + index, + ngram, query_len: query.len(), is_exact: false, dfa: build_dfa(query), @@ -82,9 +90,9 @@ fn generate_automatons(query: &str, store: &S) -> Result<(Vec(query: &str, store: &S) -> Result<(Vec(query: &str, store: &S) -> Result<(Vec