APiGen Search Module
Full-text search integration module for APiGen applications. Provides a unified API for integrating with popular search engines including Elasticsearch, Algolia, Meilisearch, and Typesense.
Features
- Unified Search API: Single interface for all search operations regardless of the underlying provider
- Multiple Provider Support: Elasticsearch, Algolia, Meilisearch, Typesense
- Full-text Search: Query with filters, sorting, pagination, and highlighting
- Autocomplete: Type-ahead suggestions with fuzzy matching
- Faceted Search: Aggregations and facet computation for filtering UIs
- Document Indexing: Single and bulk document indexing operations
- Index Management: Create, delete, and manage search indices
- Auto-configuration: Spring Boot auto-configuration for zero-boilerplate setup
Configuration
Elasticsearch
yaml
apigen:
search:
enabled: true
elasticsearch:
enabled: true
hosts:
- http://localhost:9200Algolia
yaml
apigen:
search:
enabled: true
algolia:
enabled: true
application-id: YOUR_APP_ID
api-key: YOUR_API_KEYProvider Comparison
| Feature | Elasticsearch | Algolia | Meilisearch | Typesense |
|---|---|---|---|---|
| Self-hosted | ✓ | ✗ | ✓ | ✓ |
| Cloud offering | ✓ | ✓ | ✓ | ✓ |
| Full-text search | ✓ | ✓ | ✓ | ✓ |
| Faceted search | ✓ | ✓ | ✓ | ✓ |
| Autocomplete | ✓ | ✓ | ✓ | ✓ |
| Typo tolerance | ✓ | ✓ | ✓ | ✓ |
| Real-time indexing | ✓ | ✓ | ✓ | ✓ |
| Highlighting | ✓ | ✓ | ✓ | ✓ |
Usage
Performing a Search
java
@Autowired
private SearchService<Product> searchService;
public SearchResponse<Product> searchProducts(String query) {
SearchRequest request = SearchRequest.builder()
.indexName("products")
.query(query)
.page(0)
.size(20)
.searchFields(List.of("title", "description"))
.filters(Map.of("category", "electronics"))
.sortField("price")
.sortOrder("asc")
.highlightFields(List.of("title", "description"))
.build();
return searchService.search(request, Product.class);
}Autocomplete
java
public AutocompleteResponse getSuggestions(String prefix) {
AutocompleteRequest request = AutocompleteRequest.builder()
.indexName("products")
.prefix(prefix)
.maxSuggestions(10)
.fields(List.of("title", "brand"))
.fuzzy(true)
.build();
return searchService.autocomplete(request);
}