some more sanity improvements

This commit is contained in:
Milim 2024-08-15 10:45:45 +02:00
parent 05b6dfda86
commit b0ed41ef70
No known key found for this signature in database
6 changed files with 15 additions and 10 deletions

1
Cargo.lock generated
View file

@ -3674,7 +3674,6 @@ dependencies = [
"scraper",
"serde",
"serde_json",
"tempfile",
"tokio 1.39.2",
]

View file

@ -51,10 +51,6 @@ async-compression = { version = "0.4.11", default-features = false, features = [
cfg-if = { version = "1.0.0", default-features = false, optional = true }
figment = { version = "0.10", features = ["env"] }
[dev-dependencies]
tempfile = { version = "3.10.1", default-features = false }
[features]
compress-cache-results = ["dep:async-compression", "dep:cfg-if"]
experimental-io-uring = ["actix-web/experimental-io-uring"]

View file

@ -67,7 +67,15 @@ impl Default for Config {
logging: true,
debug: false,
adaptive_window: false,
upstream_search_engines: vec!["bing".into(), "brave".into()],
upstream_search_engines: vec![
"bing".into(),
"brave".into(),
"duckduckgo".into(),
"librex".into(),
"mojeek".into(),
"searx".into(),
"startpage".into(),
],
request_timeout: 2,
tcp_connection_keep_alive: 10,
pool_idle_connection_timeout: 30,

View file

@ -11,7 +11,7 @@ use crate::config::Style;
pub struct SearchParams {
/// It stores the search parameter option `q` (or query in simple words)
/// of the search url.
pub query: Option<String>,
pub q: Option<String>,
/// It stores the search parameter `page` (or pageno in simple words)
/// of the search url.
pub page: Option<u32>,

View file

@ -147,7 +147,9 @@ pub async fn aggregate(
};
}
let results: Vec<SearchResult> = result_map.iter().map(|(_, value)| value.clone()).collect();
let mut results: Vec<SearchResult> =
result_map.iter().map(|(_, value)| value.clone()).collect();
results.sort_by(|a, b| a.description.len().cmp(&b.description.len()));
Ok(SearchResults::new(results, &engine_errors_info))
}

View file

@ -36,13 +36,13 @@ pub async fn search(
) -> Result<HttpResponse, Box<dyn std::error::Error>> {
let params = web::Query::<SearchParams>::from_query(req.query_string())?;
if !params.query.as_ref().is_some_and(|q| !q.trim().is_empty()) {
if params.q.as_ref().is_some_and(|q| q.trim().is_empty()) || params.q.is_none() {
return Ok(HttpResponse::TemporaryRedirect()
.insert_header(("location", "/"))
.finish());
}
let query = params.query.as_ref().unwrap();
let query = params.q.as_ref().unwrap().trim();
let cookie = req.cookie("appCookie");