clojurewerkz/elastisch — pull request #49 by marklar (2013-12-04 00:01:03+00:00)
Title: For sorting with the native client, allow the use of SortBuilders.

Modify elastisch.native.conversion/set-sort to accept a SortBuilder for its "sort" argument.

For example, we pass in a GeoDistanceSortBuilder, which we make like this:

(ns some-module
"Example of making a GeoDistanceSortBuilder."
(:import [org.elasticsearch.search.sort GeoDistanceSortBuilder SortOrder]
[org.elasticsearch.common.unit DistanceUnit]))

(defn mk-geo-distance-sort-builder
"Inputs:
* a {:lat, :lon} hashmap
* sort-order keyword (either :asc or :desc)
Create a GeoDistanceSortBuilder."
[coords order]
(let [o (if (= order :asc) SortOrder/ASC SortOrder/DESC)
sb (GeoDistanceSortBuilder. "latitude_longitude")]
(doto sb
(.point (:lat coords) (:lon coords))
(.order o)
(.unit DistanceUnit/MILES))
sb))

If you find that code useful, please feel free to make use of it as well.