Expand description
§a3s-search
An embeddable meta search engine library inspired by SearXNG.
This library provides a framework for aggregating search results from multiple search engines, with support for:
- Async parallel search execution
- Result deduplication and merging
- Configurable ranking algorithms
- Extensible engine interface
- Dynamic proxy IP pool for anti-crawler protection
§Example
use a3s_search::{Search, SearchQuery, engines::DuckDuckGo};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let mut search = Search::new();
search.add_engine(DuckDuckGo::new());
let query = SearchQuery::new("rust programming");
let results = search.search(query).await?;
for result in results.items() {
println!("{}: {}", result.title, result.url);
}
Ok(())
}§Using Proxy
use a3s_search::{Search, SearchQuery, engines::DuckDuckGo, HttpFetcher, PageFetcher};
use std::sync::Arc;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let fetcher: Arc<dyn PageFetcher> = Arc::new(
HttpFetcher::with_proxy("http://proxy1.example.com:8080")?
);
let mut search = Search::new();
search.add_engine(DuckDuckGo::with_fetcher(
a3s_search::engines::DuckDuckGoParser, fetcher,
));
let query = SearchQuery::new("rust programming");
let results = search.search(query).await?;
Ok(())
}§Using Dynamic Proxy Pool
use std::sync::Arc;
use a3s_search::{Search, SearchQuery, PooledHttpFetcher, PageFetcher};
use a3s_search::engines::{DuckDuckGo, DuckDuckGoParser};
use a3s_search::proxy::{ProxyPool, ProxyProvider, ProxyConfig, spawn_auto_refresh};
// Implement your own provider to fetch proxies from any source
struct MyProxyProvider { /* ... */ }
#[async_trait::async_trait]
impl ProxyProvider for MyProxyProvider {
async fn fetch_proxies(&self) -> a3s_search::Result<Vec<ProxyConfig>> {
// Fetch from your proxy API, database, etc.
Ok(vec![ProxyConfig::new("10.0.0.1", 8080)])
}
fn refresh_interval(&self) -> std::time::Duration {
std::time::Duration::from_secs(60) // refresh every minute
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let pool = Arc::new(ProxyPool::with_provider(MyProxyProvider { /* ... */ }));
let _refresh_handle = spawn_auto_refresh(Arc::clone(&pool));
let fetcher: Arc<dyn PageFetcher> = Arc::new(PooledHttpFetcher::new(Arc::clone(&pool)));
let mut search = Search::new();
search.add_engine(DuckDuckGo::with_fetcher(DuckDuckGoParser, fetcher));
let query = SearchQuery::new("rust programming");
let results = search.search(query).await?;
Ok(())
}Modules§
Structs§
- Aggregator
- Aggregates and ranks search results from multiple engines.
- Engine
Config - Configuration for a search engine.
- Engine
Entry - Per-engine configuration entry.
- Health
Config - Configuration for the health monitor.
- Health
Entry - Health monitor configuration entry.
- Health
Monitor - Monitors engine health and auto-suspends failing engines.
- Html
Engine - Generic base for all HTML-scraping search engines.
- Http
Fetcher - A page fetcher that uses plain HTTP requests via reqwest.
- Pooled
Http Fetcher - A page fetcher that rotates proxies from a
ProxyPoolon each request. - Search
- Meta search engine that orchestrates searches across multiple engines.
- Search
Config - Top-level search configuration.
- Search
Query - A search query with all parameters.
- Search
Result - A single search result.
- Search
Results - Container for aggregated search results.
Enums§
- Engine
Category - Categories for search engines.
- Result
Type - Type of search result.
- Safe
Search - Safe search level.
- Search
Error - Errors that can occur during search operations.
- Time
Range - Time range filter for search results.
- Wait
Strategy - Strategy for waiting until a page is considered fully loaded.
Traits§
- Engine
- Trait for implementing search engines.
- Html
Parser - Engine-specific logic for HTML-scraping search engines.
- Page
Fetcher - Trait for fetching the full HTML content of a URL.
Functions§
- selector
- Parse a CSS selector string, returning a
SearchError::Parseon failure.
Type Aliases§
- Result
- Result type alias for search operations.