npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nolr

v1.0.2

Published

Solr Node Client with ES6 Support

Downloads

4

Readme

nolr

This project is a fork of the Simple Solr Node Client Project.

License: MIT

Install

npm install nolr

Create Client

// Require module
const nolr = require('nolr');

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

// Set Debug Level
const client = new nolr({
    host: '127.0.0.1',
    port: '8983',
    core: 'test',
    protocol: 'http',
    debugLevel: 'ERROR' // log4js debug level paramter
});

Search

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
let strQuery = client.query().q('text:test');
let objQuery = client.query().q({text:'test', title:'test'});
let myStrQuery = 'q=text:test&wt=json';

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

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

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

Update

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

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

// JSON Array Data, takes both array or JSON Lines
let data = [{text: 'test1', title: 'test1'},
            {text: 'test2', title: 'test2'},
            {text: 'test3', title: 'test3'}];

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

Delete

// Delete Query
let strQuery = 'id:testid'
let 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:

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

Test & Coverage & Docs

gulp