@tsed-plus/meilisearch-mongoose-indexer
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Ts.ED Plus Meilisearch Mongo(ose) Indexer

Support for Meilisearch in your Ts.ED application. Extends the Ts.ED framework with the functionality to synchronize Mongoose models with Meilisearch

Contents

Prerequisite

If you have not already, familiarize yourself with the Ts.ED framework, MongoDB/Mongoose and Meilisearch.

Getting Started

Begin with the setup and configuration steps of @tsed-plus/meilisearch and @tsed/mongoose.

Install Ts.ED Module

# npm
npm install @tsed-plus/meilisearch-mongoose-indexer

# yarn
yarn add @tsed-plus/meilisearch-mongoose-indexer

Usage

  1. Have some class annotated with @Model (from @tsed-plus/mongoose), e.g.
@Model({ collection: 'pokemons' })
export class Pokemon {
  @Required()
  @ObjectID('id')
  _id: ObjectID;

  @Required()
  number: number;

  @Required()
  name: string;

  @Required()
  img: string;

  @Required()
  @CollectionOf(String)
  type: string[];

  @Required()
  @CollectionOf(Move)
  moves: Map<string, Move[]>;

  @Required()
  damages: Damages;

  @Property()
  @OnSerialize((v, ctx) => (ctx.meilisearch ? undefined : v))
  misc?: any;
}
  1. Implement a class based on BaseMeiliMongoIndexer<T> and add the @MeiliMongoIndexer decorator.
@MeiliMongoIndexer({
  model: Pokemon,
})
export class MeilisearchTestModelIndexer extends BaseMeiliMongoIndexer<Pokemon> {
  transformDocument(input: Pokemon) {
    return serialize(input, { type: Pokemon, meilisearch: true });
  }

  getCreateIndexOptions(): IndexOptions {
    return { primaryKey: 'id' };
  }

  async getUpdateIndexAndSettingsOptions(
    index: Index<Pokemon>
  ): Promise<UpdateIndexAndSettingsOptions | undefined> {
    return {
      indexSettings: {
        synonyms: { enton: ['psyduck'] },
        filterableAttributes: ['type'],
      },
    };
  }
}

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @tsed-plus/meilisearch-mongoose-indexer

      Weekly Downloads

      1

      Version

      1.0.0

      License

      MIT

      Unpacked Size

      17.3 kB

      Total Files

      20

      Last publish

      Collaborators

      • ochrstn