Solr Adapter for Feathersjs. Can also used as a Solr-client. See additional-client-methods Require >= Solr 5.x
feather-solr This demonstrate ease of a single query
npm install feathers-solr --save
Please refer to the Feathers database adapter documentation for more details or directly at:
- Service methods - How to use a database adapter
- Pagination and Sorting - How to use pagination and sorting for the database adapter
- Querying - The common adapter querying mechanism
- Extending - How to extend a database adapter
bin/solr start -e schemaless
Use feathers-solr/bin/install-solr.sh for a kickstart installation.
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} | |
paginate | {default: 10, max: 100} |
Schemaless Mode is recommended. Use Solr Field Types and Field Type Definitions and Properties to define Model properties
{
title: {
type: "text_general", // For more flexible searching. Default type is 'string'
stored: true, // default, keep value visible in results
indexed: true, // default, make it searchable
multiValued: false, // default, true becomes an array field
}
}
See your current schema definition
http://localhost:8983/solr/gettingstarted/schema/
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 = new solr.Service({
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');
node /example/app.js
See Feathers querying for more detail
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 *]", // Search in default field _text_. See Solr copy field `copy:* to _text_`
// $params: {
// qf: "name^10 friends" define explicit fields to query and boost
// }
// or $search: "name:John^10 AND !name:Doe AND age:[80 TO *]",
// or $search: "joh*",
// or $search: '"john doe"',
// or $search: 'jon~',
}
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"
}
]
}
}
]
}
}
}
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)"
}
}
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
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": ""
}]
}
}
}
}
}
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"
]
},
Support simple usage Feathers Docs
data: {views: 1};
Adapter.patch(id, data, params);
Support also advanced Solr Atomic Field Update Solr Docs
data: {views: {inc:1}}; // inc, set, add, remove, removeregex
Adapter.patch(id, data, params);
| ------
Solr Api's | Returns a Promise | ./client/requestHandler/ |
---|---|---|
Ping | Adapter.client().ping() | Ping.js |
JSON Request API | Used by Adapter .find() .get() | JsonRequestApi.js |
Update | Used by Adapter .create(), .update() and .patch() | UpdateRequestHandlers.js |
SearchHandlers | Adapter.client().search() | SearchHandlers.js |
Schema API | Adapter.client().schema.method | SchemaApi.js |
Config API | ConfigApi.js | |
CoreAdmin API | Adapter.client().coreAdmin.method | CoreAdminApi.js |
Solr ConfigSets API | Adapter.client().configSets.method | ConfigSetsApi.js |
Solr Collections API | Adapter.client().collections.method | CollectionsApi.js |
Solr Managed Resources | Adapter.client().resources.method | ManagedResources.js |
Request Parameters API | Adapter.client().requestParameters.method | RequestParametersAPI.js |
ParalellSQL.js | ||
ReplicationHandlers.js | ||
RealTime.js | ||
ShardHandlers.js | ||
BlobStoreApi.js |
Not all Solr API's implemented at the moment
- 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.
1.1.13
- refactor describe
- refactor define
- add schema tests
- edit docs
1.1.12
- refactor patch method
...
Copyright (c) 2015
Licensed under the MIT license.