Socket
Socket
Sign inDemoInstall

backbone-db-elasticsearch

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backbone-db-elasticsearch - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

58

index.js
var _ = require('lodash');
var debug = require('debug')('backbone-db-elasticsearch');
var Db = require('backbone-db');
var async = require('async');

@@ -209,2 +210,59 @@ function ElasticSearchDb(name, client) {

return result;
},
// creates a new index (http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/indices-create-index.html)
createIndex: function(options, callback) {
var indexName = this.prefixIndexKeys(options.index);
var opts = {
index: indexName,
body: {
settings: options.settings
}
};
this.client.indices.create(opts, function(error, resp) {
callback(error, resp);
});
},
deleteIndex: function(options, callback) {
var indexName = this.prefixIndexKeys(options.index);
this.client.indices.delete({
index: indexName
}, function(error, resp) {
callback(error, resp);
});
},
closeIndex: function(options, callback) {
var indexName = this.prefixIndexKeys(options.index);
this.client.indices.close({
index: indexName
}, callback);
},
openIndex: function(options, callback) {
var indexName = this.prefixIndexKeys(options.index);
this.client.indices.open({
index: indexName
}, callback);
},
// updating index requires closing it first
updateIndex: function(options, callback) {
async.series([
this.closeIndex.bind(this, options),
this._updateIndex.bind(this, options),
this.openIndex.bind(this, options)
], callback);
},
_updateIndex: function(options, callback) {
var indexName = this.prefixIndexKeys(options.index);
var opts = {
index: indexName,
body: {
settings: options.settings
}
};
this.client.indices.putSettings(opts, callback);
}

@@ -211,0 +269,0 @@

15

package.json
{
"name": "backbone-db-elasticsearch",
"version": "0.1.3",
"version": "0.1.4",
"description": "Elasticsearch driver for backbone-db",

@@ -26,11 +26,12 @@ "main": "index.js",

"lodash": "~2.4.1",
"backbone-db": "~0.4",
"backbone-db": "~0.5",
"backbone": "~1.1.0",
"debug": "~0.8",
"elasticsearch": "~2.2"
"debug": "~1.0",
"elasticsearch": "~2.4",
"async": "~0.9.0"
},
"devDependencies": {
"mocha": "~1.18",
"jshint": "~2.4",
"istanbul": "~0.2",
"mocha": "~1.21",
"jshint": "~2.5",
"istanbul": "~0.3",
"chai": "~1.9",

@@ -37,0 +38,0 @@ "backbone-promises": "~0.2"

@@ -69,2 +69,55 @@ var setup = require('./setup');

});
describe('Index CRUD', function() {
it('should create index', function(next) {
var indexSettings = {
analysis: {
analyzer: {
uax_url_email : {
filter : [
"standard",
"lowercase",
"stop"
],
tokenizer : "uax_url_email"
}
}
}
};
this.db.createIndex({
index: 'foobar',
settings: indexSettings
}, function(err) {
next(err);
});
});
it('should update index settings', function(next) {
var indexSettings = {
mappings: {
info: {
_all : {
type: 'string',
analyzer: 'uax_url_email'
}
}
}
};
this.db.updateIndex({
index: 'foobar',
settings: indexSettings
}, function(err) {
next(err);
});
});
it('should delete index', function(next) {
this.db.deleteIndex({
index: 'foobar'
}, function(err) {
next(err);
});
});
});
});

@@ -185,2 +185,3 @@ var setup = require('./setup');

it('should apply script score', function() {
var hasC = '(doc.containsKey("tags") && doc["tags"].values.length > 0 && doc["tags"].values.contains("c"))';
var query = {

@@ -193,3 +194,3 @@ function_score: {

script_score: {
script: "_source.tags.contains(\"c\") ? 100 : 0",
script: hasC + ' ? 100 : 0',
},

@@ -230,2 +231,68 @@ boost_mode: 'replace'

});
it('should sort ascending by metadata', function() {
var query = {
wildcard: {
name: '*abc*',
}
};
var sort = [
{
'meta.score': {
order: 'asc'
}
}
];
var filter = {
range: {
'meta.score': {
gte: 30
}
}
};
collection = new this.Collection();
return collection
.fetch({
query: query,
sort: sort,
filter: filter
})
.then(function() {
collection.length.should.equal(2);
collection.at(1).get('content').meta.score.should.equal(90);
});
});
it('should sort descending by metadata', function() {
var query = {
wildcard: {
name: '*abc*',
}
};
var sort = [
{
'meta.score': {
order: 'desc'
}
}
];
var filter = {
range: {
'meta.score': {
gte: 30
}
}
};
collection = new this.Collection();
return collection
.fetch({
query: query,
sort: sort,
filter: filter
})
.then(function() {
collection.length.should.equal(2);
collection.at(1).get('content').meta.score.should.equal(40);
});
});
});

@@ -232,0 +299,0 @@

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