backbone-db-elasticsearch
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -38,3 +38,6 @@ var _ = require('lodash'); | ||
}); | ||
return results; | ||
// sort by score | ||
return _.sortBy(results, function(r) { | ||
return -1 * r.score; | ||
}); | ||
}; | ||
@@ -41,0 +44,0 @@ |
{ | ||
"name": "backbone-db-elasticsearch", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Elasticsearch driver for backbone-db", | ||
@@ -29,3 +29,3 @@ "main": "index.js", | ||
"debug": "~0.8", | ||
"elasticsearch": "~2.1" | ||
"elasticsearch": "~2.2" | ||
}, | ||
@@ -32,0 +32,0 @@ "devDependencies": { |
@@ -29,2 +29,3 @@ var setup = require('./setup'); | ||
name: 'abc', | ||
tags: ['a', 'b'], | ||
meta: { | ||
@@ -47,2 +48,3 @@ score: 23 | ||
name: 'abc', | ||
tags: ['c', 'b'], | ||
meta: { | ||
@@ -184,2 +186,25 @@ score: 40 | ||
it('should apply script score', function() { | ||
var query = { | ||
function_score: { | ||
query: { | ||
matchAll: { | ||
} | ||
}, | ||
script_score: { | ||
script: "_source.tags.contains(\"c\") ? 100 : 0", | ||
}, | ||
boost_mode: 'replace' | ||
} | ||
}; | ||
collection = new this.Collection(); | ||
return collection | ||
.fetch({ | ||
query: query | ||
}) | ||
.then(function() { | ||
collection.at(0).get('content').title.should.equal('hop hep'); | ||
}); | ||
}); | ||
it('should sort', function() { | ||
@@ -233,3 +258,37 @@ var query = { | ||
}); | ||
it('should do msearch /w function_score', function() { | ||
var queriesBody = [ | ||
// match all query | ||
{ index: 'anotheridx'}, | ||
{ query: { match_all: {} } }, | ||
// query_string query, on index/type | ||
{ index: 'testidx', type: 'test' }, | ||
{ | ||
query: { | ||
function_score: { | ||
query: { | ||
matchAll: { | ||
} | ||
}, | ||
script_score: { | ||
script: "_source.tags.contains(\"c\") ? 100 : 5", | ||
}, | ||
boost_mode: 'replace' | ||
} | ||
} | ||
} | ||
]; | ||
collection = new this.Collection(); | ||
return collection | ||
.fetch({ | ||
msearch: true, | ||
body: queriesBody | ||
}) | ||
.then(function() { | ||
collection.length.should.equal(3); | ||
collection.at(0).get('content').title.should.equal('hop hep'); | ||
}); | ||
}); | ||
}); | ||
}); |
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
24506
589
+ Addedelasticsearch@2.2.0(transitive)
- Removedelasticsearch@2.1.6(transitive)
Updatedelasticsearch@~2.2