don't always search with marginalia

This commit is contained in:
mat 2024-01-02 22:33:13 -06:00
parent 02865265e3
commit 35b7b0a19d
2 changed files with 17 additions and 3 deletions

View File

@ -306,7 +306,13 @@ pub async fn search_with_engines(
start_time, start_time,
))?; ))?;
let response = engine.parse_response(&body)?; let response = match engine.parse_response(&body) {
Ok(response) => response,
Err(e) => {
eprintln!("parse error: {}", e);
EngineResponse::new()
}
};
progress_tx.send(ProgressUpdate::new( progress_tx.send(ProgressUpdate::new(
ProgressUpdateData::Engine { ProgressUpdateData::Engine {

View File

@ -1,11 +1,18 @@
use reqwest::Url; use reqwest::Url;
use crate::{ use crate::{
engines::{EngineResponse, CLIENT}, engines::{EngineResponse, RequestResponse, CLIENT},
parse::{parse_html_response_with_opts, ParseOpts}, parse::{parse_html_response_with_opts, ParseOpts},
}; };
pub fn request(query: &str) -> reqwest::RequestBuilder { pub fn request(query: &str) -> RequestResponse {
// if the query is more than 3 words or has any special characters then abort
if query.split_whitespace().count() > 3
|| !query.chars().all(|c| c.is_ascii_alphanumeric() || c == ' ')
{
return RequestResponse::None;
}
CLIENT CLIENT
.get( .get(
Url::parse_with_params( Url::parse_with_params(
@ -24,6 +31,7 @@ pub fn request(query: &str) -> reqwest::RequestBuilder {
"Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0", "Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0",
) )
.header("Accept-Language", "en-US,en;q=0.5") .header("Accept-Language", "en-US,en;q=0.5")
.into()
} }
pub fn parse_response(body: &str) -> eyre::Result<EngineResponse> { pub fn parse_response(body: &str) -> eyre::Result<EngineResponse> {