 (ns org.altlaw.www.SearchResource
   (:require [org.altlaw.www.render :as tmpl]
+            [org.altlaw.www.references :as r]
+            [org.altlaw.www.pagination :as p]
             [org.altlaw.util.date :as date]
             [org.altlaw.util.courts :as courts]
             [org.altlaw.util.context :as context]


(defn make-sortlinks [ref sort]
  (cond
   (= sort "score desc") [{:url (sort-ref ref "date") :name "Sort by date"}]
   (= sort "date desc") [{:url (sort-ref ref "relevance") :name "Sort by relevance"}]))

(defmulti render-results (fn [this variant data] (.getMediaType variant)))

(defmethod render-results MediaType/TEXT_HTML [this variant data]
  (let [ref (.. this getRequest getOriginalRef)
        ;; Do not display "relevance" sort link when using 'all' query
        data (if (= (:query data) "docid:[* TO *]")
               data
               (assoc data
                 :order (order-for-display (:sort data))
                 :sortlinks (make-sortlinks ref (:sort data))))]
    (StringRepresentation.
     (html-results ref data)
     MediaType/TEXT_HTML
     Language/ENGLISH_US
     CharacterSet/UTF_8)))


     (into-array ["doctype" "docid" "name" "citations"
                  "date" "court" "size"]))

(defn apply-page-options [this solr-query]
  (let [params (get-query-params this)
        page (if-let [p (.get params "page")]
               (Integer/parseInt p) 1)]
    (.setStart solr-query (* p/*page-size* (dec page)))))

(defn execute-search [this solr-query]
  (let [solr (.. this getContext getAttributes (get "org.altlaw.solr.server"))]
