1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
use crate::simple::{AutocompleteType, SearchIndex, SearchType};
use std::clone::Clone;
use std::cmp::Ord;
use std::collections::{BTreeMap, BTreeSet};
pub struct SearchIndexBuilder<K> {
b_tree_map: BTreeMap<String, BTreeSet<K>>,
search_type: SearchType,
autocomplete_type: AutocompleteType,
split_pattern: Option<Vec<char>>,
case_sensitive: bool,
minimum_keyword_length: usize,
maximum_keyword_length: usize,
maximum_string_length: Option<usize>,
exclude_keywords: Option<Vec<String>>,
maximum_autocomplete_options: usize,
maximum_search_results: usize,
maximum_keys_per_keyword: usize,
dump_keyword: Option<String>,
}
impl<K: Clone + Ord> From<SearchIndex<K>> for SearchIndexBuilder<K> {
fn from(search_index: SearchIndex<K>) -> Self {
SearchIndexBuilder {
b_tree_map: search_index.b_tree_map,
search_type: search_index.search_type,
autocomplete_type: search_index.autocomplete_type,
split_pattern: search_index.split_pattern,
case_sensitive: search_index.case_sensitive,
minimum_keyword_length: search_index.minimum_keyword_length,
maximum_keyword_length: search_index.maximum_keyword_length,
maximum_string_length: search_index.maximum_string_length,
exclude_keywords: search_index.exclude_keywords,
maximum_autocomplete_options: search_index.maximum_autocomplete_options,
maximum_search_results: search_index.maximum_search_results,
maximum_keys_per_keyword: search_index.maximum_keys_per_keyword,
dump_keyword: search_index.dump_keyword,
}
}
}
impl<K: Clone + Ord> From<&SearchIndexBuilder<K>> for SearchIndex<K> {
fn from(search_index: &SearchIndexBuilder<K>) -> Self {
SearchIndex {
b_tree_map: search_index.b_tree_map.clone(),
search_type: search_index.search_type.to_owned(),
autocomplete_type: search_index.autocomplete_type.to_owned(),
split_pattern: search_index.split_pattern.to_owned(),
case_sensitive: search_index.case_sensitive,
minimum_keyword_length: search_index.minimum_keyword_length,
maximum_keyword_length: search_index.maximum_keyword_length,
maximum_string_length: search_index.maximum_string_length,
exclude_keywords: search_index.exclude_keywords.clone(),
maximum_autocomplete_options: search_index.maximum_autocomplete_options,
maximum_search_results: search_index.maximum_search_results,
maximum_keys_per_keyword: search_index.maximum_keys_per_keyword,
dump_keyword: search_index.dump_keyword.to_owned(),
}
}
}
impl<K: Clone + Ord> SearchIndexBuilder<K> {
pub fn default() -> Self {
SearchIndexBuilder::from(SearchIndex::default())
}
pub fn search_type(&mut self, search_type: &SearchType) -> &mut Self {
self.search_type = search_type.to_owned();
self
}
pub fn autocomplete_type(&mut self, autocomplete_type: &AutocompleteType) -> &mut Self {
self.autocomplete_type = autocomplete_type.to_owned();
self
}
pub fn split_pattern(&mut self, split_pattern: &Option<Vec<char>>) -> &mut Self {
self.split_pattern = split_pattern.to_owned();
self
}
pub fn case_sensitive(&mut self, case_sensitive: &bool) -> &mut Self {
self.case_sensitive = *case_sensitive;
self
}
pub fn min_keyword_len(&mut self, minimum_keyword_length: &usize) -> &mut Self {
self.minimum_keyword_length = *minimum_keyword_length;
self
}
pub fn max_keyword_len(&mut self, maximum_keyword_length: &usize) -> &mut Self {
self.maximum_keyword_length = *maximum_keyword_length;
self
}
pub fn max_string_len(&mut self, maximum_string_length: &Option<usize>) -> &mut Self {
self.maximum_string_length = *maximum_string_length;
self
}
pub fn exclude_keywords(&mut self, exclude_keywords: &Option<Vec<String>>) -> &mut Self {
self.exclude_keywords = exclude_keywords.to_owned();
self
}
pub fn max_autocomplete_options(&mut self, maximum_autocomplete_options: &usize) -> &mut Self {
self.maximum_autocomplete_options = *maximum_autocomplete_options;
self
}
pub fn max_search_results(&mut self, maximum_search_results: &usize) -> &mut Self {
self.maximum_search_results = *maximum_search_results;
self
}
pub fn max_keys_per_keyword(&mut self, maximum_keys_per_keyword: &usize) -> &mut Self {
self.maximum_keys_per_keyword = *maximum_keys_per_keyword;
self
}
pub fn dump_keyword(&mut self, dump_keyword: &Option<String>) -> &mut Self {
self.dump_keyword = dump_keyword.to_owned();
self
}
pub fn build(&self) -> SearchIndex<K> {
SearchIndex::from(self)
}
}