Typesense
Configure Typesense for @foadonis/magnify
Typesense is a blazing-fast, open-source search engine built in C++. It’s easy to use, privacy-friendly, and offers a free self-hosted option for building smart, instant search experiences.
Getting Started
Install dependencies
First install the typesense package.
npm install typesenseConfigure environment variables
Update your environment variables schema and add them to your .env file.
import { } from '@adonisjs/core/env'
export default await .(new ('../', import.meta.), {
: ..({ : 'host' }),
: ..(),
})Configure the Search Engine
Add the TypesenseEngine to your Magnify configuration.
import from '#start/env'
import { , } from '@foadonis/magnify'
import type { } from '@foadonis/magnify/types'
const = ({
: 'typesense',
: {
: .({
: .get('TYPESENSE_API_KEY', ),
: [{ : .get('TYPESENSE_NODE_URL') }],
}),
},
})
export default
/**
* Inferring types for the list of engines you have configured
* in your application.
*/
declare module '@foadonis/magnify/types' {
export interface EnginesList extends <typeof > {}
}Configure indices
Typesense does not automatically create collections for you. You need to create and configure them manually.
import from '#start/env'
import { , } from '@foadonis/magnify'
import type { } from '@foadonis/magnify/types'
const = ({
: 'typesense',
: {
: .({
: .get('TYPESENSE_API_KEY', ),
: [{ : .get('TYPESENSE_NODE_URL') }],
: {
: {
: ['title'],
: [
{
: 'title',
: 'string',
},
{
: 'updatedAt',
: 'int32',
},
{
: 'createdAt',
: 'int32',
},
],
},
},
}),
},
})
export default You can then synchronize your indices with the following command:
node ace magnify:sync