nest-meilisearch
TypeScript icon, indicating that this package has built-in type declarations

1.0.14 • Public • Published

NEST-MEILISEARCH

Nest-meilisearch is a simple nestjs wrapper around the meilisearch-js library.

Installation

This plugin requires you to install the meilisearch package to work

Installation with npm

 npm i nest-meilisearch meilisearch

Installation with yarn

 yarn add nest-meilisearch meilisearch

Getting Started

Start by importing the MeiliSearchModule global module in your AppModule. Then configure your meilisearch client using the forRoot.

import { MeiliSearchModule } from "nest-meilisearch";

@Module({
  imports: [
    MeiliSearchModule.forRoot({
      host: "http://127.0.0.1:7700", // your meilisearch client server url
      apiKey: "MASTER_KEY", // your server api key
    }),
  ],
})
export class AppModule {}

You can also set up basic indices / indexes when configuring your meilisearch client

import { MeiliSearchModule } from "nest-meilisearch";

@Module({
  imports: [
    MeiliSearchModule.forRoot({
      host: "http://127.0.0.1:7700", // your meilisearch client server url
      apiKey: "MASTER_KEY", // your server api key
      indices: ['movies','products'],

      // or  pass option for your indices like this

      indices: [{ uid: "movies", options: { primaryKey: 'id' } }],
    }),
  ],
})
export class AppModule {}

Your indices would be created once your app is loaded and you can start using them right away.

Usage

Simply Inject the MeiliSearchService into your app and start using it. It extends all the methods provided by the meilisearch-js library.

import { Inject, Injectable } from "@nestjs/common";
import { MeiliSearch } from "meilisearch";
import { MeiliSearchService } from "nest-meilisearch";

@Injectable()
export class AppService {
  constructor(
    @Inject(MeiliSearchService) private readonly meiliSearch: MeiliSearch
  ) {}

  async searchMovies(query: string) {
    const moviesIndex = this.meiliSearch.index("movies");
    return await moviesIndex.search(query);
  }
}

Learn more

The following documentation resources may interest you

Package Sidebar

Install

npm i nest-meilisearch

Weekly Downloads

16

Version

1.0.14

License

MIT

Unpacked Size

13.9 kB

Total Files

20

Last publish

Collaborators

  • console45