0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-10-18 06:22:53 -04:00

♻️ refactor: remove the code to add the query & style in the SearchResults struct & also remove the associated fields from the struct (#302)

This commit is contained in:
neon_arch 2023-11-18 21:38:02 +03:00
parent 47905f1e22
commit 141ae26066

View File

@ -1,11 +1,10 @@
//! This module provides public models for handling, storing and serializing of search results //! This module provides public models for handling, storing and serializing of search results
//! data scraped from the upstream search engines. //! data scraped from the upstream search engines.
use super::engine_models::EngineError;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use smallvec::SmallVec; use smallvec::SmallVec;
use super::{engine_models::EngineError, parser_models::Style};
/// A named struct to store the raw scraped search results scraped search results from the /// A named struct to store the raw scraped search results scraped search results from the
/// upstream search engines before aggregating it.It derives the Clone trait which is needed /// upstream search engines before aggregating it.It derives the Clone trait which is needed
/// to write idiomatic rust using `Iterators`. /// to write idiomatic rust using `Iterators`.
@ -109,10 +108,6 @@ impl EngineErrorInfo {
pub struct SearchResults { pub struct SearchResults {
/// Stores the individual serializable `SearchResult` struct into a vector of /// Stores the individual serializable `SearchResult` struct into a vector of
pub results: Vec<SearchResult>, pub results: Vec<SearchResult>,
/// Stores the current pages search query `q` provided in the search url.
pub page_query: String,
/// Stores the theming options for the website.
pub style: Style,
/// Stores the information on which engines failed with their engine name /// Stores the information on which engines failed with their engine name
/// and the type of error that caused it. /// and the type of error that caused it.
pub engine_errors_info: Vec<EngineErrorInfo>, pub engine_errors_info: Vec<EngineErrorInfo>,
@ -142,15 +137,9 @@ impl SearchResults {
/// the search url. /// the search url.
/// * `engine_errors_info` - Takes an array of structs which contains information regarding /// * `engine_errors_info` - Takes an array of structs which contains information regarding
/// which engines failed with their names, reason and their severity color name. /// which engines failed with their names, reason and their severity color name.
pub fn new( pub fn new(results: Vec<SearchResult>, engine_errors_info: &[EngineErrorInfo]) -> Self {
results: Vec<SearchResult>,
page_query: &str,
engine_errors_info: &[EngineErrorInfo],
) -> Self {
Self { Self {
results, results,
page_query: page_query.to_owned(),
style: Style::default(),
engine_errors_info: engine_errors_info.to_owned(), engine_errors_info: engine_errors_info.to_owned(),
disallowed: Default::default(), disallowed: Default::default(),
filtered: Default::default(), filtered: Default::default(),
@ -159,21 +148,11 @@ impl SearchResults {
} }
} }
/// A setter function to add website style to the return search results.
pub fn add_style(&mut self, style: &Style) {
self.style = style.clone();
}
/// A setter function that sets disallowed to true. /// A setter function that sets disallowed to true.
pub fn set_disallowed(&mut self) { pub fn set_disallowed(&mut self) {
self.disallowed = true; 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. /// A setter function that sets the filtered to true.
pub fn set_filtered(&mut self) { pub fn set_filtered(&mut self) {
self.filtered = true; self.filtered = true;