Socket
Book a DemoInstallSign in
Socket

nestjs-solr

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-solr

Solr client for Nestjs

1.0.2
latest
Source
npmnpm
Version published
Weekly downloads
35
25%
Maintainers
0
Weekly downloads
 
Created
Source

nestjs-solr

Description

Solr module for Nestjs.

Installation

npm install nestjs-solr

Usage

Register SolrModule:

import { SolrModule } from 'nest-solr';

@Module({
  imports: [
    SolrModule.register({
      host: 'localhost',
      port: '8983',
      secure: false,
      core: 'mycore',
    }),
  ],
})
export class AppModule {}

Inject SolrService:

import { SolrService } from 'nest-solr';

@Injectable()
export class SearchService {
  constructor(private readonly solrService: SolrService) {}
}

Options for Basic Authentication combined with a self-signed certificate (TLS)

import { SolrModule } from 'nest-solr';

@Module({
  imports: [
    SolrModule.register({
      host: 'localhost',
      port: '8983',
      secure: true,
      tls: {
        ca: [fs.readFileSync('solr-ssl.pem')],
      },
      auth: {
        basic: {
          username: 'solr',
          password: 'SolrRocks',
        },
      },
      core: 'mycore',
    }),
  ],
})
export class AppModule {}

***(See more Securing Solr)

Async options

@Module({
  imports: [
    SolrModule.registerAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        host: configService.get('SOLR_HOST'),
        port: configService.get('SOLR_PORT'),
        secure: configService.get('SOLR_SECURE'),
        core: 'mycore',
      }),
      inject: [ConfigService],
    }),
  ],
})

Examples

// Add a new document
const obj = await this.solrService.add({ id : 12, title_t : 'Hello', status: '1' });
console.log('Solr response:', obj);

// Search
const solrQuery = this.solrService
  .query()
  .q({ title_t: 'Hello' })
  .matchFilter('status', '1') //the fq (Filter Query)
  .fl(['title_t']) //the fl (field List)
  .start(0) //the offset where the set of returned documents should begin
  .rows(10) //the maximum number of documents returned
;
const ret: SearchResponse<any> = await this.solrService.search(solrQuery);
console.log('Solr response:', obj);

// Delete all documents
await this.solrService.deleteAll();

API Spec

The SolrService wraps the Solr client from the lbdremy/solr-node-client library. The SolrModule.register() takes options object as an argument to create the client, read more here.

Solr Homepage: https://solr.apache.org/

License

Nestjs-Solr is MIT licensed.

Keywords

nestjs

FAQs

Package last updated on 19 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.