 (defn get-tags-mentions-matches
   "Extract matching timestamps for query."
   [g query]
-  (let [t-matched (map #(set (map :dest (uber/find-edges g {:src          {:tag %}
-                                                            :relationship :CONTAINS})))
-                       (:tags query))
-        m-matched (map #(set (map :dest (uber/find-edges g {:src          {:mention %}
-                                                            :relationship :CONTAINS})))
-                       (:mentions query))]
+  (let [mapper (fn [tag-type]
+                 (fn [tag]
+                   (set (map :dest (uber/find-edges g {:src          {tag-type tag}
+                                                       :relationship :CONTAINS})))))
+        t-matched (map (mapper :tag) (map s/lower-case (:tags query)))
+        m-matched (map (mapper :mention) (map s/lower-case (:mentions query)))]
     (apply set/intersection
            (concat t-matched m-matched))))
 

  [graph entry]
  (let [mentions (:mentions entry)]
    (reduce (fn [acc mention]
              (let [mention (s/lower-case mention)]
                (-> acc
                    (uber/add-nodes :mentions {:mention mention})
                    (uber/add-edges
                      [{:mention mention} (:timestamp entry) {:relationship :CONTAINS}]
                      [:mentions {:mention mention} {:relationship :IS}]))))
            graph
            mentions)))


  "Finds all hashtags used in entries by finding the edges that originate from the
  :hashtags node."
  [current-state]
  (let [g (:graph current-state)
        ltags (map #(-> % :dest :tag) (uber/find-edges g {:src :hashtags}))
        tags (map #(:val (uber/attrs g {:tag %})) ltags)]
    (set tags)))

(defn find-all-mentions
  "Finds all hashtags used in entries by finding the edges that originate from the
  :hashtags node."
  [current-state]
  (let [g (:graph current-state)
        lmentions (map #(-> % :dest :mention) (uber/find-edges g {:src :mentions}))
        mentions (map #(:val (uber/attrs g {:mention %})) lmentions)]
    (set mentions)))

(defn get-basic-stats
  "Generate some very basic stats about the graph size for display in UI."
