0.1.4 • Published 9 years ago

node-solr-request v0.1.4

Weekly downloads
2
License
ISC
Repository
github
Last release
9 years ago

node-solr-request

A lightweight node.js Solr client

Usage example

The following sample uses Express

var solrRequest = require('node-solr-request');
var express     = require('express');
var bodyParser  = require('body-parser');
var fs          = require('fs');
var app         = express();

// configure body parser
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

var port = process.env.PORT || 8080;

var settings = '{
                  "serverAddress":"[SOLR SERVER URL OR IP]",
                  "solrCore":"\/solr\/[SOLR CORE NAME]",
                  "solrPort":"[YOUR SOLR PORT NUMBER]",
                  "solrUpdatePath":"\/update\/json?commitWithin=300",
                  "solrDataPath":"\/select"
                }';

var objRequest = new solrRequest(settings);

var router = express.Router();

router.use(function(req, res, next) {
	// do logging
	next();
});

router.route('/solrQuery')
	.post(function(req, res) {
		objRequest.insertDocument(req.body, res);
	})

	.get(function(req, res) {
		objRequest.getDocuments('*', req.query, res)
	});

router.route('/solrQuery/:queryString')
	.get(function(req, res){
		objRequest.getDocuments(req.params.queryString, req.query, res);
	});

app.use('/solr-api', router);

app.listen(port);
console.log('Listening on port ' + port);

example URLS

URLRESULT
SERVER NAME/solr-api/solrQuerywill return all documents based on your solr defaults
SERVER NAME/solr-api/solrQuery?filters={"field-name":"filter_value","field-name2":"filter_value"}will return all documents based on your solr defaults and filters specified
SERVER NAME/solr-api/solrQuery?params={"rows":5,"start":10}will return 5 documents starting with the 10th document
SERVER NAME/solr-api/solrQuery?filters={"field-name":"filter_value","field-name2":"filter_value"}ms={"rows":5}will return maximum 5 documents based on your filters specified
SERVER NAME/solr-api/solrQuery/widgetwill search for the string "widgets" and return all found documents based on your solr defaults
SERVER NAME/solr-api/solrQuery/widget?filters={"field-name":"filter_value","field-name2":"filter_value"}ms={"rows":5}will search for the string "widgets" and return maximum 5 found documents based on your filters specified
0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago