Skip to content

Commit

Permalink
Implemented geolocation sorting KR-256
Browse files Browse the repository at this point in the history
  • Loading branch information
Razvan Botea committed Mar 25, 2016
1 parent 54ffc25 commit 9436765
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/database/elasticsearch_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 9436765

Please sign in to comment.