From 6fa45ecb129a8474c959be02b5db7d00975761c5 Mon Sep 17 00:00:00 2001 From: neon_arch Date: Sat, 2 Sep 2023 17:44:05 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20pass=20the=20config=20optio?= =?UTF-8?q?n=20into=20the=20results=20function=20(#201)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/engines/duckduckgo.rs | 1 + src/engines/searx.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/engines/duckduckgo.rs b/src/engines/duckduckgo.rs index 11b7d86..f5934e2 100644 --- a/src/engines/duckduckgo.rs +++ b/src/engines/duckduckgo.rs @@ -43,6 +43,7 @@ impl SearchEngine for DuckDuckGo { page: u32, user_agent: String, request_timeout: u8, + _safe_search: u8, ) -> Result, EngineError> { // Page number can be missing or empty string and so appropriate handling is required // so that upstream server recieves valid page number. diff --git a/src/engines/searx.rs b/src/engines/searx.rs index 4ad41f5..a9d615a 100644 --- a/src/engines/searx.rs +++ b/src/engines/searx.rs @@ -42,12 +42,21 @@ impl SearchEngine for Searx { page: u32, user_agent: String, request_timeout: u8, + mut safe_search: u8, ) -> Result, EngineError> { // Page number can be missing or empty string and so appropriate handling is required // so that upstream server recieves valid page number. + if safe_search == 3 { + safe_search = 2; + }; + let url: String = match page { - 0 | 1 => format!("https://searx.work/search?q={query}&pageno=1"), - _ => format!("https://searx.work/search?q={query}&pageno={page}"), + 0 | 1 => { + format!("https://searx.work/search?q={query}&pageno=1&safesearch={safe_search}") + } + _ => format!( + "https://searx.work/search?q={query}&pageno={page}&safesearch={safe_search}" + ), }; // initializing headers and adding appropriate headers.