search_hub

at b666653 Raw

use async_trait::async_trait;
use std::time::Duration;

use super::SearchEngine;

/// A fully configurable search engine defined by the user in config.
///
/// The user provides a URL template with `{}` placeholder, a CSS selector
/// for the result container, and a display name. Result extraction uses
/// the trait's default `parse_results` (finds container by selector,
/// extracts `<a href>` links, deduplicates, returns up to 10 results).
#[derive(Debug, Clone)]
pub struct Generic {
    pub name: String,
    pub url: String,
    pub selector: String,
    pub timeout_secs: Option<f32>,
}

#[async_trait]
impl SearchEngine for Generic {
    fn id(&self) -> &str {
        "generic"
    }

    fn name(&self) -> &str {
        &self.name
    }

    fn url_template(&self) -> &str {
        &self.url
    }

    fn selector(&self) -> &str {
        &self.selector
    }

    fn timeout(&self) -> Duration {
        self.timeout_secs
            .map(Duration::from_secs_f32)
            .unwrap_or(Duration::from_secs(5))
    }
}