[#217] Implement value/term filter for ckan backend

This commit is contained in:
John Glover 2013-03-27 19:58:15 +01:00
parent 0d3db924ad
commit d0f82fd165
2 changed files with 15 additions and 5 deletions

View File

@ -66,15 +66,25 @@ this.recline.Backend.Ckan = this.recline.Backend.Ckan || {};
var actualQuery = {
resource_id: dataset.id,
q: queryObj.q,
filters: {},
limit: queryObj.size || 10,
offset: queryObj.from || 0
};
if (queryObj.sort && queryObj.sort.length > 0) {
var _tmp = _.map(queryObj.sort, function(sortObj) {
return sortObj.field + ' ' + (sortObj.order || '');
});
actualQuery.sort = _tmp.join(',');
}
if (queryObj.filters && queryObj.filters.length > 0) {
_.each(queryObj.filters, function(filter) {
if (filter.type === "term") {
actualQuery.filters[filter.field] = filter.term;
}
});
}
return actualQuery;
};
@ -105,15 +115,14 @@ this.recline.Backend.Ckan = this.recline.Backend.Ckan || {};
//
// @param endpoint: CKAN api endpoint (e.g. http://datahub.io/api)
my.DataStore = function(endpoint) {
var that = {
endpoint: endpoint || my.API_ENDPOINT
};
var that = {endpoint: endpoint || my.API_ENDPOINT};
that.search = function(data) {
var searchUrl = that.endpoint + '/3/action/datastore_search';
var jqxhr = jQuery.ajax({
url: searchUrl,
data: data,
dataType: 'json'
type: 'POST',
data: JSON.stringify(data)
});
return jqxhr;
};

View File

@ -30,6 +30,7 @@ test('_normalizeQuery', function() {
var exp = {
resource_id: dataset.id,
q: 'abc',
filters: {},
sort: 'location desc,last ',
limit: 10,
offset: 0