solr-node
Simple Solr Node Client Project
Install
npm install solr-node
Usage
- Client: http://godong9.github.io/solr-node/docs/Client.html
- Query: http://godong9.github.io/solr-node/docs/Query.html
Create Client
// Require modulevar SolrNode = ; // Create clientvar client = 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)level = 'DEBUG';
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 queryvar strQuery = client;var objQuery = client;var myStrQuery = 'q=text:test&wt=json'; // Search documents using strQuerysolrClient; // Search documents using objQuerysolrClient; // Search documents using myStrQuerysolrClient;
Update
// JSON Datavar data = text: 'test' title: 'test'; // Update document to Solr serverclient;
Delete
// Delete Queryvar strQuery = 'id:testid'var objQuery = id:'testid' // Delete document using strQueryclient; // Delete document using objQueryclient;
Promise support
Skip the callback to get a promise back. ie:
var result = solrClient ;
You can also use async
/await
:
try const result = await solrClient; console; catche console;
Test & Coverage & Docs
gulp