cloud - finishes search implementation

This commit is contained in:
Bryce
2023-05-18 21:05:48 -07:00
parent 0e6a5c6749
commit cf34b4af7e
13 changed files with 1901 additions and 158 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]