a3s-search 1.0.0

Embeddable meta search engine library with CLI and proxy pool support
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# A3S Search

<p align="center">
  <strong>Embeddable Meta Search Engine</strong>
</p>

<p align="center">
  <em>Aggregate results from multiple engines with ranking and deduplication</em>
</p>

<p align="center">
  <a href="#features">Features</a><a href="#quick-start">Quick Start</a><a href="#sdks">SDKs</a><a href="#architecture">Architecture</a><a href="#api-reference">API Reference</a><a href="#development">Development</a>
</p>

---

## Overview

**A3S Search** is an embeddable meta search engine library. It aggregates results from multiple search engines, deduplicates them, and ranks them using a consensus-based scoring algorithm.

### Basic Usage

```rust
use a3s_search::{Search, SearchQuery, engines::{DuckDuckGo, Wikipedia}};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let mut search = Search::new();
    search.add_engine(DuckDuckGo::new());
    search.add_engine(Wikipedia::new());

    let query = SearchQuery::new("rust programming");
    let results = search.search(query).await?;

    for result in results.items().iter().take(10) {
        println!("{}: {}", result.title, result.url);
    }

    Ok(())
}
```

## Features

- **Multi-Engine Search**: Aggregate results from multiple engines in parallel
- **9 Built-in Engines**: DuckDuckGo, Brave, Bing, Wikipedia, Sogou, 360, Google, Baidu, Bing China
- **Result Deduplication**: Merge duplicate results based on normalized URLs
- **Consensus Ranking**: Results found by multiple engines rank higher
- **Async-First**: Built on Tokio for high-performance concurrent searches
- **Timeout Handling**: Per-engine timeout with graceful degradation
- **Extensible**: Add custom engines via the `Engine` trait
- **Dynamic Proxy Pool**: IP rotation with pluggable `ProxyProvider` trait
- **Health Monitor**: Automatic engine suspension after repeated failures
- **HCL Configuration**: Load settings from `.hcl` config files
- **Headless Browser**: Chrome and Lightpanda backends for JS-rendered engines
- **Auto-Download**: Automatically detects or downloads browsers
- **Native SDKs**: TypeScript (NAPI) and Python (PyO3) bindings

## Quick Start

### Installation

```toml
[dependencies]
a3s-search = "0.9"
tokio = { version = "1", features = ["full"] }
```

### Feature Flags

| Feature | Description |
|---------|-------------|
| `chromiumoxide` | Shared CDP client (required by chromium/lightpanda) |
| `chromium` | Chrome/Chromium headless backend |
| `lightpanda` | Lightpanda headless backend (Linux/macOS) |
| `all-headless` | Enable both chromium and lightpanda |

```toml
# Default (no headless engines)
a3s-search = "0.9"

# With Chrome/Chromium backend
a3s-search = { version = "0.9", features = ["chromium"] }

# With Lightpanda backend
a3s-search = { version = "0.9", features = ["lightpanda"] }

# With both backends
a3s-search = { version = "0.9", features = ["all-headless"] }
```

### Basic Search

```rust
use a3s_search::{Search, SearchQuery, engines::DuckDuckGo};

let mut search = Search::new();
search.add_engine(DuckDuckGo::new());

let query = SearchQuery::new("rust async");
let results = search.search(query).await?;
println!("Found {} results", results.count);
```

### Headless Browser Mode

Enable headless browser for JS-rendered engines (Google, Baidu, Bing China):

```rust
use a3s_search::{Search, SearchQuery};
use a3s_search::browser::{BrowserBackend, BrowserPool, BrowserPoolConfig};
use a3s_search::engines::{Google, DuckDuckGo};
use std::sync::Arc;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Enable headless mode with Chrome backend
    let mut search = Search::new();
    let pool = search.enable_headless(BrowserBackend::Chrome).await?;

    // Add engines
    search.add_engine(DuckDuckGo::new());
    search.add_engine(Google::new(pool.acquire_browser().await?));

    let results = search.search(SearchQuery::new("rust programming")).await?;
    println!("Found {} results", results.count);

    Ok(())
}
```

## CLI Usage

### Installation

**Homebrew (macOS):**
```bash
brew tap a3s-lab/tap https://github.com/A3S-Lab/homebrew-tap
brew install a3s-search
```

**Cargo:**
```bash
cargo install a3s-search
```

### Commands

```bash
# Basic search
a3s-search "rust programming"

# With specific engines
a3s-search "rust programming" -e ddg,wiki

# Limit results
a3s-search "rust programming" -l 5

# JSON output
a3s-search "rust programming" -f json

# Use proxy
a3s-search "rust programming" -p http://127.0.0.1:8080

# List available engines
a3s-search engines
```

### Available Engines

| Shortcut | Engine | Type |
|----------|--------|------|
| `ddg` | DuckDuckGo | HTTP |
| `brave` | Brave Search | HTTP |
| `bing` | Bing International | HTTP |
| `wiki` | Wikipedia | HTTP |
| `sogou` | 搜狗搜索 | HTTP |
| `360` | 360搜索 | HTTP |
| `g` | Google Search | Headless |
| `baidu` | 百度搜索 | Headless |
| `bing_cn` | 必应中国 | Headless |

## SDKs

Native bindings for TypeScript and Python, powered by NAPI-RS and PyO3.

### TypeScript (Node.js)

```bash
npm install @a3s-lab/search
```

```typescript
import { A3SSearch } from '@a3s-lab/search';

const search = new A3SSearch();

// Simple search
const response = await search.search('rust programming');

// With options
const response = await search.search('rust programming', {
  engines: ['ddg', 'wiki', 'brave', 'bing'],
  limit: 5,
  timeout: 15,
  proxy: 'http://127.0.0.1:8080',
});

for (const r of response.results) {
  console.log(`${r.title}: ${r.url}`);
}
```

### Python

```bash
pip install a3s-search
```

```python
from a3s_search import A3SSearch

search = A3SSearch()

# Simple search
response = search.search("rust programming")

# With options
response = search.search("rust programming",
    engines=["ddg", "wiki", "brave", "bing"],
    limit=5,
    timeout=15,
    proxy="http://127.0.0.1:8080",
)

for r in response.results:
    print(f"{r.title}: {r.url}")
```

### SDK Types

Both SDKs expose headless browser configuration types:

**TypeScript:**
```typescript
type BrowserBackend = "Chrome" | "Lightpanda"

interface HeadlessConfig {
  backend: BrowserBackend
  browserPath?: string
  maxTabs?: number
  launchArgs?: string[]
}

interface SearchConfig {
  timeout: number
  engines: Record<string, EngineConfig>
  headless?: HeadlessConfig
}
```

**Python:**
```python
class BrowserBackend:
    Chrome
    Lightpanda

class HeadlessConfig:
    def __init__(self, backend: BrowserBackend, browser_path: str = None,
                 max_tabs: int = None, launch_args: list = None)

class SearchConfig:
    def __init__(self, timeout: int, engines: dict = None,
                 headless: HeadlessConfig = None)
```

## Architecture

### System Overview

```
┌─────────────────────────────────────────────────────┐
│                      A3S Search                      │
├─────────────────────────────────────────────────────┤
│  ┌─────────┐    ┌─────────┐    ┌─────────┐        │
│  │ Rust    │    │ Python  │    │ Node.js │        │
│  │ Core    │◄───┤ SDK     │    │ SDK     │        │
│  └────┬────┘    └─────────┘    └─────────┘        │
│       │                                             │
│       ▼                                             │
│  ┌─────────────────────────────────────────────┐   │
│  │              Search Orchestrator              │   │
│  │  • Parallel execution (tokio::join_all)      │   │
│  │  • Timeout handling                           │   │
│  │  • Health monitoring                          │   │
│  └─────────────────────────────────────────────┘   │
│       │                                             │
│       ▼                                             │
│  ┌─────────────────────────────────────────────┐   │
│  │                 Engine Layer                  │   │
│  │  HTTP Engines: ddg, brave, bing, wiki, ...   │   │
│  │  Headless Engines: google, baidu, bing_cn     │   │
│  └─────────────────────────────────────────────┘   │
│       │                                             │
│       ▼                                             │
│  ┌─────────────────────────────────────────────┐   │
│  │               PageFetcher Layer               │   │
│  │  HttpFetcher │ PooledHttpFetcher │ Browser    │   │
│  └─────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────┘
```

### Core Components

| Component | Description |
|-----------|-------------|
| `Search` | Main orchestrator for parallel engine execution |
| `Engine` trait | Abstract interface for search engines |
| `PageFetcher` trait | Abstract interface for page fetching |
| `Aggregator` | URL deduplication and consensus ranking |
| `BrowserPool` | Shared headless browser process management |
| `ProxyPool` | Proxy rotation with auto-refresh |

## API Reference

### Search

```rust
pub struct Search { /* ... */ }

impl Search {
    /// Create a new search instance
    pub fn new() -> Self;

    /// Create with health monitoring
    pub fn with_health_config(config: HealthConfig) -> Self;

    /// Add a search engine
    pub fn add_engine<E: Engine + 'static>(&mut self, engine: E);

    /// Set default search timeout
    pub fn set_timeout(&mut self, timeout: Duration);

    /// Enable headless browser mode
    pub async fn enable_headless(&mut self, backend: BrowserBackend) -> Result<Arc<BrowserPool>>;

    /// Perform a search
    pub async fn search(&self, query: SearchQuery) -> Result<SearchResults>;
}
```

### BrowserBackend

```rust
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BrowserBackend {
    /// Chrome/Chromium headless
    Chrome,
    /// Lightpanda headless browser (Linux/macOS only)
    Lightpanda,
}

impl Default for BrowserBackend {
    fn default() -> Self {
        #[cfg(feature = "lightpanda")]
        { Self::Lightpanda }
        #[cfg(not(feature = "lightpanda"))]
        { Self::Chrome }
    }
}
```

### HeadlessConfig

```rust
pub struct HeadlessConfig {
    /// Which headless backend to use
    pub backend: BrowserBackend,
    /// Path to browser executable (auto-detected if None)
    pub browser_path: Option<String>,
    /// Maximum concurrent tabs (default: 4)
    pub max_tabs: usize,
    /// Additional launch arguments
    pub launch_args: Vec<String>,
}

impl Default for HeadlessConfig {
    fn default() -> Self {
        Self {
            backend: BrowserBackend::default(),
            browser_path: None,
            max_tabs: 4,
            launch_args: Vec::new(),
        }
    }
}
```

### SearchConfig (HCL)

```hcl
timeout = 10

health {
  max_failures    = 5
  suspend_seconds = 120
}

headless {
  backend     = "Chrome"  # or "Lightpanda"
  browser_path = null     # auto-detect
  max_tabs    = 4
  launch_args = []
}

engine "ddg" {
  enabled = true
  weight  = 1.0
}

engine "google" {
  enabled = true
  weight  = 1.0
}
```

### Engine Trait

```rust
#[async_trait]
pub trait Engine: Send + Sync {
    fn config(&self) -> &EngineConfig;
    async fn search(&self, query: &SearchQuery) -> Result<Vec<SearchResult>>;
}
```

## Development

### Build Commands

```bash
# Build default (all features)
cargo build -p a3s-search

# Build without headless
cargo build -p a3s-search --no-default-features

# Run tests
cargo test -p a3s-search --lib

# Format
cargo fmt -p a3s-search

# Clippy
cargo clippy -p a3s-search --no-default-features -- -D warnings
```

### Release

Releases are published to GitHub Releases with:
- CLI binaries (darwin-arm64, darwin-x86_64, linux-arm64, linux-x86_64)
- Python wheels (Python 3.9-3.13, many platforms)
- Node.js bindings (.node for multiple platforms)

```bash
# Create and push tag to trigger release
git tag v0.9.0
git push origin v0.9.0
```

## A3S Ecosystem

A3S Search is part of the A3S ecosystem:

```
a3s-box      - MicroVM sandbox
a3s-code     - AI coding agent
a3s-lane     - Queue
a3s-memory   - Memory
a3s-search   - Search
```

## License

MIT