diff --git a/src/search_results_handler/aggregation_models.rs b/src/search_results_handler/aggregation_models.rs index b6e6b81..31a43c2 100644 --- a/src/search_results_handler/aggregation_models.rs +++ b/src/search_results_handler/aggregation_models.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; -use crate::config_parser::parser_models::Style; +use crate::{config_parser::parser_models::Style, engines::engine_models::EngineError}; /// A named struct to store, serialize and deserializes the individual search result from all the /// scraped and aggregated search results from the upstream search engines. @@ -16,7 +16,7 @@ use crate::config_parser::parser_models::Style; /// * `url` - The url to be displayed below the search result title in html. /// * `description` - The description of the search result. /// * `engine` - The names of the upstream engines from which this results were provided. -#[derive(Debug, Serialize, Deserialize)] +#[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct SearchResult { pub title: String, @@ -116,6 +116,25 @@ impl RawSearchResult { } } +#[derive(Serialize, Deserialize)] +pub struct EngineErrorInfo { + pub error: String, + pub engine: String, +} + +impl EngineErrorInfo { + pub fn new(error: &EngineError, engine: String) -> Self { + Self { + error: match error { + EngineError::RequestError => String::from("RequestError"), + EngineError::EmptyResultSet => String::from("EmptyResultSet"), + EngineError::UnexpectedError => String::from("UnexpectedError"), + }, + engine, + } + } +} + /// A named struct to store, serialize, deserialize the all the search results scraped and /// aggregated from the upstream search engines. /// @@ -130,6 +149,8 @@ pub struct SearchResults { pub results: Vec, pub page_query: String, pub style: Style, + pub engine_errors_info: Vec, + pub empty_result_set: bool, } impl SearchResults { @@ -141,15 +162,29 @@ impl SearchResults { /// and stores it into a vector of `SearchResult` structs. /// * `page_query` - Takes an argument of current page`s search query `q` provided in /// the search url. - pub fn new(results: Vec, page_query: String) -> Self { + pub fn new( + results: Vec, + page_query: String, + engine_errors_info: Vec, + ) -> Self { SearchResults { results, page_query, style: Style::new("".to_string(), "".to_string()), + engine_errors_info, + empty_result_set: false, } } pub fn add_style(&mut self, style: Style) { self.style = style; } + + pub fn is_empty_result_set(&self) -> bool { + self.results.is_empty() + } + + pub fn set_empty_result_set(&mut self) { + self.empty_result_set = true; + } }