From 9436765fc43dd59583513781327366634f258377 Mon Sep 17 00:00:00 2001 From: Razvan Botea Date: Fri, 25 Mar 2016 14:42:18 +0200 Subject: [PATCH] Implemented geolocation sorting KR-256 --- lib/database/elasticsearch_adapter.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/database/elasticsearch_adapter.js b/lib/database/elasticsearch_adapter.js index 1b841b5..641f5b3 100644 --- a/lib/database/elasticsearch_adapter.js +++ b/lib/database/elasticsearch_adapter.js @@ -1080,7 +1080,15 @@ ElasticSearchDB.prototype.modelSearch = function(channel, sort, offset, limit, c } if (sort) { - elasticSearchQuery.sort = [sort]; + elasticSearchQuery.sort = {}; + + if (sort.type == 'default') { + elasticSearchQuery.sort[sort.field] = sort.order; + } else if (sort.type == 'geo') { + elasticSearchQuery.sort._geo_distance = {}; + elasticSearchQuery.sort._geo_distance[sort.field] = {lat: sort.poi.lat || 0.0, lon: sort.poi.long || 0.0}; + elasticSearchQuery.sort._geo_distance.order = sort.order; + } } this.connection.search({