neon_arch commited on
Commit
d6463f0
1 Parent(s): 8eeaf19

✨ feat: add condition to filter results only when safe_search level is

Browse files
Files changed (1) hide show
  1. src/results/aggregator.rs +23 -14
src/results/aggregator.rs CHANGED
@@ -70,6 +70,7 @@ pub async fn aggregate(
70
  debug: bool,
71
  upstream_search_engines: Vec<EngineHandler>,
72
  request_timeout: u8,
 
73
  ) -> Result<SearchResults, Box<dyn std::error::Error>> {
74
  let user_agent: String = random_user_agent();
75
 
@@ -92,7 +93,13 @@ pub async fn aggregate(
92
  let user_agent: String = user_agent.clone();
93
  tasks.push(tokio::spawn(async move {
94
  search_engine
95
- .results(query, page, user_agent.clone(), request_timeout)
 
 
 
 
 
 
96
  .await
97
  }));
98
  }
@@ -151,20 +158,22 @@ pub async fn aggregate(
151
  }
152
  }
153
 
154
- let mut blacklist_map: HashMap<String, SearchResult> = HashMap::new();
155
- filter_with_lists(
156
- &mut result_map,
157
- &mut blacklist_map,
158
- &file_path(FileType::BlockList)?,
159
- )?;
 
160
 
161
- filter_with_lists(
162
- &mut blacklist_map,
163
- &mut result_map,
164
- &file_path(FileType::AllowList)?,
165
- )?;
166
 
167
- drop(blacklist_map);
 
168
 
169
  let results: Vec<SearchResult> = result_map.into_values().collect();
170
 
@@ -194,7 +203,7 @@ pub fn filter_with_lists(
194
  let mut reader = BufReader::new(File::open(file_path)?);
195
 
196
  for line in reader.by_ref().lines() {
197
- let re = Regex::new(&line?)?;
198
 
199
  // Iterate over each search result in the map and check if it matches the regex pattern
200
  for (url, search_result) in map_to_be_filtered.clone().into_iter() {
 
70
  debug: bool,
71
  upstream_search_engines: Vec<EngineHandler>,
72
  request_timeout: u8,
73
+ safe_search: u8,
74
  ) -> Result<SearchResults, Box<dyn std::error::Error>> {
75
  let user_agent: String = random_user_agent();
76
 
 
93
  let user_agent: String = user_agent.clone();
94
  tasks.push(tokio::spawn(async move {
95
  search_engine
96
+ .results(
97
+ query,
98
+ page,
99
+ user_agent.clone(),
100
+ request_timeout,
101
+ safe_search,
102
+ )
103
  .await
104
  }));
105
  }
 
158
  }
159
  }
160
 
161
+ if safe_search >= 3 {
162
+ let mut blacklist_map: HashMap<String, SearchResult> = HashMap::new();
163
+ filter_with_lists(
164
+ &mut result_map,
165
+ &mut blacklist_map,
166
+ &file_path(FileType::BlockList)?,
167
+ )?;
168
 
169
+ filter_with_lists(
170
+ &mut blacklist_map,
171
+ &mut result_map,
172
+ &file_path(FileType::AllowList)?,
173
+ )?;
174
 
175
+ drop(blacklist_map);
176
+ }
177
 
178
  let results: Vec<SearchResult> = result_map.into_values().collect();
179
 
 
203
  let mut reader = BufReader::new(File::open(file_path)?);
204
 
205
  for line in reader.by_ref().lines() {
206
+ let re = Regex::new(line?.trim())?;
207
 
208
  // Iterate over each search result in the map and check if it matches the regex pattern
209
  for (url, search_result) in map_to_be_filtered.clone().into_iter() {