# amqp2solr

> Pulls from an AMQP queue and pushes to Solr

Latest version **0.0.8** (published 2014-10-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install amqp2solr
pnpm add amqp2solr
yarn add amqp2solr
bun add amqp2solr
```

## Health

**Score 5/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2014-10-18 |
| First published | 2014-10-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+6 in 2 direct dependencies) |
| Install scripts | no |
| Author | ifroz |
| Maintainers | ifroz |

## Links

- npm: https://www.npmjs.com/package/amqp2solr
- npm.io page: https://npm.io/package/amqp2solr

## Dependencies (5)

- [amqp](https://npm.io/package/amqp.md) ^0.2.0
- [jstk](https://npm.io/package/jstk.md) git://github.com/ifroz/jstk.git
- [nconf](https://npm.io/package/nconf.md) ^0.6.9
- [lodash](https://npm.io/package/lodash.md) ^2.4.1
- [solr-client](https://npm.io/package/solr-client.md) ^0.4.0

## Recent versions

- 0.0.8 (latest) — 2014-10-18
- 0.0.7 — 2014-10-18
- 0.0.6 — 2014-10-18
- 0.0.5 — 2014-10-17
- 0.0.4 — 2014-10-17
- 0.0.3 — 2014-10-17
- 0.0.1 — 2014-10-16
- 0.0.0 — 2014-10-11

## 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.

---
_Source: https://npm.io/package/amqp2solr · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
