os_query_builder_rs/full_text/intervals/rules/
fuzzy.rs

1use serde::Serialize;
2use crate::misc::fuzziness::Fuzziness;
3
4#[derive(Debug, Default, Clone, Serialize)]
5pub struct FuzzyRule {
6    term: String,
7    #[serde(skip_serializing_if = "Option::is_none")]
8    analyzer: Option<String>,
9    #[serde(skip_serializing_if = "Option::is_none")]
10    fuzziness: Option<Fuzziness>,
11    #[serde(skip_serializing_if = "Option::is_none")]
12    transpositions: Option<bool>,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    prefix_length: Option<i64>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    use_field: Option<String>
17}
18
19
20impl FuzzyRule {
21    pub fn new() -> Self {
22        Self::default()
23    }
24
25    pub fn term<T: Into<String> + Serialize>(self, term: T) -> Self {
26        Self {
27            term: term.into(),
28            ..self
29        }
30    }
31
32    pub fn analyzer<T: Into<String> + Serialize>(self, analyzer: T) -> Self {
33        Self {
34            analyzer: Some(analyzer.into()),
35            ..self
36        }
37    }
38
39    pub fn fuzziness<T: Into<Fuzziness> + Serialize>(self, fuzziness: T) -> Self {
40        Self {
41            fuzziness: Some(fuzziness.into()),
42            ..self
43        }
44    }
45
46    pub fn transpositions<T: Into<bool> + Serialize>(self, transpositions: T) -> Self {
47        Self {
48            transpositions: Some(transpositions.into()),
49            ..self
50        }
51    }
52
53    pub fn prefix_length<T: Into<i64> + Serialize>(self, prefix_length: T) -> Self {
54        Self {
55            prefix_length: Some(prefix_length.into()),
56            ..self
57        }
58    }
59
60    pub fn use_field<T: Into<String> + Serialize>(self, use_field: T) -> Self {
61        Self {
62            use_field: Some(use_field.into()),
63            ..self
64        }
65    }
66}