mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-22 05:58:21 -05:00
✨ feat: add condition to filter results only when safe_search level is
set to 3 or above (#201)
This commit is contained in:
parent
8eeaf19cbd
commit
d6463f0872
@ -70,6 +70,7 @@ pub async fn aggregate(
|
|||||||
debug: bool,
|
debug: bool,
|
||||||
upstream_search_engines: Vec<EngineHandler>,
|
upstream_search_engines: Vec<EngineHandler>,
|
||||||
request_timeout: u8,
|
request_timeout: u8,
|
||||||
|
safe_search: u8,
|
||||||
) -> Result<SearchResults, Box<dyn std::error::Error>> {
|
) -> Result<SearchResults, Box<dyn std::error::Error>> {
|
||||||
let user_agent: String = random_user_agent();
|
let user_agent: String = random_user_agent();
|
||||||
|
|
||||||
@ -92,7 +93,13 @@ pub async fn aggregate(
|
|||||||
let user_agent: String = user_agent.clone();
|
let user_agent: String = user_agent.clone();
|
||||||
tasks.push(tokio::spawn(async move {
|
tasks.push(tokio::spawn(async move {
|
||||||
search_engine
|
search_engine
|
||||||
.results(query, page, user_agent.clone(), request_timeout)
|
.results(
|
||||||
|
query,
|
||||||
|
page,
|
||||||
|
user_agent.clone(),
|
||||||
|
request_timeout,
|
||||||
|
safe_search,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -151,6 +158,7 @@ pub async fn aggregate(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if safe_search >= 3 {
|
||||||
let mut blacklist_map: HashMap<String, SearchResult> = HashMap::new();
|
let mut blacklist_map: HashMap<String, SearchResult> = HashMap::new();
|
||||||
filter_with_lists(
|
filter_with_lists(
|
||||||
&mut result_map,
|
&mut result_map,
|
||||||
@ -165,6 +173,7 @@ pub async fn aggregate(
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
drop(blacklist_map);
|
drop(blacklist_map);
|
||||||
|
}
|
||||||
|
|
||||||
let results: Vec<SearchResult> = result_map.into_values().collect();
|
let results: Vec<SearchResult> = result_map.into_values().collect();
|
||||||
|
|
||||||
@ -194,7 +203,7 @@ pub fn filter_with_lists(
|
|||||||
let mut reader = BufReader::new(File::open(file_path)?);
|
let mut reader = BufReader::new(File::open(file_path)?);
|
||||||
|
|
||||||
for line in reader.by_ref().lines() {
|
for line in reader.by_ref().lines() {
|
||||||
let re = Regex::new(&line?)?;
|
let re = Regex::new(line?.trim())?;
|
||||||
|
|
||||||
// Iterate over each search result in the map and check if it matches the regex pattern
|
// Iterate over each search result in the map and check if it matches the regex pattern
|
||||||
for (url, search_result) in map_to_be_filtered.clone().into_iter() {
|
for (url, search_result) in map_to_be_filtered.clone().into_iter() {
|
||||||
|
Loading…
Reference in New Issue
Block a user