Search¶
Overview¶
Centrali's Search service provides fast, full-text search across all your structured data powered by Meilisearch. Search is automatically configured for all your structures and records.
Key Features¶
- Fast: Sub-50ms search responses
- Typo-tolerant: Finds results even with misspellings
- Ranking: Results ranked by relevance
- Filters: Combine search with structured filters
- Highlights: Matched terms highlighted in results
Basic Search¶
Search across all records in a structure:
curl -X GET "https://api.centrali.io/workspace/my-workspace/api/v1/structures/products/search?q=laptop" \
-H "Authorization: Bearer YOUR_TOKEN"
Response:
{
"hits": [
{
"id": "rec_abc123",
"name": "Gaming Laptop",
"description": "High-performance laptop for gaming",
"price": 1299.99,
"_formatted": {
"name": "Gaming <em>Laptop</em>",
"description": "High-performance <em>laptop</em> for gaming"
}
}
],
"estimatedTotalHits": 1,
"processingTimeMs": 12
}
Search with Filters¶
Combine full-text search with structured filters:
curl -X GET "https://api.centrali.io/workspace/my-workspace/api/v1/structures/products/search?q=laptop&filter=price<1000" \
-H "Authorization: Bearer YOUR_TOKEN"
Pagination¶
curl -X GET "https://api.centrali.io/workspace/my-workspace/api/v1/structures/products/search?q=laptop&limit=20&offset=0" \
-H "Authorization: Bearer YOUR_TOKEN"
Faceted Search¶
Get counts of matching documents by field values:
curl -X POST "https://api.centrali.io/workspace/my-workspace/api/v1/structures/products/search" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"q": "laptop",
"facets": ["category", "brand"]
}'
Response includes facet counts:
{
"hits": [...],
"facetDistribution": {
"category": {
"electronics": 45,
"computers": 32
},
"brand": {
"Dell": 15,
"HP": 12,
"Lenovo": 8
}
}
}
Search Settings¶
Searchable Attributes¶
By default, all text fields are searchable. Configure which fields to search:
curl -X PUT "https://api.centrali.io/workspace/my-workspace/api/v1/structures/products/search/settings" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"searchableAttributes": ["name", "description", "tags"]
}'
Ranking Rules¶
Customize result ranking:
curl -X PUT "https://api.centrali.io/workspace/my-workspace/api/v1/structures/products/search/settings" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"rankingRules": [
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
"price:asc"
]
}'
Advanced Features¶
Synonyms¶
Configure synonyms for better search results:
curl -X PUT "https://api.centrali.io/workspace/my-workspace/api/v1/structures/products/search/settings" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"synonyms": {
"laptop": ["notebook", "portable computer"],
"phone": ["mobile", "smartphone"]
}
}'
Stop Words¶
Exclude common words from search:
curl -X PUT "https://api.centrali.io/workspace/my-workspace/api/v1/structures/products/search/settings" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"stopWords": ["the", "a", "an"]
}'
Search in Functions¶
export async function handler(event, context) {
// Perform search
const results = await context.data.search('products', {
q: 'laptop',
filter: 'price < 1000',
limit: 10
});
context.logger.info('Search results', { count: results.hits.length });
return results;
}
Best Practices¶
- Use specific search terms for better relevance
- Combine search with filters for precise results
- Configure searchable attributes for performance
- Use faceted search for filtering UI
- Monitor search performance via metrics
Performance¶
- Average search time: < 50ms
- Index update: Real-time (records indexed on creation/update)
- Max results per page: 1000
- Search rate limit: 1000 requests/minute
Related Documentation¶
- Query Guide - Structured querying
- Structures & Records - Data management
- Compute Functions - Search in functions