Add query param to define the number of categories to be ranked
This commit is contained in:
parent
50ecdb5fee
commit
743bb0723b
@ -94,7 +94,7 @@ function getQueryRewriteData(mapConfig, dataviewDefinition, params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getOverrideParams(params, ownFilter) {
|
function getOverrideParams(params, ownFilter) {
|
||||||
var overrideParams = _.reduce(_.pick(params, 'start', 'end', 'bins', 'offset'),
|
var overrideParams = _.reduce(_.pick(params, 'start', 'end', 'bins', 'offset', 'categories'),
|
||||||
function castNumbers(overrides, val, k) {
|
function castNumbers(overrides, val, k) {
|
||||||
if (!Number.isFinite(+val)) {
|
if (!Number.isFinite(+val)) {
|
||||||
throw new Error('Invalid number format for parameter \'' + k + '\'');
|
throw new Error('Invalid number format for parameter \'' + k + '\'');
|
||||||
|
@ -109,7 +109,8 @@ LayergroupController.prototype.register = function(app) {
|
|||||||
'bins', // number
|
'bins', // number
|
||||||
'aggregation', //string
|
'aggregation', //string
|
||||||
'offset', // number
|
'offset', // number
|
||||||
'q' // widgets search
|
'q', // widgets search
|
||||||
|
'categories', // number
|
||||||
];
|
];
|
||||||
|
|
||||||
app.get(
|
app.get(
|
||||||
|
@ -245,6 +245,10 @@ module.exports = class Aggregation extends BaseDataview {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const limit = Number.isFinite(override.categories) && override.categories > 0 ?
|
||||||
|
override.categories :
|
||||||
|
CATEGORIES_LIMIT;
|
||||||
|
|
||||||
const aggregationSql = aggregationDataviewQueryTpl({
|
const aggregationSql = aggregationDataviewQueryTpl({
|
||||||
override: override,
|
override: override,
|
||||||
query: this.query,
|
query: this.query,
|
||||||
@ -256,7 +260,7 @@ module.exports = class Aggregation extends BaseDataview {
|
|||||||
aggregationColumn: this.aggregationColumn || 1
|
aggregationColumn: this.aggregationColumn || 1
|
||||||
}),
|
}),
|
||||||
isFloatColumn: this._isFloatColumn,
|
isFloatColumn: this._isFloatColumn,
|
||||||
limit: CATEGORIES_LIMIT
|
limit
|
||||||
});
|
});
|
||||||
|
|
||||||
debug(aggregationSql);
|
debug(aggregationSql);
|
||||||
|
@ -325,7 +325,7 @@ describe('aggregation-dataview: special float values', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('categories param', function () {
|
describe('aggregation dataview tuned by categories query param', function () {
|
||||||
afterEach(function(done) {
|
afterEach(function(done) {
|
||||||
if (this.testClient) {
|
if (this.testClient) {
|
||||||
this.testClient.drain(done);
|
this.testClient.drain(done);
|
||||||
@ -388,16 +388,41 @@ describe('categories param', function () {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
it('should accept cartegories param to customize aggregation dataview', function (done) {
|
var scenarios = [
|
||||||
this.testClient = new TestClient(mapConfig, 1234);
|
{
|
||||||
const params = {
|
params: { own_filter: 0, categories: -1 },
|
||||||
categories: 2
|
categoriesExpected: 4
|
||||||
};
|
},
|
||||||
|
{
|
||||||
|
params: { own_filter: 0, categories: 0 },
|
||||||
|
categoriesExpected: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
params: { own_filter: 0, categories: 1 },
|
||||||
|
categoriesExpected: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
params: { own_filter: 0, categories: 2 },
|
||||||
|
categoriesExpected: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
params: { own_filter: 0, categories: 4 },
|
||||||
|
categoriesExpected: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
params: { own_filter: 0, categories: 5 },
|
||||||
|
categoriesExpected: 4
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
this.testClient.getDataview('categories', params, (err, dataview) => {
|
scenarios.forEach(function (scenario) {
|
||||||
assert.ifError(err);
|
it(`should handle cartegories to customize aggregations: ${JSON.stringify(scenario.params)}`, function (done) {
|
||||||
assert.equal(dataview.categoriesCount, 2);
|
this.testClient = new TestClient(mapConfig, 1234);
|
||||||
done();
|
this.testClient.getDataview('categories', scenario.params, (err, dataview) => {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.equal(dataview.categories.length, scenario.categoriesExpected);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -415,7 +415,7 @@ TestClient.prototype.getDataview = function(dataviewName, params, callback) {
|
|||||||
own_filter: params.hasOwnProperty('own_filter') ? params.own_filter : 1
|
own_filter: params.hasOwnProperty('own_filter') ? params.own_filter : 1
|
||||||
};
|
};
|
||||||
|
|
||||||
['bbox', 'bins', 'start', 'end', 'aggregation', 'offset'].forEach(function(extraParam) {
|
['bbox', 'bins', 'start', 'end', 'aggregation', 'offset', 'categories'].forEach(function(extraParam) {
|
||||||
if (params.hasOwnProperty(extraParam)) {
|
if (params.hasOwnProperty(extraParam)) {
|
||||||
urlParams[extraParam] = params[extraParam];
|
urlParams[extraParam] = params[extraParam];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user