Merge branch 'master' into 217-ckan-backend
This commit is contained in:
@@ -119,6 +119,19 @@ this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {};
|
||||
return out;
|
||||
},
|
||||
|
||||
// convert from Recline sort structure to ES form
|
||||
// http://www.elasticsearch.org/guide/reference/api/search/sort.html
|
||||
this._normalizeSort = function(sort) {
|
||||
var out = _.map(sort, function(sortObj) {
|
||||
var _tmp = {};
|
||||
var _tmp2 = _.clone(sortObj);
|
||||
delete _tmp2['field'];
|
||||
_tmp[sortObj.field] = _tmp2;
|
||||
return _tmp;
|
||||
});
|
||||
return out;
|
||||
},
|
||||
|
||||
this._convertFilter = function(filter) {
|
||||
var out = {};
|
||||
out[filter.type] = {}
|
||||
@@ -137,10 +150,12 @@ this.recline.Backend.ElasticSearch = this.recline.Backend.ElasticSearch || {};
|
||||
// @return deferred supporting promise API
|
||||
this.query = function(queryObj) {
|
||||
var esQuery = (queryObj && queryObj.toJSON) ? queryObj.toJSON() : _.extend({}, queryObj);
|
||||
var queryNormalized = this._normalizeQuery(queryObj);
|
||||
esQuery.query = this._normalizeQuery(queryObj);
|
||||
delete esQuery.q;
|
||||
delete esQuery.filters;
|
||||
esQuery.query = queryNormalized;
|
||||
if (esQuery.sort && esQuery.sort.length > 0) {
|
||||
esQuery.sort = this._normalizeSort(esQuery.sort);
|
||||
}
|
||||
var data = {source: JSON.stringify(esQuery)};
|
||||
var url = this.endpoint + '/_search';
|
||||
var jqxhr = makeRequest({
|
||||
|
||||
@@ -67,14 +67,15 @@ this.recline.Backend.Memory = this.recline.Backend.Memory || {};
|
||||
results = this._applyFilters(results, queryObj);
|
||||
results = this._applyFreeTextQuery(results, queryObj);
|
||||
|
||||
// not complete sorting!
|
||||
// TODO: this is not complete sorting!
|
||||
// What's wrong is we sort on the *last* entry in the sort list if there are multiple sort criteria
|
||||
_.each(queryObj.sort, function(sortObj) {
|
||||
var fieldName = _.keys(sortObj)[0];
|
||||
var fieldName = sortObj.field;
|
||||
results = _.sortBy(results, function(doc) {
|
||||
var _out = doc[fieldName];
|
||||
return _out;
|
||||
});
|
||||
if (sortObj[fieldName].order == 'desc') {
|
||||
if (sortObj.order == 'desc') {
|
||||
results.reverse();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -119,15 +119,17 @@ my.SlickGrid = Backbone.View.extend({
|
||||
// Column sorting
|
||||
var sortInfo = this.model.queryState.get('sort');
|
||||
if (sortInfo){
|
||||
var column = _.keys(sortInfo[0])[0];
|
||||
var sortAsc = !(sortInfo[0][column].order == 'desc');
|
||||
var column = sortInfo[0].field;
|
||||
var sortAsc = !(sortInfo[0].order == 'desc');
|
||||
this.grid.setSortColumn(column, sortAsc);
|
||||
}
|
||||
|
||||
this.grid.onSort.subscribe(function(e, args){
|
||||
var order = (args.sortAsc) ? 'asc':'desc';
|
||||
var sort = [{}];
|
||||
sort[0][args.sortCol.field] = {order: order};
|
||||
var sort = [{
|
||||
field: args.sortCol.field,
|
||||
order: order
|
||||
}];
|
||||
self.model.query({sort: sort});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user