From 410257c276439bba577239291f7d316383c4eab0 Mon Sep 17 00:00:00 2001 From: neon_arch Date: Sat, 2 Sep 2023 17:48:27 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20implement=20new=20fields,?= =?UTF-8?q?=20traits=20and=20functions=20(#201)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/results/aggregation_models.rs | 37 +++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/results/aggregation_models.rs b/src/results/aggregation_models.rs index e985765..ec7971c 100644 --- a/src/results/aggregation_models.rs +++ b/src/results/aggregation_models.rs @@ -102,13 +102,15 @@ impl EngineErrorInfo { /// and the type of error that caused it. /// * `empty_result_set` - Stores a boolean which indicates that no engines gave a result for the /// given search query. -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, Default)] #[serde(rename_all = "camelCase")] pub struct SearchResults { pub results: Vec, pub page_query: String, pub style: Style, pub engine_errors_info: Vec, + pub disallowed: bool, + pub filtered: bool, } impl SearchResults { @@ -122,6 +124,7 @@ impl SearchResults { /// the search url. /// * `empty_result_set` - Takes a boolean which indicates that no engines gave a result for the /// given search query. + /// * `` pub fn new( results: Vec, page_query: String, @@ -130,13 +133,39 @@ impl SearchResults { SearchResults { results, page_query, - style: Style::new("".to_string(), "".to_string()), + style: Style::default(), engine_errors_info, + disallowed: Default::default(), + filtered: Default::default(), } } /// A setter function to add website style to the return search results. - pub fn add_style(&mut self, style: Style) { - self.style = style; + pub fn add_style(&mut self, style: &Style) { + self.style = style.clone(); + } + + /// A setter function that sets disallowed to true. + pub fn set_disallowed(&mut self) { + self.disallowed = true; + } + + /// A setter function to set the current page search query. + pub fn set_page_query(&mut self, page: &str) { + self.page_query = page.to_owned(); + } + + /// A setter function that sets the filtered to true. + pub fn set_filtered(&mut self) { + self.filtered = true; + } + + /// A getter function that gets the value of `engine_errors_info`. + pub fn engine_errors_info(&mut self) -> Vec { + std::mem::take(&mut self.engine_errors_info) + } + /// A getter function that gets the value of `results`. + pub fn results(&mut self) -> Vec { + self.results.clone() } }