feathers-solr
![Dependency Status](https://david-dm.org/sajov/feathers-solr.svg)
Solr Adapter for Feathersjs
Online Demo
feather-solr
This demonstrate ease of a single query
Installation
npm install feathers-solr --save
Documentation
Please refer to the Feathers database adapter documentation for more details or directly at:
Getting Started
Install Solr
bin/solr start -e schemaless
Use feathers-solr/bin/install-solr.sh for a kickstart installation.
Options
Option | Default | Description |
---|
host | http://localhost:8983/solr | |
core | /gettingstarted | |
schema | false | {title: {type:"string"}} |
migrate | alter | safe, alter and drop (delete all data and reset schema) |
idfield | 'id' | Unique Document identifier |
commitStrategy | {softCommit: true, commitWithin: 50000, overwrite: true} | |
Managed Schema
Schemaless Mode is recommended.
Use Solr Field Types and Field Type Definitions and Properties to define Model properties
{
title: {
type: "text_general",
stored: true,
indexed: true,
multiValued: false,
}
}
See your current schema definition
http://localhost:8983/solr/gettingstarted/schema/
Complete Example
Here's an example of a Feathers server that uses feathers-solr
.
const feathers = require('feathers');
const rest = require('feathers-rest');
const hooks = require('feathers-hooks');
const bodyParser = require('body-parser');
const errorHandler = require('feathers-errors/handler');
const solr = require('feathers-solr');
const Service = feathersSolr({
host: 'http://localhost:8983/solr',
core: '/gettingstarted',
schema:{
name: 'text_general',
company: 'text_general',
email: 'text_general',
age: 'int',
gender: 'string',
color: {
type: 'string',
multiValued: true,
},
address: {
type: 'string',
default: 'Düsseldorf'
}
},
paginate: {
default: 10,
max: 100
});
const app = feathers()
.configure(rest())
.configure(hooks())
.use(bodyParser.json())
.use(bodyParser.urlencoded({ extended: true }))
.use('/solr', Service())
.use(errorHandler());
app.listen(3030);
console.log('Feathers app started on 127.0.0.1:3030');
Run Demo App
node /example/app.js
Support all Feathers Queries
See Feathers querying for more detail
Supported Solr Queries
$search
Simple query
query: {
$search: "John"
}
'$search' will try to match against Solr default search field 'text' Schemaless Mode
More complex query with a default Solr configuration.
query: {
$search: "John !Doe +age:[80 TO *]",
}
$params
Add all kind of Solr query params!
Combine huge Solr Features like facets, stats, ranges, grouping and more with the default response.
This example will group the result.
query: {
$params: {
group : true,
"group.field" : "country",
"group.format" : "simple",
}
}
Feathers Rest query
http://localhost:3030/solr?$params[group]=true&$params[group.field]=gender&$params[group.field]=age&$params[group.limit]=1&$params[group.format]=grouped&$select=id,age,gender
Feathers Result
{
"QTime": 0,
"total": 0,
"limit": 10,
"skip": 0,
"data": {
"gender": {
"matches": 50,
"groups": [
{
"groupValue": "male",
"doclist": {
"numFound": 24,
"start": 0,
"docs": [
{
"id": "59501959f2786e0207a8b29f",
"age": "45",
"gender": "male"
}
]
}
},
{
"groupValue": "female",
"doclist": {
"numFound": 26,
"start": 0,
"docs": [
{
"id": "595019590a8632fecd292592",
"age": "51",
"gender": "female"
}
]
}
}
]
},
"age": {
"matches": 50,
"groups": [
{
"groupValue": "45",
"doclist": {
"numFound": 3,
"start": 0,
"docs": [
{
"id": "59501959f2786e0207a8b29f",
"age": "45",
"gender": "male"
}
]
}
},
{
"groupValue": "51",
"doclist": {
"numFound": 2,
"start": 0,
"docs": [
{
"id": "595019590a8632fecd292592",
"age": "51",
"gender": "female"
}
]
}
}
]
}
}
}
$facet Functions and Analytics
See Solr Facet Functions and Analytics
Aggregation | Example | Effect |
---|
sum | sum(sales) | summation of numeric values |
avg | avg(popularity) | average of numeric values |
sumsq | sumsq(rent) | sum of squares |
min | min(salary) | minimum value |
max | max(mul(price,popularity)) | maximum value |
unique | unique(state) | number of unique values (count distinct) |
hll | hll(state) | number of unique values using the HyperLogLog algorithm |
percentile | percentile(salary,50,75,99,99.9) | calculates percentiles |
query: {
$facet: {
age_avg : "avg(age)",
age_sum : "sum(age)"
}
}
$facet Ranges
Add a facet type range
query: {
$facet: {
age_ranges: {
type: "range",
field: "age",
start: 0,
end: 100,
gap: 25
}
}
}
Feathers Rest query
http://localhost:3030/solr?&$facet[age_ranges][type]=range&$facet[age_ranges][field]=age&$facet[age_ranges][start]=0&$facet[age_ranges][end]=100&$facet[age_ranges][gap]=25&$facet[age_avg]=avg(age)&$facet[age_sum]=sum(age)
Feathers Result
{
QTime: 0,
total: 50,
limit: 10,
skip: 0,
data: [...],
facet: {
age_avg: 29.44,
age_sum: 1472,
count: 54,
age_ranges: {
buckets: [{
val: 0,
count: 4
}, {
val: 25,
count: 17
}, {
val: 50,
count: 15
}, {
val: 75,
count: 14
}]
}
}
}
See more query variants JSON Facet API,Solr Facet Functions and Analytics, Solr Subfacets, Multi-Select Faceting
$suggest
A custom response object for autocompleter suggestions.
See example app.js for creating a custom searchcomponent and requesthandler including a spellcheck component
query: {
$suggest: 'Handmake',
$params: {} // to plain solr parameter
}
Feathers Rest query
http://localhost:3030/solr?&$suggest=Handmake
Feathers Result
This is a plain solr response
{
{
"responseHeader": {
"status": 0,
"QTime": 1
},
"spellcheck": {
"suggestions": [
"handmake", {
"numFound": 1,
"startOffset": 0,
"endOffset": 8,
"origFreq": 0,
"suggestion": [{
"word": "handmade",
"freq": 1
}]
}
],
"correctlySpelled": false,
"collations": [
"collation",
"handmade"
]
},
"suggest": {
"suggest": {
"Handmake": {
"numFound": 1,
"suggestions": [{
"term": "Handmade Wooden Keyboard",
"weight": 0,
"payload": ""
}]
}
}
}
}
}
$spellcheck
This feature add a spellcheck component to the default find result
query: {
$search: "Handmake",
$spellcheck:1,
color: "sky blue",
$limit: 10,
}
Feathers Rest query
http://localhost:3030/solr?$search=Handmake&color=Handmke&color="sky blue"&$limit=10&$spellcheck
Feathers Result
{
"QTime": 0,
"total": 6,
"limit": 10,
"skip": 0,
"data": [...],
"spellcheck": {
"suggestions": [
"handmake", {
"numFound": 1,
"startOffset": 0,
"endOffset": 8,
"origFreq": 0,
"suggestion": [{
"word": "handmade",
"freq": 1
}]
}
],
"correctlySpelled": false,
"collations": [
"collation",
"handmade"
]
},
Additional Client Methods
Not all Solr API's implemented at the moment
TODO
- Write more Tests
- Write more Docs
- Implement $suggest and $spellcheck
- Add demo autocompleter with suggestions.
- Add demo search page with facet navigation, filter(ranges, sliders), pagination and result listing by just one query.
Changelog
1.0.1
License
Copyright (c) 2015
Licensed under the MIT license.