This commit is contained in:
Bryce
2023-05-18 22:06:05 -07:00
206 changed files with 36447 additions and 387 deletions

View File

@@ -9,11 +9,12 @@
pull-many
query2]]
[auto-ap.graphql.utils :refer [limited-clients]]
[auto-ap.search :as search]
[clj-time.coerce :as coerce]
[clojure.string :as str]
[com.brunobonacci.mulog :as mu]
[datomic.api :as dc]))
[datomic.api :as dc]
[clj-http.client :as client]
[auto-ap.solr :as solr]))
(def full-read '[*
{:client/square-integration-status [:integration-status/message
@@ -107,23 +108,38 @@
(first)))
(defn best-match [identifier]
(first (search/search-ids {:q (str/replace identifier #"[\(\)\-/\*\]\[\#:\&]" " ")} "client")))
(when (and identifier (not-empty identifier))
(some-> (solr/query solr/impl "clients"
{"query" (format "_text_:\"%s\"" (str/upper-case (solr/escape identifier)))
"fields" "id"})
first
:id
Long/parseLong)))
(defn exact-match [identifier]
(first (search/search-ids {:exact-match (str/upper-case identifier)} "client")))
(when (and identifier (not-empty identifier))
(some-> (solr/query solr/impl "clients"
{"query" (format "exact:\"%s\"" (str/upper-case (solr/escape identifier)))
"fields" "id"})
first
:id
Long/parseLong)))
(defn rebuild-search-index []
(search/full-index-query
(for [result (map first (dc/q '[:find (pull ?v [:client/name :client/matches :db/id])
:in $
:where [?v :client/code]]
(dc/db conn)))
match (conj (or (:client/matches result) [])
(:client/name result))]
{:id (:db/id result)
:text match
:exact-match (str/upper-case match)})
"client"))
(solr/index-documents-raw solr/impl
"clients"
(for [result (map first (dc/q '[:find (pull ?v [:client/name :client/matches :db/id :client/code])
:in $
:where [?v :client/code]]
(dc/db conn)))
:let [matches (conj (or (:client/matches result) [])
(:client/name result))]]
{"id" (:db/id result)
"name" matches
"code" (:client/code result)
"exact" (map str/upper-case matches)})))
(defn raw-graphql-ids [db args]

View File

@@ -7,16 +7,16 @@
<-graphql
assert-admin
assert-can-see-client
can-see-client?
cleanse-query
enum->keyword
is-admin?
limited-clients
result->page]]
[auto-ap.search :as search]
[auto-ap.utils :refer [heartbeat]]
[auto-ap.solr :as solr]
[datomic.api :as dc]
[iol-ion.tx :refer [random-tempid]]
[mount.core :as mount]
[yang.scheduler :as scheduler]))
[com.brunobonacci.mulog :as mu]))
(defn get-graphql [context args _]
(assert-admin (:id context))
@@ -68,9 +68,29 @@
:account-client-override/search-terms (:name client-override)})
client-overrides)}
id (dissoc :account/numeric-code :account/code))]]
(:id context))]
(:id context))
updated-account (d-accounts/get-by-id (or id (get-in result [:tempids "new-account"])))]
(mu/log ::account-updated :account updated-account)
(solr/index-documents-raw solr/impl
"accounts"
(into [{"id" (:db/id updated-account)
"account_id" (:db/id updated-account)
"name" (:account/name updated-account)
"numeric_code" (:account/numeric-code updated-account)
"location" (:account/location updated-account)
"applicability" (clojure.core/name (:account/applicability updated-account))}]
(for [o (:account/client-overrides updated-account)]
{"id" (:db/id o)
"account_id" (:db/id updated-account)
"name" (:account-client-override/name o)
"numeric_code" (:account/numeric-code updated-account)
"location" (:account/location updated-account)
"applicability" (clojure.core/name (:account/applicability updated-account))
"client_id" (:db/id (:account-client-override/client o))
"account_client_override_id" (:db/id o)}))
)
(->graphql
(d-accounts/get-by-id (or id (get-in result [:tempids "new-account"])))))))
updated-account))))
(def search-pattern [:db/id
:account/numeric-code
@@ -78,12 +98,25 @@
{:account/vendor-allowance [:db/ident]
:account/default-allowance [:db/ident]
:account/invoice-allowance [:db/ident]}])
(defn search- [id query client]
(let [client-part (if (some->> client (can-see-client? id))
(format "((applicability:(global OR optional) AND -client_id:*) OR (account_client_override_id:* AND client_id:%s))" client)
"(applicability:(global OR optional) AND -client_id:*)"
)
query (format "_text_:(%s) AND %s" (cleanse-query query) client-part)]
(mu/log ::searching :search-query query)
(for [{:keys [account_id name] :as g} (solr/query solr/impl "accounts"
{"query" query
"fields" "id, name, client_id, numeric_code, applicability, account_id"})]
{:account_id (first account_id)
:name (first name)})))
(defn search [context {query :query client :client_id allowance :allowance vendor-id :vendor_id} _]
(when client
(assert-can-see-client (:id context) client))
(let [query (cleanse-query query)
_ (println query)
num (some-> (re-find #"([0-9]+)" query)
(let [num (some-> (re-find #"([0-9]+)" query)
second
(not-empty )
Integer/parseInt)
@@ -130,41 +163,34 @@
allowance
search-pattern)
(sequence xform))
(->> (dc/q '[:find ?n (pull ?i pattern) ?s
:in $ [[?i ?n ?s]] pattern
:where (or [?i :account/applicability :account-applicability/global]
[?i :account/applicability :account-applicability/optional])]
(dc/db conn)
(search/search {:q query} "account")
search-pattern)
(concat (when client
(dc/q '[:find ?n (pull ?i pattern) ?s
:in $ [[?i ?n ?s]] pattern]
(dc/db conn)
(search/search {:q query :client (str client)} "account-client-override")
search-pattern)))
(sort-by (comp - last))
(sequence xform)))
(->> (search- (:id context) query client)
(sequence
(comp (map (fn [i] [(:name i) (dc/pull (dc/db conn) search-pattern (:account_id i))]))
xform))))
[])))
(defn rebuild-search-index []
(search/full-index-query
(for [result (map first (dc/qseq {:query '[:find (pull ?aco [:account-client-override/search-terms :account-client-override/client :db/id {:account/_client-overrides [:account/numeric-code :account/location :db/id]}])
(solr/index-documents-raw
solr/impl
"accounts"
(for [result (map first (dc/qseq {:query '[:find (pull ?aco [:account-client-override/search-terms :account-client-override/client :db/id {:account/_client-overrides [:account/numeric-code :account/location :db/id {:account/applicability [:db/ident]}]}])
:in $
:where [?aco :account-client-override/client ]
[?aco :account-client-override/search-terms ]
[_ :account/client-overrides ?aco]]
:args [(dc/db conn)]}))
:when (:account/numeric-code (:account/_client-overrides result))]
{:id (:db/id (:account/_client-overrides result))
:account-client-override-id (:db/id result)
:text (:account-client-override/search-terms result)
:client (str (:db/id (:account-client-override/client result)))
:numeric-code (:account/numeric-code (:account/_client-overrides result))
:location (:account/location (:account/_client-overrides result))})
"account-client-override")
(search/full-index-query
:when (:account/numeric-code (:account/_client-overrides result))]
{"id" (:db/id result)
"account_id" (:db/id (:account/_client-overrides result))
"account_client_override_id" (str (:db/id result))
"name" (:account-client-override/search-terms result)
"client_id" (str (:db/id (:account-client-override/client result)))
"numeric_code" (:account/numeric-code (:account/_client-overrides result))
"location" (:account/location (:account/_client-overrides result))
"applicability" (name (:db/ident (:account/applicability (:account/_client-overrides result))))}))
(solr/index-documents-raw
solr/impl
"accounts"
(for [result (map first (dc/qseq {:query '[:find (pull ?a [:account/numeric-code
:account/search-terms
{:account/applicability [:db/ident]}
@@ -173,14 +199,14 @@
:in $
:where [?a :account/search-terms ]]
:args [(dc/db conn)]}))
:when (:account/search-terms result)
:when (:account/search-terms result)
]
{:id (:db/id result)
:text (:account/search-terms result)
:numeric-code (:account/numeric-code result)
:location (:account/location result)
:applicability (name (:db/ident (:account/applicability result)))})
"account"))
{"id" (:db/id result)
"account_id" (:db/id result)
"name" (:account/search-terms result)
"numeric_code" (:account/numeric-code result)
"location" (:account/location result)
"applicability" (name (:db/ident (:account/applicability result)))})))
#_(dc/transact conn
[{:db/ident :account-client-override/k2
@@ -195,8 +221,3 @@
#_(dc/pull (dc/db conn) '[*] [:db/ident :account-client-override/k])
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(mount/defstate indexer
:start (scheduler/every (* 5 60 1000) (heartbeat rebuild-search-index "rebuild-search-index"))
:stop (scheduler/stop indexer))

View File

@@ -419,7 +419,7 @@
(dissoc % :payment/pdf-data)
%) checks ) id)]
(doseq [i (:tempids result)]
(doseq [[_ i] (:tempids result)]
(solr/touch-with-ledger i)))
{:invoices (d-invoices/get-multi (map :invoice-id invoice-payments))
:pdf-url (if (= type :payment-type/check)
@@ -485,7 +485,7 @@
:payment/date (c/to-date (parse (:date args) iso-date)))]
(invoice-payments invoices invoice-payment-lookup))
(:id context))]
(doseq [i (:tempids result)]
(doseq [[_ i] (:tempids result)]
(solr/touch-with-ledger i)))
(->graphql
{:s3-url nil
@@ -655,7 +655,7 @@
(let [result (audit-transact (-> []
(conj payment)
(into (invoice-payments invoices invoice-amounts))) (:id context))]
(doseq [n (:tempids result)]
(doseq [[_ n] (:tempids result)]
(solr/touch-with-ledger n)))
(->graphql {:invoices (d-invoices/get-multi (map :db/id invoices))})))

View File

@@ -24,7 +24,8 @@
[iol-ion.tx :refer [random-tempid]]
[mount.core :as mount]
[unilog.context :as lc]
[yang.scheduler :as scheduler])
[yang.scheduler :as scheduler]
[auto-ap.solr :as solr])
(:import
(java.util UUID)
(org.apache.commons.codec.binary Base64)))
@@ -156,7 +157,15 @@
result (audit-transact [[:upsert-entity updated-entity]] (:id context))]
(when (:square_auth_token edit_client)
(square/upsert-locations (-> result :tempids (get id) (or id) d-clients/get-by-id)))
(-> (-> result :tempids (get id) (or id) d-clients/get-by-id)
(let [updated-client (-> result :tempids (get id) (or id) d-clients/get-by-id)]
(solr/index-documents-raw solr/impl "clients"
[{"id" (:db/id updated-client)
"name" (conj (or (:client/matches updated-client) [])
(:client/name updated-client))
"code" (:client/code updated-client)
"exact" (map str/upper-case (conj (or (:client/matches updated-client) [])
(:client/name updated-client)))}])
(-> updated-client
(update :client/bank-accounts
(fn [bas]
@@ -165,11 +174,11 @@
(fn [lms]
(mapcat (fn [lm]
(map (fn [m]
{:location-match/match m
:location-match/location (:location-match/location lm)})
(:location-match/matches lm)))
{:location-match/match m
:location-match/location (:location-match/location lm)})
(:location-match/matches lm)))
lms)))
->graphql)))
->graphql))))
(defn refresh-all-current-balance []
@@ -629,8 +638,3 @@
:input-objects input-objects
:enums enums})
(attach-tracing-resolvers resolvers)))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(mount/defstate indexer
:start (scheduler/every (* 5 60 1000) (heartbeat d-clients/rebuild-search-index "rebuild-search-index"))
:stop (scheduler/stop indexer))

View File

@@ -1,35 +1,22 @@
(ns auto-ap.graphql.ezcater
(:require
[auto-ap.datomic :refer [conn]]
[auto-ap.graphql.utils
:refer [assert-admin attach-tracing-resolvers cleanse-query]]
[auto-ap.search :as search]
[auto-ap.utils :refer [heartbeat]]
[datomic.api :as dc]
[mount.core :as mount]
[yang.scheduler :as scheduler]))
[auto-ap.graphql.utils :refer [assert-admin attach-tracing-resolvers]]
[clojure.string :as str]
[datomic.api :as dc]))
(defn search [context args _]
(assert-admin (:id context))
(let [search-query (cleanse-query (:query args))]
(for [[id name] (search/search {:q search-query}
"ezcater-caterer")]
{:name name
:id (Long/parseLong id)})))
(for [[id name] (dc/q '[:find ?i ?n
:in $ ?s
:where [?i :ezcater-caterer/name ?n]
[(clojure.string/upper-case ?n) ?n2]
[(clojure.string/includes? ?n2 ?s)]]
(dc/db conn)
(str/upper-case (:query args)))]
{:name name
:id id}))
(defn rebuild-search-index []
(search/full-index-query
(for [result (map first (dc/qseq {:query '[:find (pull ?a [:ezcater-caterer/search-terms :db/id :ezcater-caterer/name])
:in $
:where [?a :ezcater-caterer/search-terms ]]
:args [(dc/db conn)]}))]
{:id (:db/id result)
:text (:ezcater-caterer/search-terms result)})
"ezcater-caterer"))
(mount/defstate indexer
:start (scheduler/every (* 5 60 1000) (heartbeat rebuild-search-index "rebuild-search-index"))
:stop (scheduler/stop indexer))
(def objects
{:ezcater_caterer {:fields {:name {:type 'String}

View File

@@ -1,7 +1,6 @@
(ns auto-ap.graphql.vendors
(:require
[auto-ap.datomic :refer [audit-transact conn pull-attr remove-nils]]
[iol-ion.tx :refer [random-tempid]]
[auto-ap.datomic :refer [audit-transact conn remove-nils]]
[auto-ap.datomic.vendors :as d-vendors]
[auto-ap.graphql.utils
:refer [->graphql
@@ -12,19 +11,13 @@
enum->keyword
is-admin?
result->page]]
[auto-ap.search :as search]
[auto-ap.utils :refer [heartbeat]]
[auto-ap.solr :as solr]
[clojure.set :as set]
[clojure.string :as str]
[manifold.executor :as ex]
[manifold.deferred :as de]
[clojure.tools.logging :as log]
[datomic.api :as dc]
[yang.scheduler :as scheduler]
[mount.core :as mount]
[clj-time.core :as time]
[clj-time.coerce :as coerce]
[com.brunobonacci.mulog :as mu]))
[iol-ion.tx :refer [random-tempid]]
[manifold.deferred :as de]
[manifold.executor :as ex]))
(defn can-user-edit-vendor? [vendor-id id]
(if (is-admin? id)
@@ -138,10 +131,18 @@
:vendor/automatically-paid-when-due (:automatically_paid_when_due in)))]
transaction-result (audit-transact [transaction] (:id context))]
transaction-result (audit-transact [transaction] (:id context))
new-vendor (d-vendors/get-by-id (or (-> transaction-result :tempids (get "vendor"))
id))]
(-> (d-vendors/get-by-id (or (-> transaction-result :tempids (get "vendor"))
id))
(auto-ap.solr/index-documents-raw
auto-ap.solr/impl
"vendors"
[{"id" (:db/id new-vendor)
"name" (:vendor/name new-vendor)
"hidden" (boolean (:vendor/hidden new-vendor))}])
(-> new-vendor
(->graphql))))
(defn merge-vendors [context {:keys [from to]} _]
@@ -183,64 +184,28 @@
matches))
(defn search [context args _]
(let [search-query (cleanse-query (:query args))]
(for [[id name] (search/search (cond-> {:q search-query}
(not (is-admin? (:id context))) (assoc :hidden false))
"vendor")]
{:name name
:id id})))
(let [search-query (str "name:(" (cleanse-query (:query args)) ")")]
(for [{:keys [id name]} (solr/query solr/impl "vendors" {"query" (cond-> search-query
(not (is-admin? (:id context))) (str " hidden:false"))
"fields" "id, name"})]
{:id (Long/parseLong id)
:name (first name)})))
(def single-thread (ex/fixed-thread-executor 1))
(defn rebuild-search-index []
(de/future-with
single-thread
(search/full-index-query
(auto-ap.solr/index-documents-raw
auto-ap.solr/impl
"vendors"
(for [[result] (dc/qseq {:query '[:find (pull ?v [:vendor/search-terms :db/id :vendor/name :vendor/hidden])
:in $
:where [?v :vendor/search-terms ]]
:args [(dc/db conn)]})]
{:id (:db/id result)
:text (or (first (:vendor/search-terms result))
(:vendor/name result))
:hidden (boolean (:vendor/hidden result))})
"vendor")))
(def last-run-basis (atom nil))
(defn add-incremental-changes []
(de/future-with
single-thread
(if-let [last-run-basis-value @last-run-basis]
(let [db (dc/db conn)
recent (dc/since db last-run-basis-value)
_ (mu/log ::indexing
:last-run last-run-basis-value
:starting-from (:basisT db))
results (for [[result] (dc/qseq {:query '[:find (pull ?v [:vendor/search-terms :db/id :vendor/name :vendor/hidden])
:in $ $$
:where [$ ?v :vendor/name ]
[$$ ?v]]
:args [db recent]})]
{:id (:db/id result)
:text (or (first (:vendor/search-terms result))
(:vendor/name result))
:hidden (boolean (:vendor/hidden result))})]
(when (seq results)
(mu/log ::adding-to-index
:sample (first results)
:count (count results))
(search/full-index-query results "vendor" false))
(reset! last-run-basis (:basisT db))
(count results))
(reset! last-run-basis (:basisT (dc/db conn))))))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(mount/defstate indexer
:start (scheduler/every (* 5 60 1000) (heartbeat rebuild-search-index "rebuild-search-index"))
:stop (scheduler/stop indexer))
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(mount/defstate incremental-indexer
:start (scheduler/every (* 5 1000) (heartbeat add-incremental-changes "incremental-indexing"))
:stop (scheduler/stop incremental-indexer))
{"id" (:db/id result)
"name" (or (first (:vendor/search-terms result))
(:vendor/name result))
"hidden" (boolean (:vendor/hidden result))}))))

View File

@@ -6,6 +6,7 @@
[auto-ap.datomic.transaction-rules :as tr]
[auto-ap.datomic.transactions :as d-transactions]
[auto-ap.rule-matching :as rm]
[auto-ap.solr :as solr]
[auto-ap.time :as atime]
[auto-ap.utils :refer [dollars=]]
[clj-time.coerce :as coerce]
@@ -13,8 +14,7 @@
[clojure.core.cache :as cache]
[clojure.tools.logging :as log]
[datomic.api :as dc]
[digest :as di]
[auto-ap.solr :as solr]))
[digest :as di]))
(defn rough-match [client-id bank-account-id amount]
(if (and client-id bank-account-id amount)
@@ -219,7 +219,8 @@
:transaction/vendor (:db/id (:payment/vendor existing-payment))
:transaction/location "A"
:transaction/accounts [#:transaction-account
{:account (:db/id (a/get-account-by-numeric-code-and-sets 21000 ["default"]))
{:db/id (random-tempid)
:account (:db/id (a/get-account-by-numeric-code-and-sets 21000 ["default"]))
:location "A"
:amount (Math/abs (double amount))}])))
@@ -234,7 +235,8 @@
(assoc transaction
:transaction/expected-deposit {:db/id (:db/id expected-deposit)
:expected-deposit/status :expected-deposit-status/cleared}
:transaction/accounts [{:transaction-account/account :account/ccp
:transaction/accounts [{:db/id (random-tempid)
:transaction-account/account :account/ccp
:transaction-account/amount amount
:transaction-account/location "A"}]
:transaction/approval-status :transaction-approval-status/approved
@@ -242,7 +244,7 @@
))))
(defn maybe-code [{:transaction/keys [client amount] :as transaction} apply-rules valid-locations]
(when (seq (match-transaction-to-unpaid-invoices amount client))
(when-not (seq (match-transaction-to-unpaid-invoices amount client))
(apply-rules transaction valid-locations)))
(defn transaction->txs [transaction bank-account apply-rules]
@@ -323,7 +325,7 @@
:import-batch/entry (:db/id transaction)}]
{:user/name user
:user/role ":admin"})]
(doseq [n (:tempids result)]
(doseq [[_ n] (:tempids result)]
(solr/touch-with-ledger n))))))
(get-stats [_]

View File

@@ -89,7 +89,8 @@
:tip (fmt-amount tip)}]
:total (fmt-amount (+ food-total
tax
tip))
tip
(or adjustments 0.0)))
:discount (fmt-amount (or adjustments 0.0))
:service-charge (fmt-amount (+ fee commission))
:tax (fmt-amount tax)

View File

@@ -1,75 +0,0 @@
(ns auto-ap.search
(:require [config.core :refer [env]])
(:import
(java.nio.file Paths)
(org.apache.lucene.analysis.standard StandardAnalyzer)
(org.apache.lucene.document Document Field$Store StoredField StringField TextField)
(org.apache.lucene.index DirectoryReader IndexWriter IndexWriterConfig Term)
(org.apache.lucene.queryparser.classic QueryParser)
(org.apache.lucene.search BooleanClause$Occur BooleanQuery$Builder IndexSearcher PhraseQuery$Builder Query TermQuery)
(org.apache.lucene.store FSDirectory)))
(defn full-index-query
([results index-name]
(full-index-query results index-name true))
([results index-name delete?]
(let [directory (FSDirectory/open (Paths/get (java.net.URI. (str "file:///tmp/search/" (:dd-env env) "/" index-name))))
analyzer (StandardAnalyzer.)
index-writer-config (IndexWriterConfig. analyzer)
index-writer (IndexWriter. directory index-writer-config)]
(when delete?
(.deleteAll index-writer))
(try
(doseq [{:keys [text id] :as x} results
:let [doc (doto
(Document.)
(.add (TextField. "name" text Field$Store/YES))
(.add (StoredField. "id" (long id))))]]
(doseq [k (filter (complement #{:text :id}) (keys x))]
(.add doc (StringField. (name k) (str (get x k)) Field$Store/YES)))
(.addDocument index-writer doc))
(finally
(.close index-writer))))))
(defn make-query [n]
(let [
text-query (when (:q n)
(.parse (QueryParser. "name" (StandardAnalyzer.)) (:q n)))
text-query-exact (when (:q-exact n)
(.build (doto (PhraseQuery$Builder. )
(.add (Term. "name" (:q-exact n)) 0))))
full-query (BooleanQuery$Builder.)
]
(when text-query
(.add full-query text-query BooleanClause$Occur/MUST))
(when text-query-exact
(.add full-query text-query-exact BooleanClause$Occur/MUST))
(doseq [[k v] (dissoc n :q :q-exact)]
(if (instance? Query v)
(.add full-query v BooleanClause$Occur/MUST)
(.add full-query (TermQuery. (Term. (name k) (str v))) BooleanClause$Occur/MUST)))
(.build full-query)))
(defn search
([n index-name]
(search n index-name []))
([n index-name other-keys]
(let [directory (FSDirectory/open (Paths/get (java.net.URI. (str "file:///tmp/search/" (:dd-env env) "/" index-name))))
index-reader (DirectoryReader/open directory)
index-searcher (IndexSearcher. index-reader)]
(for [x (seq (.scoreDocs (.search index-searcher (make-query n) 10)))]
(into
[(Long/parseLong (.get (.doc index-searcher (.-doc x)) "id"))
(.get (.doc index-searcher (.-doc x)) "name")
(.-score x)]
(map (fn [o]
(.get (.doc index-searcher (.-doc x)) o))
other-keys)))))
)
(defn search-ids [n index-name]
(let [directory (FSDirectory/open (Paths/get (java.net.URI. (str "file:///tmp/search/" (:dd-env env) "/" index-name))))
index-reader (DirectoryReader/open directory)
index-searcher (IndexSearcher. index-reader)]
(for [x (seq (.scoreDocs (.search index-searcher (make-query n) 100)))]
(Long/parseLong (.get (.doc index-searcher (.-doc x)) "id")))))

View File

@@ -1,6 +1,7 @@
(ns auto-ap.solr
(:require
[auto-ap.datomic :refer [conn pull-id]]
[cemerick.url :as url]
[auto-ap.time :as atime]
[clj-http.client :as client]
[clj-time.coerce :as c]
@@ -9,6 +10,12 @@
[config.core :refer [env]]
[datomic.api :as dc]))
(defn escape [s]
(str/escape s
(into {}
(for [c "\\+-&&||!(){}[]^\"~*?:/"]
[c (str "\\" c)]))))
(def solr-uri (:solr-uri env))
(defn fmt-amount [a]
@@ -118,26 +125,38 @@
(defprotocol SolrClient
(index-documents [this xs])
(query [this q])
(delete [this]))
(index-documents-raw [this index xs])
(index-documents [this index xs])
(query [this index q])
(delete [this index]))
(defrecord RealSolrClient [solr-uri]
SolrClient
(index-documents [this xs]
(index-documents-raw [this index xs]
(client/post
(str solr-uri "/solr/invoices/update?commitWithin=15000")
(str (assoc (url/url solr-uri "solr" index "update")
:query {"commitWithin" 60000}))
{:headers {"Content-Type" "application/json"}
:socket-timeout 30000
:connection-timeout 30000
:method "POST"
:body (json/write-str xs)}))
(index-documents [this index xs]
(client/post
(str (assoc (url/url solr-uri "solr" index "update")
:query {"commitWithin" 60000}))
{:headers {"Content-Type" "application/json"}
:socket-timeout 30000
:connection-timeout 30000
:method "POST"
:body (json/write-str (filter identity (map datomic->solr xs)))}))
(query [this q]
(-> (client/post (str solr-uri "/solr/invoices/query")
{:body (json/write-str {"query" q
"fields" "id, date, amount, type, description, number, client_code, client_id, vendor_name"})
(query [this index q]
(-> (client/post (str (url/url solr-uri "solr" index "query"))
{:body (json/write-str q )
:socket-timeout 30000
:connection-timeout 30000
:headers {"Content-Type" "application/json"}
@@ -146,32 +165,41 @@
:body
:response
:docs))
(delete [this]
(delete [this index]
(client/post
(str solr-uri "/solr/invoices/update?commitWithin=1000")
(str (assoc (url/url solr-uri "solr" index "update")
:query {"commitWithin" 15000}))
{:headers {"Content-Type" "application/json"}
:method "POST"
:body (json/write-str {"delete" {"query" "*:*"}})})))
(defrecord MockSolrClient []
SolrClient
(index-documents [this xs]
(index-documents [this index xs]
nil)
(query [this q]
(index-documents-raw [this index xs]
nil)
(delete [this]
(query [this index q]
nil)
(delete [this index]
nil))
(def impl (if (= :solr (:solr-impl env))
(->RealSolrClient (:solr-uri env))
(->MockSolrClient )))
(defn touch-with-ledger [i]
(index-documents impl [i
(pull-id (dc/db conn) [:journal-entry/original-entity i])]))
(index-documents impl "invoices" [i [:journal-entry/original-entity i]]))
(defn touch [i]
(index-documents impl [i]))
(defn touch
([i] (touch i "invoices"))
([i index]
(index-documents impl index [i])))

View File

@@ -55,7 +55,8 @@
(into []
(filter (fn [d]
(can-see-client? id (first (:client_id d)))))
(solr/query solr/impl (q->solr-q q))))
(solr/query solr/impl "invoices" {"query" (q->solr-q q)
"fields" "id, date, amount, type, description, number, client_code, client_id, vendor_name"})))
(defn search-results* [q id]

View File

@@ -346,7 +346,7 @@
(mu/start-publisher! {:type :dev})
(mount.core/start (mount.core/only #{#'auto-ap.datomic/conn })))
(defn start-search []
#_(defn start-search []
(mount.core/start (mount.core/only #{#'auto-ap.graphql.vendors/indexer #'auto-ap.graphql.accounts/indexer})))
(defn restart-db []
@@ -573,7 +573,7 @@
(partition-all 1000))]
(print ".")
(flush)
(solr/index-documents solr/impl batch))
(solr/index-documents solr/impl "invoices" batch))
(doseq [batch (->> (dc/qseq {:query '[:find ?i
:in $
@@ -584,7 +584,7 @@
(partition-all 1000))]
(print ".")
(flush)
(solr/index-documents solr/impl batch))
(solr/index-documents solr/impl "invoices" batch))
(doseq [batch (->> (dc/qseq {:query '[:find ?i
:in $
@@ -595,7 +595,7 @@
(partition-all 1000))]
(print ".")
(flush)
(solr/index-documents solr/impl batch))
(solr/index-documents solr/impl "invoices" batch))
(doseq [batch (->> (dc/qseq {:query '[:find ?i
:in $
:where [?i :journal-entry/date]]
@@ -604,7 +604,7 @@
(partition-all 1000))]
(print ".")
(flush)
(solr/index-documents solr/impl batch)))
(solr/index-documents solr/impl "invoices" batch)))
(defn setup-sales-orders []
(doseq [n (->> (dc/qseq {:query '[:find ?s ?c :where [?s :sales-order/client ?c]] :args [(dc/db auto-ap.datomic/conn)]})