New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

feathers-solr

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

feathers-solr

Solr Adapter for Feathersjs

  • 0.1.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9K
decreased by-37.65%
Maintainers
1
Weekly downloads
 
Created
Source

feathers-solr

Build Status Coverage Status Dependency Status

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

OptionDefaultDescription
hosthttp://localhost:8983/solr
core/gettingstarted
schemafalse{title: {type:"string"}}
migratealtersafe, alter and drop (delete all data and reset schema)
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", // 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 = 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: 4
    });

    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

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: '"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"
            ]
        },

Additional Client Methods

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

0.1.5

  • Add $suggest feature 0.1.4 0.1.3

  • Initial release

License

Copyright (c) 2015

Licensed under the MIT license.

Keywords

FAQs

Package last updated on 29 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc