Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davide-gheri/nestjs-algoliasearch
Algolia search module for Nest framework (node.js)
https://github.com/davide-gheri/nestjs-algoliasearch
Last synced: about 1 month ago
JSON representation
Algolia search module for Nest framework (node.js)
- Host: GitHub
- URL: https://github.com/davide-gheri/nestjs-algoliasearch
- Owner: Davide-Gheri
- License: mit
- Created: 2020-05-08T07:43:21.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-08T00:53:45.000Z (almost 2 years ago)
- Last Synced: 2024-10-12T22:30:01.639Z (2 months ago)
- Language: TypeScript
- Size: 388 KB
- Stars: 6
- Watchers: 1
- Forks: 3
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# nestjs-algoliasearch
Algolia search module for NestJS, using the official [algoliasearch](https://github.com/algolia/algoliasearch-client-javascript#readme) package## Install
```bash
npm install nestjs-algoliasearch algoliasearch
```
or
```bash
yarn add nestjs-algoliasearch algoliasearch
```## Getting started
### Register the module```typescript
// 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
```typescript
// 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](https://www.algolia.com/doc/api-reference/settings-api-parameters/) 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](https://www.algolia.com/doc/api-client/methods/search/) for a list of available methods
```typescript
// 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,
)
}
```