some more sanity improvements
This commit is contained in:
parent
05b6dfda86
commit
b0ed41ef70
6 changed files with 15 additions and 10 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -3674,7 +3674,6 @@ dependencies = [
|
||||||
"scraper",
|
"scraper",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tempfile",
|
|
||||||
"tokio 1.39.2",
|
"tokio 1.39.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -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 }
|
cfg-if = { version = "1.0.0", default-features = false, optional = true }
|
||||||
figment = { version = "0.10", features = ["env"] }
|
figment = { version = "0.10", features = ["env"] }
|
||||||
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
tempfile = { version = "3.10.1", default-features = false }
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
compress-cache-results = ["dep:async-compression", "dep:cfg-if"]
|
compress-cache-results = ["dep:async-compression", "dep:cfg-if"]
|
||||||
experimental-io-uring = ["actix-web/experimental-io-uring"]
|
experimental-io-uring = ["actix-web/experimental-io-uring"]
|
||||||
|
|
|
@ -67,7 +67,15 @@ impl Default for Config {
|
||||||
logging: true,
|
logging: true,
|
||||||
debug: false,
|
debug: false,
|
||||||
adaptive_window: 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,
|
request_timeout: 2,
|
||||||
tcp_connection_keep_alive: 10,
|
tcp_connection_keep_alive: 10,
|
||||||
pool_idle_connection_timeout: 30,
|
pool_idle_connection_timeout: 30,
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::config::Style;
|
||||||
pub struct SearchParams {
|
pub struct SearchParams {
|
||||||
/// It stores the search parameter option `q` (or query in simple words)
|
/// It stores the search parameter option `q` (or query in simple words)
|
||||||
/// of the search url.
|
/// of the search url.
|
||||||
pub query: Option<String>,
|
pub q: Option<String>,
|
||||||
/// It stores the search parameter `page` (or pageno in simple words)
|
/// It stores the search parameter `page` (or pageno in simple words)
|
||||||
/// of the search url.
|
/// of the search url.
|
||||||
pub page: Option<u32>,
|
pub page: Option<u32>,
|
||||||
|
|
|
@ -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))
|
Ok(SearchResults::new(results, &engine_errors_info))
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,13 +36,13 @@ pub async fn search(
|
||||||
) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
||||||
let params = web::Query::<SearchParams>::from_query(req.query_string())?;
|
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()
|
return Ok(HttpResponse::TemporaryRedirect()
|
||||||
.insert_header(("location", "/"))
|
.insert_header(("location", "/"))
|
||||||
.finish());
|
.finish());
|
||||||
}
|
}
|
||||||
|
|
||||||
let query = params.query.as_ref().unwrap();
|
let query = params.q.as_ref().unwrap().trim();
|
||||||
|
|
||||||
let cookie = req.cookie("appCookie");
|
let cookie = req.cookie("appCookie");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue