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

amqp2solr

v0.0.8

Published

Pulls from an AMQP queue and pushes to Solr

Downloads

3

Readme

amqp2solr

amqp2solr is a library both for querying a SOLR core and queueing (add) queries for delayed execution. It is a wrapper, which aims to make delayed/remote execution of solr queries more seamless.

Basic usage

var dependencies = { config, logger, amqp };
var amqp2solr = require('amqp2solr')(dependencies);

The dependencies parameter can be used for overriding config and/or logger.

  • logger should have info, error and debug methods. It defaults to console.log.
  • config assumed to have a get method. (nconf is used)

getResource(options) and query locally

var resourceParams = { core: 'blogs' };
var blogResource = amqp2solr.getResource(resourceParams);
// ... and then ...
blogResource.add({id: 'example', someField: 1}, cb);
blogResource.createOrUpdate({id: 'example'}, {someOtherField: 1}, cb);

getQueue([queueName,] blogResource) and queue queries

// Create a resource ...
var blogResource = amqp2solr.getResource(resourceParams);

// ... and map it to the resource ...
var blogQueue = amqp2solr.getQueue(blogResource);
// ... optionally with explicitly given AMQP queue name ...
var blogQueue = amqp2solr.getQueue(queueName, blogResource);

You can give resourceParams instead of an actual resource (can be useful in environments where you don't want to use the resource locally.

var blogQueue = amqp2solr.getQueue(queueName, resourceParams);

You can get the resource var blogResource = blogQueue.resource;.

solrQueue.listen() to consume a queue

amqp2solr.getQueue(queueName, resourceParams).listen(); 

getResource(options)

Returns a solrResource instance.

The options parameter accepts the following fields:

  • core: the name of the core to connect to, defaults to ''
  • fields: an object consisting of key-value pairs to transform field names.
    • it's keys are keys of your existing model
    • it's values are field names in SOLR
    • Typically, this can be used to adapt to the default solr schema.xml, eg: {email: 'email_s'}
  • transformations is an optional object which can be used for transforming the data before/after solr.
    • it's keys are keys of your existing model
    • it's values are objects with 2 fields:
    • formSolr: function(value) {return value; }
    • toSolr: function(value) {return value; }
  • mlt is an optional more like this setting to be used as default in the recommend method.

It returns a solrResource object;

solrResource

  • add(doc [,cb]): creates/replaces a document
  • find(q [,cb]): find documents both by query or id
  • findAndModify(q, updateParams [, opts ,cb]): update some fields of existing documents matched by find(q)
  • createOrUpdate(q, updateParams, [, cb]): similar to findAndModify, but this creates a new document if none found.
  • moreLikeThis(q, [mlt], cb): find similar documents to any document which matches
  • delete(id, cb) deletes by a query, mapped from node-solr-client
  • deleteById(id, cb) deletes by id
  • encode formats the document to solr (transposes field names and performs transformations)
  • deocde formats the document came back from solr (reverses field names and performs reverse transformations)
  • solr exposes the wrapped node-solr-client

getQueue([queueName,] solrResourceOrOptions)

Returns a solrQueue instance. If solrResourceOrOptions is not a solrResource, it calls getResource with solrResourceOrOptions.

getAsymmetric([queueName,] solrResourceOrOptions)

Returns an asymmetric (queued-write, direct-read), mixed resource which queues inserts/updates/modifies but directly queries selects/moreLikeThis/...

solrQueue

solrQueue has exactly the same methods than a solrResource, but it pushes the task to the queue rather than executing it locally.