Expand description
§Search Engine Backend
A Rust-based search engine backend that integrates with Azure Cognitive Search and CosmosDB to provide web crawling, indexing, and search capabilities.
§Features
- Web Search: Full-text search across indexed web content
- Domain Indexing: Crawl and index web domains with robots.txt compliance
- Search Analytics: Track search queries, performance metrics, and usage patterns
- Azure Integration: Uses Azure Cognitive Search and CosmosDB for scalable storage
- REST API: Clean HTTP API for all operations
§Architecture
The application is structured around several key services:
SearchService
: Handles search operations via Azure Cognitive SearchStorageService
: Manages data persistence in Azure CosmosDBIndexerService
: Orchestrates web crawling and content indexingConfig
: Application configuration management
§Example Usage
use search_engine_backend::{Config, AppState, create_router, StorageService, SearchService, IndexerService};
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load configuration
let config = Arc::new(Config::from_env()?);
// Initialize services
let storage_service = Arc::new(StorageService::new(config.clone()).await?);
let search_service = Arc::new(SearchService::new(config.clone()).await?);
let indexer_service = Arc::new(IndexerService::new(
config.clone(),
storage_service.clone(),
search_service.clone()
).await?);
// Create application state
let app_state = AppState {
config,
search_service,
storage_service,
indexer_service,
};
// Create router and start server
let app = create_router(app_state);
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
axum::serve(listener, app).await?;
Ok(())
}
Modules§
Macros§
- log_
and_ capture - Macro to log and capture messages for the dashboard
Structs§
- AppState
- Application state containing all service instances and configuration.
- Args
- Command-line arguments for the Search Engine Backend application.
- Config
- Main application configuration structure.
- Force
Index Response - Response structure for force indexing operations.
- Force
Process Queue Response - Response structure for force queue processing operations.
- Index
Request - Request structure for indexing operations.
- Index
Response - Response structure for indexing operations.
- Indexer
Service - Search
Query - Query parameters for search requests.
- Search
Response - Response structure for search operations.
- Search
Result - Individual search result item.
- Search
Service - Search
Statistic - Represents search analytics and statistics data.
- Stats
Response - Response structure for search statistics.
- Storage
Service - Storage service for Azure CosmosDB operations.
- TopQueries
Response - Response structure for top search queries.
- TopQuery
- Individual top query item.
Functions§
- admin_
force_ index_ handler - HTTP handler for force indexing operations.
- admin_
force_ process_ queue_ handler - HTTP handler for force queue processing operations.
- admin_
stats_ handler - HTTP handler for retrieving search statistics.
- admin_
top_ queries_ handler - HTTP handler for retrieving top search queries.
- create_
router - Creates the main application router with all endpoints configured.
- default_
limit 🔒 - Default limit for search results when not specified.
- generate_
system_ 🔒activity_ log - Generates a system activity log for the statistics dashboard.
- health_
handler - HTTP handler for health check operations.
- index_
handler - HTTP handler for domain indexing operations.
- search_
handler - HTTP handler for search operations.
- stats_
page_ handler - HTTP handler for the statistics dashboard page.
- validate_
admin_ 🔒auth - Validates admin authentication from request headers.