reddb_server/storage/unified/dsl/builders/
text.rs1use std::sync::Arc;
6
7use crate::storage::query::unified::ExecutionError;
8
9use super::super::super::store::UnifiedStore;
10use super::super::execution::execute_text_query;
11use super::super::types::QueryResult;
12
13#[derive(Debug, Clone)]
15pub struct TextSearchBuilder {
16 pub(crate) query: String,
17 pub(crate) collections: Option<Vec<String>>,
18 pub(crate) fields: Option<Vec<String>>,
19 pub(crate) limit: Option<usize>,
20 pub(crate) fuzzy: bool,
21}
22
23impl TextSearchBuilder {
24 pub fn new(query: impl Into<String>) -> Self {
25 Self {
26 query: query.into(),
27 collections: None,
28 fields: None,
29 limit: None,
30 fuzzy: false,
31 }
32 }
33
34 pub fn in_collection(mut self, name: impl Into<String>) -> Self {
36 self.collections
37 .get_or_insert_with(Vec::new)
38 .push(name.into());
39 self
40 }
41
42 pub fn in_field(mut self, field: impl Into<String>) -> Self {
44 self.fields.get_or_insert_with(Vec::new).push(field.into());
45 self
46 }
47
48 pub fn fuzzy(mut self) -> Self {
50 self.fuzzy = true;
51 self
52 }
53
54 pub fn limit(mut self, n: usize) -> Self {
56 self.limit = Some(n);
57 self
58 }
59
60 pub fn execute(self, store: &Arc<UnifiedStore>) -> Result<QueryResult, ExecutionError> {
62 execute_text_query(self, store)
63 }
64}