finishing server side engine selection
This commit is contained in:
parent
e666316995
commit
0faf8c19a9
6 changed files with 32 additions and 27 deletions
|
@ -80,3 +80,18 @@ impl From<&Engines> for Vec<EngineHandler> {
|
|||
v
|
||||
}
|
||||
}
|
||||
|
||||
impl Engines {
|
||||
/// Returns a list of all engines
|
||||
pub fn list(&self) -> Box<[&'static str]> {
|
||||
Box::new([
|
||||
"duckduckgo",
|
||||
"searx",
|
||||
"brave",
|
||||
"startpage",
|
||||
"librex",
|
||||
"mojeek",
|
||||
"bing",
|
||||
])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
//! This module provides the error enum to handle different errors associated while requesting data from
|
||||
//! the upstream search engines with the search query provided by the user.
|
||||
|
||||
use crate::engines;
|
||||
|
||||
use super::aggregation_models::SearchResult;
|
||||
use error_stack::{Report, Result, ResultExt};
|
||||
use error_stack::{Result, ResultExt};
|
||||
use reqwest::Client;
|
||||
use std::{fmt, sync::Arc};
|
||||
|
||||
|
@ -152,6 +150,7 @@ pub trait SearchEngine: Sync + Send {
|
|||
}
|
||||
|
||||
/// A named struct which stores the engine struct with the name of the associated engine.
|
||||
#[derive(Clone)]
|
||||
pub struct EngineHandler {
|
||||
/// It stores the engine struct wrapped in a box smart pointer as the engine struct implements
|
||||
/// the `SearchEngine` trait.
|
||||
|
@ -160,15 +159,6 @@ pub struct EngineHandler {
|
|||
name: &'static str,
|
||||
}
|
||||
|
||||
impl Clone for EngineHandler {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
engine: self.engine.clone(),
|
||||
name: self.name.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl EngineHandler {
|
||||
/// Parses an engine name into an engine handler.
|
||||
///
|
||||
|
|
|
@ -70,7 +70,12 @@ pub async fn settings(
|
|||
&config.style.colorscheme,
|
||||
&config.style.theme,
|
||||
&config.style.animation,
|
||||
//&config.upstream_search_engines,
|
||||
&config
|
||||
.upstream_search_engines
|
||||
.list()
|
||||
.iter()
|
||||
.map(|n| (*n, true))
|
||||
.collect(),
|
||||
)?
|
||||
.0,
|
||||
))
|
||||
|
|
|
@ -5,14 +5,12 @@ use crate::{
|
|||
config::Config,
|
||||
engines::Engines,
|
||||
models::{
|
||||
aggregation_models::SearchResults,
|
||||
engine_models::EngineHandler,
|
||||
server_models::{self, SearchParams},
|
||||
aggregation_models::SearchResults, engine_models::EngineHandler,
|
||||
server_models::SearchParams,
|
||||
},
|
||||
results::aggregator::aggregate,
|
||||
};
|
||||
use actix_web::{get, http::header::ContentType, web, HttpRequest, HttpResponse};
|
||||
use std::borrow::Cow;
|
||||
use tokio::join;
|
||||
|
||||
/// Handles the route of search page of the `crabbysearch` meta search engine website and it takes
|
||||
|
@ -50,7 +48,8 @@ pub async fn search(
|
|||
// Get search settings using the user's cookie or from the server's config
|
||||
let search_settings: crate::engines::Engines = cookie
|
||||
.and_then(|cookie_value| serde_json::from_str(cookie_value.value()).ok())
|
||||
.unwrap();
|
||||
.inspect(|e| log::info!("{e:?}"))
|
||||
.unwrap_or_default();
|
||||
|
||||
// Closure wrapping the results function capturing local references
|
||||
let get_results = |page| results(config.clone(), cache.clone(), query, page, &search_settings);
|
||||
|
@ -149,7 +148,7 @@ async fn results(
|
|||
// default selected upstream search engines from the config file otherwise
|
||||
// parse the non-empty cookie and grab the user selected engines from the
|
||||
// UI and use that.
|
||||
let mut results: SearchResults = match true {
|
||||
let mut results: SearchResults = match false {
|
||||
false => aggregate(query, page, config, &Vec::<EngineHandler>::from(upstream)).await?,
|
||||
true => {
|
||||
let mut search_results = SearchResults::default();
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
//! A module that handles the engines tab for setting page view in the `crabbysearch` frontend.
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use maud::{html, Markup};
|
||||
|
||||
/// A functions that handles the html code for the engines tab for the settings page for the search page.
|
||||
|
@ -14,7 +12,7 @@ use maud::{html, Markup};
|
|||
/// # Returns
|
||||
///
|
||||
/// It returns the compiled html markup code for the engines tab.
|
||||
pub fn engines(engine_names: &HashMap<String, bool>) -> Markup {
|
||||
pub fn engines(engine_names: &Vec<(&str, bool)>) -> Markup {
|
||||
html!(
|
||||
div class="engines tab"{
|
||||
h1{"Engines"}
|
||||
|
@ -26,7 +24,7 @@ pub fn engines(engine_names: &HashMap<String, bool>) -> Markup {
|
|||
// Checks whether all the engines are selected or not if they are then the
|
||||
// checked `select_all` button is rendered otherwise the unchecked version
|
||||
// is rendered.
|
||||
@if engine_names.values().all(|selected| *selected){
|
||||
@if engine_names.iter().all(|selected| selected.1){
|
||||
.toggle_btn{
|
||||
label class="switch"{
|
||||
input type="checkbox" class="select_all" onchange="toggleAllSelection()" checked;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
//! A module that handles the view for the settings page in the `crabbysearch` frontend.
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use maud::{html, Markup};
|
||||
|
||||
use crate::templates::partials::{
|
||||
|
@ -28,7 +26,7 @@ pub fn settings(
|
|||
colorscheme: &str,
|
||||
theme: &str,
|
||||
animation: &Option<String>,
|
||||
//engine_names: &HashMap<String, bool>,
|
||||
engine_names: &Vec<(&'static str, bool)>,
|
||||
) -> Result<Markup, Box<dyn std::error::Error>> {
|
||||
Ok(html!(
|
||||
(header(colorscheme, theme, animation))
|
||||
|
@ -44,7 +42,7 @@ pub fn settings(
|
|||
}
|
||||
.main_container{
|
||||
(user_interface(theme, colorscheme, animation)?)
|
||||
//(engines(engine_names))
|
||||
(engines(&engine_names))
|
||||
(cookies())
|
||||
p class="message"{}
|
||||
button type="submit" onclick="setClientSettings()"{"Save"}
|
||||
|
|
Loading…
Add table
Reference in a new issue