cloud - finishes search implementation
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user