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.
var dependencies = { config, logger, amqp };
var amqp2solr = require('amqp2solr')(dependencies);
The dependencies parameter can be used for overriding config
and/or logger
.
logger
should haveinfo
,error
anddebug
methods. It defaults to console.log.config
assumed to have aget
method. (nconf is used)
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);
// 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;
.
amqp2solr.getQueue(queueName, resourceParams).listen();
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 therecommend
method.
It returns a solrResource
object;
add(doc [,cb])
: creates/replaces a documentfind(q [,cb])
: find documents both by query or idfindAndModify(q, updateParams [, opts ,cb])
: update some fields of existing documents matched byfind(q)
createOrUpdate(q, updateParams, [, cb])
: similar tofindAndModify
, but this creates a new document if none found.moreLikeThis(q, [mlt], cb)
: find similar documents to any document which matchesdelete(id, cb)
deletes by a query, mapped fromnode-solr-client
deleteById(id, cb)
deletes by idencode
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 wrappednode-solr-client
Returns a solrQueue
instance. If solrResourceOrOptions is not a
solrResource,
it calls getResource with solrResourceOrOptions.
Returns an asymmetric (queued-write, direct-read), mixed resource which queues inserts/updates/modifies but directly queries selects/moreLikeThis/...
solrQueue
has exactly the same methods than a solrResource
, but it pushes the task to the queue rather than executing it locally.