Adding Search Indices to the Frontend
This guide explains how to add new indices to the frontend search functionality. The search system uses Meilisearch and requires configuration in two main files.
Files to Modify
app/src/composables/useHttp.js- Register the search endpointapp/src/components/ui/CommandPalette/StartScreen.vue- Configure the index mapping
Step 1: Add Search Endpoint in useHttp.js
In useHttp.js, add a new entry to the REGISTRY object for your index:
javascript
const REGISTRY = {
// ... existing entries ...
"search.your_index": { service: 'search', path: "/indexes/your_index/search/" },
"search.multiple": { service: 'search', path: "/multi-search" }, // This is required for multi-index search
}For example, to add a search endpoint for projects:
javascript
"search.project": { service: 'search', path: "/indexes/project/search/" }Step 2: Configure Index Mapping in StartScreen.vue
In StartScreen.vue, add your index to the indices object:
javascript
const indices = {
// ... existing indices ...
'your_index': 'your_resource',
}The key is the Meilisearch index name, and the value is the resource name used in the application.
For example:
javascript
const indices = {
'project': 'project',
'milestones': 'milestones',
'employee': 'employee',
}Step 3: Update Search Function
The search function in StartScreen.vue should use the following format:
javascript
function search() {
requests.value.search = getResource('search.multiple')
requests.value.search.method = 'post'
const searchQuery = removeHashtags(q.value)
const searchIndices = customIndices.value.length > 0 ? customIndices.value : Object.keys(indices)
requests.value.search.data = {
"federation": {},
"queries": searchIndices.map(index => ({
"indexUid": index,
"q": searchQuery
}))
}
sendRequest(requests.value.search)
}Example: Adding a New Index
Let's say you want to add a new index for "drivers":
- Add to
useHttp.js:
javascript
"search.driver": { service: 'search', path: "/indexes/driver/search/" }- Add to
StartScreen.vue:
javascript
const indices = {
// ... existing indices ...
'driver': 'driver',
}Important Notes
- The index name in Meilisearch must match the key in the
indicesobject - The resource name should match your application's resource naming convention
- Make sure the Meilisearch index is properly configured on the backend
- The index should have the necessary fields for search results (typically
id,name,full_name,description) - The search request must include the
federationfield with an empty object - Each query in the
queriesarray must haveindexUidandqfields
Testing
After adding a new index:
- Restart the frontend application
- Try searching in the command palette
- Verify that results from your new index appear in the search results
- Check the network tab in your browser's developer tools to ensure the request format matches the example
Troubleshooting
If search results don't appear:
- Check the browser console for errors
- Verify the Meilisearch index exists and has data
- Ensure the index name matches exactly between frontend and backend
- Check that the search endpoint is correctly registered in
useHttp.js - Verify the request format matches the example above
- Check the network tab to see the exact request being sent