From b428cedd7a7b3d392c3232346752bb836b865236 Mon Sep 17 00:00:00 2001 From: neon_arch Date: Sat, 23 Sep 2023 12:48:01 +0300 Subject: [PATCH 1/7] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20new=20check=20val?= =?UTF-8?q?ue=20for=20no=20engine=20selected=20(#227)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/aggregation_models.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/models/aggregation_models.rs b/src/models/aggregation_models.rs index 656297f..72bbf08 100644 --- a/src/models/aggregation_models.rs +++ b/src/models/aggregation_models.rs @@ -122,6 +122,11 @@ pub struct SearchResults { /// search query was filtered when the safe search level set to 3 and it /// was present in the `Blocklist` file. pub filtered: bool, + /// Stores the safe search level `safesearch` provided in the search url. + pub safe_search_level: u8, + /// Stores the flag option which holds the check value that whether any search engines were + /// selected or not. + pub no_engines_selected: bool, } impl SearchResults { @@ -147,6 +152,8 @@ impl SearchResults { engine_errors_info: engine_errors_info.to_owned(), disallowed: Default::default(), filtered: Default::default(), + safe_search_level: Default::default(), + no_engines_selected: Default::default(), } } @@ -178,4 +185,19 @@ impl SearchResults { pub fn results(&mut self) -> Vec { self.results.clone() } + + /// A setter function to set the current page safe search level. + pub fn set_safe_search_level(&mut self, safe_search_level: u8) { + self.safe_search_level = safe_search_level; + } + + /// A getter function that gets the value of `no_engines_selected`. + pub fn no_engines_selected(&self) -> bool { + self.no_engines_selected + } + + /// A setter function to set the `no_engines_selected` to true. + pub fn set_no_engines_selected(&mut self) { + self.no_engines_selected = true; + } } From 173c6ba821321245d8acfef5d86bb2b251c1886e Mon Sep 17 00:00:00 2001 From: neon_arch Date: Sat, 23 Sep 2023 12:50:36 +0300 Subject: [PATCH 2/7] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20code=20to=20handl?= =?UTF-8?q?e=20aggregation=20when=20no=20engines=20are=20selected=20(#227)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/routes/search.rs | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/server/routes/search.rs b/src/server/routes/search.rs index dc327d6..e46d30c 100644 --- a/src/server/routes/search.rs +++ b/src/server/routes/search.rs @@ -195,16 +195,26 @@ async fn results( .filter_map(|name| EngineHandler::new(name)) .collect(); - aggregate( - query, - page, - config.aggregator.random_delay, - config.debug, - &engines, - config.request_timeout, - safe_search, - ) - .await? + match engines.is_empty() { + false => { + aggregate( + query, + page, + config.aggregator.random_delay, + config.debug, + &engines, + config.request_timeout, + safe_search, + ) + .await? + } + true => { + let mut search_results = SearchResults::default(); + search_results.set_no_engines_selected(); + search_results.set_page_query(query); + search_results + } + } } None => { aggregate( @@ -219,7 +229,10 @@ async fn results( .await? } }; - if results.engine_errors_info().is_empty() && results.results().is_empty() { + if results.engine_errors_info().is_empty() + && results.results().is_empty() + && !results.no_engines_selected() + { results.set_filtered(); } results.add_style(&config.style); From 69adc893d06a3a0c921a554399de0ac82ce845f6 Mon Sep 17 00:00:00 2001 From: neon_arch Date: Sat, 23 Sep 2023 12:53:18 +0300 Subject: [PATCH 3/7] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20new=20error=20mes?= =?UTF-8?q?sage=20to=20show=20when=20no=20engines=20are=20selected=20(#227?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/templates/search.html | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/public/templates/search.html b/public/templates/search.html index 8a79d69..513f122 100644 --- a/public/templates/search.html +++ b/public/templates/search.html @@ -45,6 +45,20 @@ Image of a paper inside a funnel + {{else}} {{#if noEnginesSelected}} +
+
+

+ No results could be fetched for your search "{{{this.pageQuery}}}" . +

+

Dear user,

+

+ No results could be retrieved from the upstream search engines as no + upstream search engines were selected from the settings page. +

+
+ Image of a white cross inside a red circle +
{{else}}

Your search - {{{this.pageQuery}}} - did not match any documents.

@@ -56,7 +70,7 @@ Man fishing gif
- {{/if}} {{/if}} {{/if}} + {{/if}} {{/if}} {{/if}} {{/if}}