              ;; because of the size=2 cut
              [k (limit (input-facet-settings input (keyword k))
                        v
-                       :count)])))
-
+                       by-count)])))
 
 (defn result-reducer [sum next]
   (let [next (if (future? next)

                              true)
    (TopScoreDocCollector/create pq-size true)))

(defn limit
  ([input hits sort-key] (limit input hits sort-key #(compare %2 %1)))
  ([input hits sort-key comparator]
     (let [size (get input :size default-size)
           sorted (sort-by sort-key comparator hits)]
       (if (and  (> (count hits) size)
                 (get input :enforce-limits true))
         (subvec (vec sorted) 0 size)
         sorted))))

(defn concat-facets [big small]
  (if (not big)

    (-> result
        (assoc-in [:facets] (merge-and-limit-facets input (:facets result)))
        (assoc-in [:hits] (if (:sort input)
                            (limit input (:hits result) by-abs-position-score)
                            (limit input (:hits result) by-score)))
        (assoc-in [:took] (time-took ms-start)))))

(defn shard-search
