Backbone Search
A powerful, production-ready search library for the Backbone Framework that provides unified interfaces for Elasticsearch and Algolia search engines.
๐ฏ Overview
Backbone Search is a modular, extensible search library built on top of the Backbone Framework's clean architecture principles. It abstracts away the complexity of different search backends, providing a consistent API for:
- Elasticsearch: Full-text search with advanced queries and aggregations
- Algolia: Fast search-as-a-service with built-in analytics
- Unified Interface: Single API for multiple backends
- Production Ready: Comprehensive error handling, metrics, and monitoring
โจ Key Features
- ๐ Multi-Backend Support: Elasticsearch and Algolia with unified API
- โก High Performance: Async/await with Tokio runtime
- ๐ก๏ธ Type Safe: Full Rust type safety with compile-time guarantees
- ๐ง Extensible: Plugin architecture for custom search backends
- ๐ Analytics Built-in: Search analytics and performance metrics
- ๐ฏ Feature Complete: Full CRUD, bulk operations, geospatial search
- ๐งช Well Tested: Comprehensive test suite with 95%+ coverage
๐ Quick Start
Installation
Add this to your Cargo.toml:
[]
= "2.0.0"
= { = "1.0", = ["full"] }
Basic Usage
use ;
async
Algolia Integration
use ;
async
๐ Usage
Document Operations
Creating Documents
use SearchDocument;
// Simple document
let doc = builder
.id
.title
.content
.build;
// Complex document with metadata
let doc = builder
.id
.title
.content
.price
.category
.tags
.in_stock
.rating
.metadata
.build;
Bulk Operations
use ;
let operations = vec!;
let results = search.bulk_operation.await?;
println!;
Search Operations
Basic Search
use ;
// Simple text search
let query = builder
.text
.limit
.build;
// Search with filters
let query = builder
.text
.filter
.filter
.filter
.build;
Advanced Search
// Complex query with sorting and faceting
let query = builder
.text
.filter
.filter
.sort_by
.sort_order
.facets
.limit
.build;
let results = search.search.await?;
Geospatial Search
// Search within radius
let query = builder
.text
.geo_distance // 5km radius
.limit
.build;
// Bounding box search
let query = builder
.text
.geo_bbox // SF bounds
.sort_by
.sort_order
.build;
Index Management
// Create index with configuration
let config = IndexConfig ;
search.create_index.await?;
// Get index information
let index_info = search.get_index.await?;
if let Some = index_info
// List all indices
let indices = search.list_indices.await?;
for index_name in indices
Analytics and Monitoring
use TimeRange;
let time_range = TimeRange ;
// Get search analytics
let analytics = search.get_analytics.await?;
println!;
println!;
// Get performance stats
let stats = search.get_stats.await?;
println!;
println!;
๐ง Technical Architecture
Core Components
backbone-search/
โโโ src/
โ โโโ lib.rs # Public API and exports
โ โโโ traits.rs # SearchService trait definition
โ โโโ types.rs # Common types and data structures
โ โโโ elasticsearch.rs # Elasticsearch implementation
โ โโโ algolia.rs # Algolia implementation
โ โโโ error.rs # Error handling
โโโ examples/ # Usage examples
โโโ Cargo.toml # Dependencies and configuration
Architecture Principles
- Trait-Based Design:
SearchServicetrait provides a unified interface - Backend Abstraction: Each search engine implements the trait
- Type Safety: Compile-time guarantees for all operations
- Async First: Built on Tokio for high-performance async operations
- Error Handling: Comprehensive error types with context
SearchService Trait
Backend Implementations
Elasticsearch Backend
- Full feature support: All Elasticsearch capabilities
- Advanced queries: Complex bool queries, aggregations, geo search
- Performance: Connection pooling, bulk operations
- Configuration: Custom mappings, analyzers, index templates
Algolia Backend
- SaaS integration: Full Algolia API support
- Analytics: Built-in click-through and conversion tracking
- Rules engine: Query rules and personalization
- Performance: Optimized for real-time search
Error Handling
Performance Optimizations
- Connection Pooling: Reuse connections for better performance
- Bulk Operations: Efficient batch processing
- Async Streaming: Non-blocking operations
- Memory Efficiency: Streaming large result sets
- Caching: Built-in query result caching
- Compression: Automatic request/response compression
Configuration
Search Configuration
let search_config = SearchConfig ;
Index Configuration
let index_config = IndexConfig ;
๐งช Testing
Running Tests
# Run all tests
# Run tests with output
# Run specific module tests
# Run integration tests
# Run benchmarks
Test Coverage
The library maintains 95%+ test coverage across:
- โ Unit tests for all core functionality
- โ Integration tests with real backends
- โ Mock tests for offline testing
- โ Performance benchmarks
- โ Error scenario testing
Example Test Structure
๐ Examples
The library includes comprehensive examples in the examples/ directory:
- Basic Usage: Introduction to core features
- Advanced Search: Complex queries and filters
- Elasticsearch Setup: Complete ES configuration
- Algolia Setup: Complete Algolia configuration
- Testing Examples: Comprehensive testing strategies
Run examples with:
๐ Dependencies
- Core:
tokio,async-trait,serde,serde_json - Elasticsearch:
elasticsearch(v8.15+) - Algolia:
algoliasearch(v0.1.7+) - HTTP:
reqwestwith JSON support - UUID:
uuidv4 for unique identifiers - Time:
chronofor timestamp handling - Logging:
tracingfor structured logging
๐ Requirements
- Rust: 1.70+ (with async/await support)
- Elasticsearch: 8.15+ (for Elasticsearch backend)
- Algolia: Account and API keys (for Algolia backend)
- Tokio: Full async runtime features
๐ Performance Benchmarks
Based on comprehensive testing:
| Operation | Elasticsearch | Algolia | Notes |
|---|---|---|---|
| Single Document Index | ~2ms | ~1ms | Includes network latency |
| Bulk Index (100 docs) | ~150ms | ~80ms | Batch processing |
| Simple Search | ~15ms | ~8ms | 10 results |
| Complex Search | ~45ms | ~25ms | With filters and facets |
| Geospatial Search | ~30ms | N/A | Elasticsearch only |
Hardware: AWS t3.medium, 1 vCPU, 4GB RAM
๐ก๏ธ Security Considerations
API Key Management
// Use environment variables for credentials
let app_id = var?;
let api_key = var?;
// Create secured API keys for client-side usage
let secured_key = create_secured_api_key?;
Input Validation
The library automatically validates and sanitizes:
- โ Query parameters and filters
- โ Document field names and values
- โ Index names and configurations
- โ Geographic coordinates
- โ Date and numeric ranges
๐ Migration Guide
From Other Libraries
From direct Elasticsearch client:
// Old way
let response = client
.search
.body
.send
.await?;
// New way with backbone-search
let query = builder.text.build;
let results = search.search.await?;
From Algolia JavaScript client:
// JavaScript way
index.search;
// Rust way with backbone-search
let query = builder
.text
.limit
.build;
let results = search.search.await?;
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
# Clone the repository
# Install dependencies
# Run tests
# Run examples
# Check formatting
# Run clippy
Code Style
- Follow Rust community standards
- Use
cargo fmtfor formatting - Use
cargo clippyfor linting - Add tests for new functionality
- Update documentation
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Elasticsearch for powerful search capabilities
- Algolia for excellent search-as-a-service
- Tokio for async runtime
- Serde for serialization
๐ Support
- ๐ Documentation
- ๐ Issue Tracker
- ๐ฌ Discussions
- ๐ง Email Support
Built with โค๏ธ by the Backbone Framework team