nestjs-algoliasearch
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

nestjs-algoliasearch

Algolia search module for NestJS, using the official algoliasearch package

Install

npm install nestjs-algoliasearch algoliasearch

or

yarn add nestjs-algoliasearch algoliasearch

Getting started

Register the module

// app.module.ts
import { AlgoliaModule } from 'nestjs-algoliasearch';

@Module({
  imports: [
    //...
    AlgoliaModule.forRoot({
      applicationId: 'ALGOLIA_APPLICATION_ID',
      apiKey: 'ALGOLIA_API_KEY',
    }),

    // Or async:
    AlgoliaModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (config: ConfigService) => config.get('algolia'),
    }),
    //...
  ],
})
export class AppModule {}

Register the indexes

// todo.module.ts
import { AlgoliaModule } from 'nestjs-algoliasearch';

@Module({
  imports: [
    TypeOrmModule.forFeature([
      TodoEntity,
    ]),
    AlgoliaModule.forFeature([{
      name: TodoEntity, // Or a string, this will be the index name
      options: {/* custom Algolia client index settings */},
    }])
  ],
})
export class TodoModule {}

See the official Algolia client documentatin for a list of all available Index options

Using the registered Index

The Index is injectable using the @InjectIndex decorator, the returned value is an algoliasearch.SearchIndex.

See the official Algolia client documentation for a list of available methods

// todo.service.ts
import { InjectIndex } from 'nestjs-algoliasearch';
import { SearchIndex } from 'algoliasearch';

@Injectable()
export class TodoService {
  constructor(
    @InjectIndex(TodoEntity /* or the string used as "name" prop while registering the index */)
    private readonly todoIndex: SearchIndex,
  )
}

Readme

Keywords

none

Package Sidebar

Install

npm i nestjs-algoliasearch

Weekly Downloads

57

Version

1.0.0

License

MIT

Unpacked Size

26.2 kB

Total Files

25

Last publish

Collaborators

  • davide-gheri