Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

solr-node

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

solr-node

Simple Solr Node Client Project

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.1K
increased by11.85%
Maintainers
1
Weekly downloads
 
Created
Source

solr-node

Simple Solr Node Client Project

NPM

codecov bitHound Dependencies License: MIT

Install

npm install solr-node

Usage

Create Client

// Require module
var SolrNode = require('solr-node');

// Create client
var client = new SolrNode({
    host: '127.0.0.1',
    port: '8983',
    core: 'test',
    protocol: 'http'
});

// Set logger level (can be set to DEBUG, INFO, WARN, ERROR, FATAL or OFF)
require('log4js').getLogger('solr-node').level = 'DEBUG';

Search can be executed with a simple text query or an object query.

Text

Text queries are similar to what one would find on the SOLR Core UI, EX:

From the URL: http://localhost:8080/solr/products/select?q=*%3A*&wt=json

The Query would be:

*:*&wt=json

NOTE: url decoded ':' from %3A.

Object

Object based queries can be simple or complex using chaining. Each method of the Query object returns an instance of itself.

Examples:

Simple:

client.query().q({text:'test', title:'test'});

Complex and chained:

client.query()
    .q({text:'test', title:'test'})
    .addParams({
        wt: 'json',
        indent: true
    })
    .start(1)
    .rows(1)
;

Query Examples

// Create query
var strQuery = client.query().q('text:test');
var objQuery = client.query().q({text:'test', title:'test'});
var myStrQuery = 'q=text:test&wt=json';

// Search documents using strQuery
solrClient.search(strQuery, function (err, result) {
   if (err) {
      console.log(err);
      return;
   }
   console.log('Response:', result.response);
});

// Search documents using objQuery
solrClient.search(objQuery, function (err, result) {
   if (err) {
      console.log(err);
      return;
   }
   console.log('Response:', result.response);
});

// Search documents using myStrQuery
solrClient.search(myStrQuery, function (err, result) {
   if (err) {
      console.log(err);
      return;
   }
   console.log('Response:', result.response);
});

Update

// JSON Data
var data = {
    text: 'test',
    title: 'test'
};

// Update document to Solr server
client.update(data, function(err, result) {
   if (err) {
      console.log(err);
      return;
   }
   console.log('Response:', result.responseHeader);
});

Delete

// Delete Query
var strQuery = 'id:testid'
var objQuery = {id:'testid'}

// Delete document using strQuery
client.delete(strQuery, function(err, result) {
   if (err) {
      console.log(err);
      return;
   }
   console.log('Response:', result.responseHeader);
});

// Delete document using objQuery
client.delete(objQuery, function(err, result) {
   if (err) {
      console.log(err);
      return;
   }
   console.log('Response:', result.responseHeader);
});

Promise support

Skip the callback to get a promise back. ie:

var result = solrClient.search(query)
    .then(function(result) {
      console.log('Response:', result.response);
    })
    .catch(function(err) {
      console.error(err);
    });

You can also use async/await:

try {
   const result = await solrClient.search(query);
   console.log('Response:', result.response);
} catch(e) {
   console.error(err);
}

Test & Coverage & Docs

gulp

Keywords

FAQs

Package last updated on 06 May 2019

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc