Appearance
Typesense Integration ​
File Information ​
- Path:
server/api/typesense/search.post.ts,app/composables/api/useSearchApi.ts - Purpose: Server-side Typesense search proxy and integration
Overview ​
Typesense is a fast, typo-tolerant search engine that powers the search functionality in the Brand Portal. This document covers the complete setup, configuration, and API integration for high-performance full-text search across digital assets, folders, and collages.
Architecture ​
System Components ​
- Typesense Server: Search engine server (self-hosted or cloud)
- Collections: Indexed data structures (digital_assets, folders, collages)
- Search API: Server-side proxy for Typesense operations
- Frontend Client: Search composables and components
- Search Store: Search state management
Key Features ​
1. Server-Side Search Proxy ​
- Secure search API endpoint
- Server-side Typesense API key (never exposed to client)
- Request validation
- Response transformation
- Error handling
2. Multi-Collection Search ​
- Search across multiple collections
- Collection filtering
- Unified search results
- Result aggregation
3. Advanced Filtering ​
- Tag filters
- File type filters
- Date range filters
- Custom field filters
- Workspace filtering
4. Sorting ​
- Sort by relevance (default)
- Sort by date (created, modified)
- Sort by file size
- Sort by file name
- Ascending/descending order
5. Pagination ​
- Page-based pagination
- Results per page configuration
- Total results count
- Last page detection
File Structure ​
Core Files ​
Server API Routes ​
server/api/typesense/search.post.ts- Typesense search proxy- Server-side search execution
- Typesense API key management
- Request validation
- Response transformation
- Error handling
server/api/typesense/utils.ts- Typesense utilities- Search query building
- Filter construction
- Response formatting
Composables ​
app/composables/api/useSearchApi.ts- Search API composable- Search execution
- Filter building
- Query construction
- Result processing
Stores ​
app/stores/search.ts- Search state management- Search query
- Active filters
- Search results
- Pagination state
Configuration ​
Environment Variables ​
bash
TYPESENSE_HOST=search.example.com
TYPESENSE_PORT=443
TYPESENSE_PROTOCOL=https
TYPESENSE_API_KEY=your-api-key
SEARCH_KEY=public-search-keyServer Configuration ​
typescript
// server/api/typesense/search.post.ts
const typesenseConfig = {
nodes: [{
host: process.env.TYPESENSE_HOST,
port: parseInt(process.env.TYPESENSE_PORT || '443'),
protocol: process.env.TYPESENSE_PROTOCOL || 'https'
}],
apiKey: process.env.TYPESENSE_API_KEY
}Search Flow ​
Search Execution ​
- User enters search query or applies filters
- Frontend builds search request
- Request sent to
/api/typesense/search - Server validates request
- Server calls Typesense API with secure key
- Typesense returns results
- Server transforms and returns results
- Frontend processes and displays results
Filter Building ​
- User selects filters (tags, file types, dates)
- Filters converted to Typesense filter_by syntax
- Filter query built
- Search executed with filters
- Results filtered accordingly
API Endpoints ​
Search ​
- Endpoint:
POST /api/typesense/search - Request:typescript
{ request: { q: string, // Search query collections: string[], // Collections to search sort_by: string // Sort expression }, filterQuery: object, // Collection filters commonSearchParams: { query_by: string, // Fields to search per_page: number, // Results per page page: number // Page number }, workspace_id_filter: string } - Response:typescript
{ digital_assets: { data: { hits: Asset[], found: number, page: number } } }
Security Features ​
- Server-Side API Key: Typesense API key never exposed to client
- Request Validation: All requests validated on server
- Workspace Filtering: Automatic workspace filtering
- Permission Checks: Search permissions validated
Performance Optimizations ​
- Server-Side Proxy: Reduces client-side complexity
- Caching: Search results can be cached
- Pagination: Efficient pagination prevents large result sets
- Filter Optimization: Optimized filter queries
Related Documentation ​
- Search & Discovery - Search feature documentation
- Search API - Typesense API endpoints
- Search Store - Search state management
- Search Components - Search UI components