diff --git a/milli/src/search/query_tree.rs b/milli/src/search/query_tree.rs
index 64babe053..87245ce20 100644
--- a/milli/src/search/query_tree.rs
+++ b/milli/src/search/query_tree.rs
@@ -157,6 +157,8 @@ trait Context {
pub struct QueryTreeBuilder<'a> {
rtxn: &'a heed::RoTxn<'a>,
index: &'a Index,
+ optional_words: bool,
+ authorize_typos: bool,
}
impl<'a> Context for QueryTreeBuilder<'a> {
@@ -177,7 +179,25 @@ impl<'a> QueryTreeBuilder<'a> {
/// Create a `QueryTreeBuilder` from a heed ReadOnly transaction `rtxn`
/// and an Index `index`.
pub fn new(rtxn: &'a heed::RoTxn<'a>, index: &'a Index) -> Self {
- Self { rtxn, index }
+ Self { rtxn, index, optional_words: true, authorize_typos: true }
+ }
+
+ /// if `optional_words` is set to `false` the query tree will be
+ /// generated forcing all query words to be present in each matching documents
+ /// (the criterion `words` will be ignored).
+ /// default value if not called: `true`
+ pub fn optional_words(&mut self, optional_words: bool) -> &mut Self {
+ self.optional_words = optional_words;
+ self
+ }
+
+ /// if `authorize_typos` is set to `false` the query tree will be generated
+ /// forcing all query words to match documents without any typo
+ /// (the criterion `typo` will be ignored).
+ /// default value if not called: `true`
+ pub fn authorize_typos(&mut self, authorize_typos: bool) -> &mut Self {
+ self.authorize_typos = authorize_typos;
+ self
}
/// Build the query tree:
@@ -187,16 +207,10 @@ impl<'a> QueryTreeBuilder<'a> {
/// - if `authorize_typos` is set to `false` the query tree will be generated
/// forcing all query words to match documents without any typo
/// (the criterion `typo` will be ignored)
- pub fn build(
- &self,
- optional_words: bool,
- authorize_typos: bool,
- query: TokenStream,
- ) -> anyhow::Result