use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchResult {
pub title: String,
pub url: String,
pub snippet: Option<String>,
}
pub trait SearchResultParser {
fn parse(&self, content: &str, max_results: usize) -> Vec<SearchResult>;
}
pub fn clean_url(url: &str) -> String {
if url.contains("duckduckgo.com/l/")
&& let Some(query) = url.split("uddg=").nth(1)
&& let Some(encoded) = query.split('&').next()
{
return urlencoding::decode(encoded).unwrap_or_default().into_owned();
}
url.to_string()
}
pub fn strip_html_tags(s: &str) -> String {
let re = regex::Regex::new(r"<[^>]*>").unwrap();
let without_tags = re.replace_all(s, "");
without_tags
.replace("&", "&")
.replace("<", "<")
.replace(">", ">")
.replace(""", "\"")
.replace("'", "'")
.replace(" ", " ")
.trim()
.to_string()
}