[backend/memory,bugfix][s]: corrected sort for memory backend so works correctly on string fields.
This commit is contained in:
@@ -74,8 +74,11 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
|
|||||||
var fieldName = _.keys(sortObj)[0];
|
var fieldName = _.keys(sortObj)[0];
|
||||||
results = _.sortBy(results, function(doc) {
|
results = _.sortBy(results, function(doc) {
|
||||||
var _out = doc[fieldName];
|
var _out = doc[fieldName];
|
||||||
return (sortObj[fieldName].order == 'asc') ? _out : -1*_out;
|
return _out;
|
||||||
});
|
});
|
||||||
|
if (sortObj[fieldName].order == 'desc') {
|
||||||
|
results.reverse();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
var total = results.length;
|
var total = results.length;
|
||||||
var facets = this.computeFacets(results, queryObj);
|
var facets = this.computeFacets(results, queryObj);
|
||||||
|
|||||||
@@ -44,6 +44,22 @@ test('query sort', function () {
|
|||||||
};
|
};
|
||||||
var out = data.query(queryObj);
|
var out = data.query(queryObj);
|
||||||
equal(out.records[0].x, 6);
|
equal(out.records[0].x, 6);
|
||||||
|
|
||||||
|
var queryObj = {
|
||||||
|
sort: [
|
||||||
|
{'country': {order: 'desc'}}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
var out = data.query(queryObj);
|
||||||
|
equal(out.records[0].country, 'US');
|
||||||
|
|
||||||
|
var queryObj = {
|
||||||
|
sort: [
|
||||||
|
{'country': {order: 'asc'}}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
var out = data.query(queryObj);
|
||||||
|
equal(out.records[0].country, 'DE');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('query string', function () {
|
test('query string', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user