1.1.17 • Published 6 years ago

feathers-ynm-solr v1.1.17

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

feathers-solr

Build Status Coverage Status dependencies Status Known Vulnerabilities

Solr Adapter for Feathersjs. Can also used as a Solr-client. See additional-client-methods Require >= Solr 5.x

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

OptionDefaultDescription
hosthttp://localhost:8983/solr
core/gettingstarted
schemafalse{title: {type:"string"}}
migratealtersafe, 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}

Managed Schema

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/

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 = 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');

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 *]", // 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~', 
  
}

$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

AggregationExampleEffect
sumsum(sales)summation of numeric values
avgavg(popularity)average of numeric values
sumsqsumsq(rent)sum of squares
minmin(salary)minimum value
maxmax(mul(price,popularity))maximum value
uniqueunique(state)number of unique values (count distinct)
hllhll(state)number of unique values using the HyperLogLog algorithm
percentilepercentile(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"
            ]
        },

Adapter.patch

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);

| ------

Additional Client Methods

Solr Api'sReturns a Promise./client/requestHandler/
PingAdapter.client().ping()Ping.js
JSON Request APIUsed by Adapter .find() .get()JsonRequestApi.js
UpdateUsed by Adapter .create(), .update() and .patch()UpdateRequestHandlers.js
SearchHandlersAdapter.client().search()SearchHandlers.js
Schema APIAdapter.client().schema.methodSchemaApi.js
Config APIConfigApi.js
CoreAdmin APIAdapter.client().coreAdmin.methodCoreAdminApi.js
Solr ConfigSets APIAdapter.client().configSets.methodConfigSetsApi.js
Solr Collections APIAdapter.client().collections.methodCollectionsApi.js
Solr Managed ResourcesAdapter.client().resources.methodManagedResources.js
Request Parameters APIAdapter.client().requestParameters.methodRequestParametersAPI.js
Parallel SQL InterfaceParalellSQL.js
ReplicationHandlersReplicationHandlers.js
RealTime GetRealTime.js
ShardHandlersShardHandlers.js
Solr BolbStore APIBlobStoreApi.js

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.1.13

  • refactor describe
  • refactor define
  • add schema tests
  • edit docs

1.1.12

  • refactor patch method

...

License

Copyright (c) 2015

Licensed under the MIT license.