1.0.0 • Published 2 years ago

@tsed-plus/meilisearch-mongoose-indexer v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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'],
      },
    };
  }
}