Meilisearch

Configure Meilisearch for @foadonis/magnify

Meilisearch is a fast, open-source search engine written in Rust. It’s easy to set up, delivers instant, relevant results, and offers a free self-hosted option.

Getting Started

Install dependencies

First install the meilisearch package.

npm install meilisearch

Configure 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 MeilisearchEngine to your Magnify configuration.

config/magnify.ts
import  from '#start/env'
import { ,  } from '@foadonis/magnify'
import type {  } from '@foadonis/magnify/types'
 
const  = ({
  : 'meilisearch',
  : {
    : .({
      : .get('MEILISEARCH_HOST'),
      : .get('MEILISEARCH_API_KEY', ),
    }),
  },
})
 
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 > {}
}

Index Settings

Some features like filtering and ordering require custom index configurations.

config/magnify.ts
import  from '#start/env'
import { ,  } from '@foadonis/magnify'
import type {  } from '@foadonis/magnify/types'
 
const  = ({
  : 'meilisearch',
  : {
    : .({
      : .get('MEILISEARCH_HOST'),
      : .get('MEILISEARCH_API_KEY', ),
      : {
        : {
          : ['isAdmin'],
          : ['createdAt'],
        },
      },
    }),
  },
})
 
export default 

You can then synchronize your indices with the following command:

node ace magnify:sync

Start Searching

On this page