backbone-db-elasticsearch
Advanced tools
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 @@ |
{ | ||
"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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28712
755
6
+ Addedasync@~0.9.0
+ Addedansi-regex@0.2.1(transitive)
+ Addedansi-styles@1.1.0(transitive)
+ Addedasync@0.9.2(transitive)
+ Addedbackbone-db@0.5.7(transitive)
+ Addedbackdash@1.1.2-2.4.1(transitive)
+ Addedbluebird@2.2.2(transitive)
+ Addedchalk@0.5.1(transitive)
+ Addeddebug@1.0.5(transitive)
+ Addedelasticsearch@2.4.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-ansi@0.1.0(transitive)
+ Addedlodash@2.4.1(transitive)
+ Addedms@2.0.0(transitive)
+ Addedpff@0.2.0(transitive)
+ Addedstrip-ansi@0.3.0(transitive)
+ Addedsupports-color@0.2.0(transitive)
- Removedansi-styles@1.0.0(transitive)
- Removedbackbone-db@0.4.25(transitive)
- Removedbluebird@1.2.4(transitive)
- Removedchalk@0.4.0(transitive)
- Removeddebug@0.8.1(transitive)
- Removedelasticsearch@2.2.0(transitive)
- Removedhas-color@0.1.7(transitive)
- Removedjsonquery@0.1.8(transitive)
- Removedstrip-ansi@0.1.1(transitive)
Updatedbackbone-db@~0.5
Updateddebug@~1.0
Updatedelasticsearch@~2.4