<commit_before>(ns sound-effector.models.sound-effect
  (:require [clojure.java.jdbc :as sql]
            [clojurewerkz.elastisch.rest :as esr]
            [clojurewerkz.elastisch.rest.document :as esd]
            [clojurewerkz.elastisch.query :as esq]
            [sound-effector.core :refer [db-spec es-spec]]))

(defn search [query]
  (loop [hits (:hits (:hits (esd/search (esr/connect es-spec)
                                        "sound_effector"
                                        "sound_effect"
                                        :query (esq/query-string {:query query}))))
         result []]
    (if (empty? hits)
      result
      (recur (next hits) (conj result (:_source (first hits)))))))

(defn create [title url]
  ; TODO: apply the transaction.
  (let [sound-effect (first (sql/insert! db-spec :sound_effects {:title title :url url}))]
    (esd/create (esr/connect es-spec)
                "sound_effector"
                "sound_effect"
                sound-effect
                :id (str (:id sound-effect)))))

(defn read
  ([]
   (into [] (sql/query db-spec ["SELECT * FROM sound_effects ORDER BY id DESC"])))
  ([id]
   (sql/query db-spec ["SELECT * FROM sound_effects WHERE id = ?" id])))

(defn delete [id]
  ; TODO: apply the transaction.
  (esd/delete (esr/connect es-spec) "sound_effector" "sound_effect" (str id))
  (sql/delete! db-spec :sound_effects ["id = ?" id]))
<commit_msg>Fixed to return only one result.<commit_after>(ns sound-effector.models.sound-effect
  (:require [clojure.java.jdbc :as sql]
            [clojurewerkz.elastisch.rest :as esr]
            [clojurewerkz.elastisch.rest.document :as esd]
            [clojurewerkz.elastisch.query :as esq]
            [sound-effector.core :refer [db-spec es-spec]]))

(defn search [query]
  (loop [hits (:hits (:hits (esd/search (esr/connect es-spec)
                                        "sound_effector"
                                        "sound_effect"
                                        :query (esq/query-string {:query query}))))
         result []]
    (if (empty? hits)
      result
      (recur (next hits) (conj result (:_source (first hits)))))))

(defn create [title url]
  ; TODO: apply the transaction.
  (let [sound-effect (first (sql/insert! db-spec :sound_effects {:title title :url url}))]
    (esd/create (esr/connect es-spec)
                "sound_effector"
                "sound_effect"
                sound-effect
                :id (str (:id sound-effect)))))

(defn read
  ([]
   (into [] (sql/query db-spec ["SELECT * FROM sound_effects ORDER BY id DESC"])))
  ([id]
   (first (sql/query db-spec ["SELECT * FROM sound_effects WHERE id = ?" id]))))

(defn delete [id]
  ; TODO: apply the transaction.
  (esd/delete (esr/connect es-spec) "sound_effector" "sound_effect" (str id))
  (sql/delete! db-spec :sound_effects ["id = ?" id]))

{'fraction_non_alphanumeric': 0.14156521739130434, 'fraction_numerical': 0.0, 'mean_word_length': 2.119305856832972, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1781584', 'n_tokens_mistral': 942, 'n_tokens_neox': 909, 'n_words': 238}