[#240,bugfix,backend/memory][s]: range filters now work as expected when one end of range is null - fixes #240.
* see ticket and comments for more details
This commit is contained in:
parent
7819b3b185
commit
046ee8c1a0
@ -134,12 +134,19 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
|
||||
}
|
||||
|
||||
function range(record, filter) {
|
||||
var startnull = (filter.start == null || filter.start === '');
|
||||
var stopnull = (filter.stop == null || filter.stop === '');
|
||||
var parse = getDataParser(filter);
|
||||
var value = parse(record[filter.field]);
|
||||
var start = parse(filter.start);
|
||||
var stop = parse(filter.stop);
|
||||
|
||||
return (value >= start && value <= stop);
|
||||
// if at least one end of range is set do not allow '' to get through
|
||||
// note that for strings '' <= {any-character} e.g. '' <= 'a'
|
||||
if ((!startnull || !stopnull) && value === '') {
|
||||
return false;
|
||||
}
|
||||
return ((startnull || value >= start) && (stopnull || value <= stop));
|
||||
}
|
||||
|
||||
function geo_distance() {
|
||||
|
||||
@ -114,6 +114,42 @@ test('filters', function () {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('filters with nulls', function () {
|
||||
var data = _wrapData();
|
||||
|
||||
query = new recline.Model.Query();
|
||||
query.addFilter({type: 'range', field: 'z', start: '', stop: null});
|
||||
data.query(query.toJSON()).then(function(out) {
|
||||
equal(out.total, 6);
|
||||
});
|
||||
|
||||
query = new recline.Model.Query();
|
||||
query.addFilter({type: 'range', field: 'x', start: '', stop: '3'});
|
||||
data.query(query.toJSON()).then(function(out) {
|
||||
equal(out.total, 3);
|
||||
});
|
||||
|
||||
query = new recline.Model.Query();
|
||||
query.addFilter({type: 'range', field: 'x', start: '3', stop: ''});
|
||||
data.query(query.toJSON()).then(function(out) {
|
||||
equal(out.total, 4);
|
||||
});
|
||||
|
||||
data.data[5].country = '';
|
||||
query = new recline.Model.Query();
|
||||
query.addFilter({type: 'range', field: 'country', start: '', stop: 'Z'});
|
||||
data.query(query.toJSON()).then(function(out) {
|
||||
equal(out.total, 5);
|
||||
});
|
||||
|
||||
query = new recline.Model.Query();
|
||||
query.addFilter({type: 'range', field: 'x', start: '', stop: ''});
|
||||
data.query(query.toJSON()).then(function(out) {
|
||||
equal(out.total, 6);
|
||||
});
|
||||
});
|
||||
|
||||
test('facet', function () {
|
||||
var data = _wrapData();
|
||||
var query = new recline.Model.Query();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user