neon_arch commited on
Commit
3aeb3b3
1 Parent(s): 9ee516e

✨ feat: add setter functions to SearchResults struct

Browse files
src/search_results_handler/aggregation_models.rs CHANGED
@@ -3,7 +3,7 @@
3
 
4
  use serde::{Deserialize, Serialize};
5
 
6
- use crate::config_parser::parser_models::Style;
7
 
8
  /// A named struct to store, serialize and deserializes the individual search result from all the
9
  /// scraped and aggregated search results from the upstream search engines.
@@ -16,7 +16,7 @@ use crate::config_parser::parser_models::Style;
16
  /// * `url` - The url to be displayed below the search result title in html.
17
  /// * `description` - The description of the search result.
18
  /// * `engine` - The names of the upstream engines from which this results were provided.
19
- #[derive(Debug, Serialize, Deserialize)]
20
  #[serde(rename_all = "camelCase")]
21
  pub struct SearchResult {
22
  pub title: String,
@@ -116,6 +116,25 @@ impl RawSearchResult {
116
  }
117
  }
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  /// A named struct to store, serialize, deserialize the all the search results scraped and
120
  /// aggregated from the upstream search engines.
121
  ///
@@ -130,6 +149,8 @@ pub struct SearchResults {
130
  pub results: Vec<SearchResult>,
131
  pub page_query: String,
132
  pub style: Style,
 
 
133
  }
134
 
135
  impl SearchResults {
@@ -141,15 +162,29 @@ impl SearchResults {
141
  /// and stores it into a vector of `SearchResult` structs.
142
  /// * `page_query` - Takes an argument of current page`s search query `q` provided in
143
  /// the search url.
144
- pub fn new(results: Vec<SearchResult>, page_query: String) -> Self {
 
 
 
 
145
  SearchResults {
146
  results,
147
  page_query,
148
  style: Style::new("".to_string(), "".to_string()),
 
 
149
  }
150
  }
151
 
152
  pub fn add_style(&mut self, style: Style) {
153
  self.style = style;
154
  }
 
 
 
 
 
 
 
 
155
  }
 
3
 
4
  use serde::{Deserialize, Serialize};
5
 
6
+ use crate::{config_parser::parser_models::Style, engines::engine_models::EngineError};
7
 
8
  /// A named struct to store, serialize and deserializes the individual search result from all the
9
  /// scraped and aggregated search results from the upstream search engines.
 
16
  /// * `url` - The url to be displayed below the search result title in html.
17
  /// * `description` - The description of the search result.
18
  /// * `engine` - The names of the upstream engines from which this results were provided.
19
+ #[derive(Serialize, Deserialize)]
20
  #[serde(rename_all = "camelCase")]
21
  pub struct SearchResult {
22
  pub title: String,
 
116
  }
117
  }
118
 
119
+ #[derive(Serialize, Deserialize)]
120
+ pub struct EngineErrorInfo {
121
+ pub error: String,
122
+ pub engine: String,
123
+ }
124
+
125
+ impl EngineErrorInfo {
126
+ pub fn new(error: &EngineError, engine: String) -> Self {
127
+ Self {
128
+ error: match error {
129
+ EngineError::RequestError => String::from("RequestError"),
130
+ EngineError::EmptyResultSet => String::from("EmptyResultSet"),
131
+ EngineError::UnexpectedError => String::from("UnexpectedError"),
132
+ },
133
+ engine,
134
+ }
135
+ }
136
+ }
137
+
138
  /// A named struct to store, serialize, deserialize the all the search results scraped and
139
  /// aggregated from the upstream search engines.
140
  ///
 
149
  pub results: Vec<SearchResult>,
150
  pub page_query: String,
151
  pub style: Style,
152
+ pub engine_errors_info: Vec<EngineErrorInfo>,
153
+ pub empty_result_set: bool,
154
  }
155
 
156
  impl SearchResults {
 
162
  /// and stores it into a vector of `SearchResult` structs.
163
  /// * `page_query` - Takes an argument of current page`s search query `q` provided in
164
  /// the search url.
165
+ pub fn new(
166
+ results: Vec<SearchResult>,
167
+ page_query: String,
168
+ engine_errors_info: Vec<EngineErrorInfo>,
169
+ ) -> Self {
170
  SearchResults {
171
  results,
172
  page_query,
173
  style: Style::new("".to_string(), "".to_string()),
174
+ engine_errors_info,
175
+ empty_result_set: false,
176
  }
177
  }
178
 
179
  pub fn add_style(&mut self, style: Style) {
180
  self.style = style;
181
  }
182
+
183
+ pub fn is_empty_result_set(&self) -> bool {
184
+ self.results.is_empty()
185
+ }
186
+
187
+ pub fn set_empty_result_set(&mut self) {
188
+ self.empty_result_set = true;
189
+ }
190
  }