<commit_before>(ns ctia.stores.es.feedback
  (:import java.util.UUID)
  (:require
   [schema.core :as s]
   [ctia.schemas.feedback :refer [Feedback
                                 NewFeedback
                                 realize-feedback]]
   [ctia.stores.es.document :refer [create-doc
                                   delete-doc
                                   search-docs]]))

(def ^{:private true} mapping "feedback")

(defn handle-create-feedback [state realized-new-feedback _ _]
  (create-doc (:conn state)
              (:index state)
              mapping
              realized-new-feedback))

(defn handle-delete-feedback [state id]
  (delete-doc (:conn state)
              (:index state)
              mapping
              id))

(defn handle-list-feedback [state filter-map]
  (search-docs (:conn state)
               (:index state)
               mapping
               filter-map))<commit_msg>Feedback ES coercion<commit_after>(ns ctia.stores.es.feedback
  (:import java.util.UUID)
  (:require
   [schema.core :as s]
   [schema.coerce :as c]
   [ring.swagger.coerce :as sc]
   [ctia.schemas.feedback :refer [Feedback
                                  NewFeedback
                                  StoredFeedback
                                  realize-feedback]]
   [ctia.stores.es.document :refer [create-doc
                                    delete-doc
                                    search-docs]]))

(def ^{:private true} mapping "feedback")

(def coerce-stored-feedback
  (c/coercer! (s/maybe StoredFeedback)
              sc/json-schema-coercion-matcher))

(defn handle-create-feedback [state realized-new-feedback _ _]
  (-> (create-doc (:conn state)
                  (:index state)
                  mapping
                  realized-new-feedback)
      coerce-stored-feedback))

(defn handle-delete-feedback [state id]
  (delete-doc (:conn state)
              (:index state)
              mapping
              id))

(defn handle-list-feedback [state filter-map]
  (->> (search-docs (:conn state)
                    (:index state)
                    mapping
                    filter-map)
       (map coerce-stored-feedback)))
{'fraction_non_alphanumeric': 0.10799632352941177, 'fraction_numerical': 0.0, 'mean_word_length': 1.4488188976377954, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4603191', 'n_tokens_mistral': 646, 'n_tokens_neox': 594, 'n_words': 129}