Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
sails-solr
Advanced tools
Readme
![](http://i.imgur.com/RIvu9.png | width=50)
Provides easy access to solr
from Sails.js & Waterline.
This module is a Waterline/Sails adapter, an early implementation of a rapidly-developing, tool-agnostic data standard. Its goal is to provide a set of declarative interfaces, conventions, and best-practices for integrating with all sorts of data sources.
The main goal is a simple usage and integration of a full managaged Solr.
To install this adapter, run:
$ npm install sails-solr
To install/start solr if you not have one running
make kickstart
Note: not recommended for production systems! Solr installation Tomcat for more
Add the solr
configuration to the config/connections.js
file. The basic
options are as follows:
module.exports.connections = {
solrConnectionOne: {
module : 'sails-solr',
host: 'localhost',
port: 8983,
core: 'schemaless',
schema: true,
migrate: 'drop'
}
};
Note: you can define multiple solr connections/cores. By default sails-solr will run multiple models inside one core
manageCores
. Connection Options
And then change default model configuration to the config/models.js:
module.exports.models = {
connection: 'solrConnectionOne',
attributes: {
name:'string'
...
}
};
Note: you can add more model based configuartion Model Options / Connection Options
create a user:
User.create({name:'foo'},console)
find a user:
User.find({name:'foo'},console);
User.findOne({name:'foo'},console);
User.findByName('foo',console);
Note: See Waterline Documentation Query Language and Query Methods
search suggestion and spellchecked phrase. Known as "Did You Mean: foo
?"
// as sails request see hooks and blueprint
// http://localhost:1337/user/suggest/foa
// in node
User.suggest('foa', console);
//response
{
"responseHeader": {
"status": 0,
"QTime": 1
},
"spellcheck": {
"suggestions": [
"foa",
{
"numFound": 1,
"startOffset": 0,
"endOffset": 9,
"origFreq": 0,
"suggestion": [
{
"word": "foo",
"freq": 1
}
]
}
],
"correctlySpelled": false,
"collations": [
"collation",
"foo"
]
},
"suggest": {
"suggest": {
"foa": {
"numFound": 2,
"suggestions": [
{
"term": "foo",
"weight": 0,
"payload": ""
},{
"term": "foo bar",
"weight": 0,
"payload": ""
}
]
}
}
}
}
Well known as filter. facet
for strings
and min,max,avg
for ìnteger
to build Options and Range Slider Elemets. Query Methods
// as sails request see hooks and blueprint
// http://localhost:1337/user/catalog/?name="*"&limit=3&sort=age asc&skip=0
// in node
User.catalog({name:'foo'},console);
//response
{
"responseHeader":{
"status":0,
"QTime":1,
"params":{
"q":"*:*",
"indent":"true",
"stats":"true",
"sort":"percent asc",
"rows":"100",
"wt":"json",
"stats.field":["age",
"percent"]}},
"response":{"numFound":13,"start":0,"docs":[
{
"name":"foo",
"age":10,
"color":"blue",
"createdAt":"2015-12-30T23:32:24.755Z",
"updatedAt":"2015-12-30T23:32:24.755Z",
"id":"612bb75f-be0f-496b-ba51-8e79ee786c50"},
{
"name":"bar",
"age":20,
"color":"yellow",
"createdAt":"2015-12-30T23:15:09.859Z",
"updatedAt":"2015-12-30T23:15:09.859Z",
"id":"517a4917-b3b8-4ea0-a3fd-acd41497b6e0"},
{
"name":"john",
"age":30,
"color":"black",
"createdAt":"2015-12-30T23:15:10.859Z",
"updatedAt":"2015-12-30T23:15:10.859Z",
"id":"515a4917-b3b8-4ea0-a3fd-acd4149432fd"},
},
"facet_counts": {
"facet_queries": {},
"facet_fields": {
"name": [
{
"blue":1},
{
"yellow":1},
{
"black":1},
]
},
"facet_dates": {},
"facet_ranges": {},
"facet_intervals": {},
"facet_heatmaps": {}
},
"stats":{
"stats_fields":{
"age":{
"min":10.0,
"max":30.0,
"count":3,
"missing":0,
"sum":60.0,
"sumOfSquares":100,
"mean":20,
"stddev":10}}}}
Note: See Waterline Documentation
Params | Default | Description |
---|---|---|
host | 'localhost' | |
port | '8983' | |
core | 'schemaless' | |
manageCores | true | create cores if not exists CoreAdmin |
schema | true | allow migrate drop, alter schema manage schema |
single | false | force manageCores to create a core for each model |
fieldTypeMap | fieldTypes | Field Type Map |
useFqParam | true | force query mapping as fq=name:foo param |
schemaDefaultFieldTypes | {} | |
debugAdapter | false | |
debugCollection | false | |
debugQuery | false | |
debugSolr | false |
{
attributes: {
first_name: {
type:'string'
// Overwrite per Field
schemaDefaultFieldAttributes: {
indexed: true,
type: 'text_de'
}
}
}
// Overwrite per Model
schemaDefaultFieldAttributes: {
indexed: false
}
}
The following table represents mappings between Sails/Waterline model data types and Solr field types:
Sails/Waterline Type | Solr Type |
---|---|
string | text_general |
text | text_general |
binary | text_general |
integer | int |
float | float |
date | date |
time | date |
datetime | date |
boolean | boolean |
binary | text_general |
array | text_general |
json | text_general |
point | point |
Note: You can even define your custom mapping as
fieldTypeMap:
inside connection settings and as model option. If you want a field type explicit mapping usefieldType
as additional fieldTypeMapattribute
The following table represents Solr field attributes:
Solr Field Attributes | Default |
---|---|
name | newField |
type | text_general |
indexed | true |
stored | true |
docValues | false |
sortMissingFirst | false |
sortMissingLast | false |
multiValued | false |
omitNorms | true |
omitTermFreqAndPositions | false |
omitPositions | false |
termVectors | true |
termPositions | false |
termOffsets | false |
termPayloads | false |
required | false |
dynamicField | false |
json | text_general |
Note: You can even define your custom field attribute default as
schemaDefaultFieldAttributes:
inside connection settings and as model option. If you want a field attribute explicit you can add this attribute as an additional option inside the Model attribute settings
$ npm test
FAQs
Solr Adapter for Sails / Waterline sds
The npm package sails-solr receives a total of 3 weekly downloads. As such, sails-solr popularity was classified as not popular.
We found that sails-solr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.