(cloud) Saving things now update the search index

This commit is contained in:
2023-05-04 21:23:09 -07:00
parent 4e7e19da97
commit 14156e6ced
6 changed files with 71 additions and 38 deletions

View File

@@ -1,13 +1,13 @@
(ns auto-ap.solr
(:require
[auto-ap.datomic :refer [conn]]
[clj-http.client :as client]
[clojure.data.json :as json]
[config.core :refer [env]]
[datomic.api :as dc]
[clj-time.coerce :as c]
[auto-ap.datomic :refer [conn pull-id]]
[auto-ap.time :as atime]
[clojure.string :as str]))
[clj-http.client :as client]
[clj-time.coerce :as c]
[clojure.data.json :as json]
[clojure.string :as str]
[config.core :refer [env]]
[datomic.api :as dc]))
(def solr-uri (:solr-uri env))
@@ -34,8 +34,7 @@
"journal-entry"
:else
(throw (ex-info "Trying to index unknown entity"
{:id d}))))))
nil))))
(defmethod datomic->solr "transaction" [d]
(let [i (dc/pull (dc/db conn) '[:db/id :transaction/description-original
@@ -54,6 +53,9 @@
"vendor_id" (-> i :transaction/vendor :db/id)
"type" "transaction"}))
(defmethod datomic->solr nil [d]
nil)
(defmethod datomic->solr "journal-entry" [d]
(let [i (dc/pull (dc/db conn) '[:db/id
:journal-entry/amount
@@ -123,7 +125,7 @@
:socket-timeout 30000
:connection-timeout 30000
:method "POST"
:body (json/write-str (map datomic->solr xs))}))
:body (json/write-str (filter identity (map datomic->solr xs)))}))
(defn query [q]
(-> (client/post (str solr-uri "/solr/invoices/query")
@@ -145,3 +147,13 @@
:method "POST"
:body (json/write-str {"delete" {"query" "*:*"}})})
)
(defn touch-with-ledger [i]
(index-documents [i
(pull-id (dc/db conn) [:journal-entry/original-entity i])]))
(defn touch [i]
(index-documents [i]))