Skip to content

Commit

Permalink
fix(aggregate): handle sorting by text score correctly
Browse files Browse the repository at this point in the history
Fix #5258
  • Loading branch information
vkarpov15 committed May 20, 2017
1 parent b386516 commit 6a2d405
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,11 @@ Aggregate.prototype.sort = function(arg) {
if (arg.constructor.name === 'Object') {
var desc = ['desc', 'descending', -1];
Object.keys(arg).forEach(function(field) {
// If sorting by text score, skip coercing into 1/-1
if (arg[field] instanceof Object && arg[field].$meta) {
sort[field] = arg[field];
return;
}
sort[field] = desc.indexOf(arg[field]) === -1 ? 1 : -1;
});
} else if (arguments.length === 1 && typeof arg === 'string') {
Expand Down

0 comments on commit 6a2d405

Please sign in to comment.