                                     "yyyy"))
 
 (defn parse-date [val] (format/parse multi-parser val))
+
+(defn parse-long [val]
+    (try
+      (Long/valueOf val)
+    (catch Exception exception
+      (.info logger (str exception " with " val))
+      0)))
 
 (defn conv-fun [sport-key]
 	(if (sport-key #{:distance :duration})

	(:require 	[clj-time.format :as format]
				[clojure.string :as string]
			  	[clj-time.core :as time]))

(def multi-parser (format/formatter (time/default-time-zone)
                                    "dd.MM.yyyy"

(defn make-basic-query [query-keys]
	(vec (map (partial apply or-filter) query-keys)))

(defn long-cmp-keys[]
	(vec (for [op ["lte" "gte" "lt" "gt"] qkey ["pace" "distance" "duration" "avghr"]]
		(keyword (str op "_" qkey)))))

(defn make-query-from [params]
  (let [basic-query (make-basic-query (select-keys params [:user :tags :sport :distance :duration]))
  		date-range-query (make-range-query parse-date (select-keys params [:lte_creationDate :gte_creationDate]))
  		long-range-query (make-range-query parse-long (select-keys params (long-cmp-keys)))]
  	{$and (vec (concat basic-query date-range-query long-range-query))}))

(defn sortby [params]
	(if-let [sortkey (:sb params)]
