 (ns lcmap.aardvark.tile-spec-index
-  "Search index for tile-spec ubids (universal band ids)."
+  "Search index for tile-specs"
   (:require [lcmap.aardvark.config :refer [config]]
             [lcmap.aardvark.es :as es]
             [lcmap.aardvark.tile-spec :as tile-spec]

  (str (url) "/_search"))

(defn +tags
  "Creates additional tags from a ubid"
  [tile-spec]
  (let [ubid-tags (str/split (:ubid tile-spec) #"/|_")]
    (if (> (count ubid-tags) 1)

   (es/search api-url query (get-in config [:search :max-result-size]))))

(defn result
  "Extracts tile-specs from search results"
  [search-results]
  (map #(get % "_source")
       (get-in search-results ["hits" "hits"])))

(defn save
  "Saves tile-specs to the ElasticSearch index."
  [tile-specs]
  (log/debugf "creating index entry(s) for %s" tile-specs)
  (es/load! (bulk-api-url)
