msot
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
(ns auto-ap.ssr.company-dropdown
|
||||
(:require [auto-ap.datomic :refer [conn pull-many]]
|
||||
[auto-ap.graphql.utils :refer [cleanse-query]]
|
||||
[auto-ap.solr :as solr]
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
[auto-ap.ssr.hx :as hx]
|
||||
[auto-ap.ssr.svg :as svg]
|
||||
[auto-ap.ssr.utils :refer [html-response]]
|
||||
[bidi.bidi :as bidi]
|
||||
[clojure.string :as str]
|
||||
[datomic.api :as dc]
|
||||
[hiccup2.core :as hiccup]
|
||||
[iol-ion.query :refer [can-see-client?]]
|
||||
[clojure.data.json :as json]))
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn pull-many]]
|
||||
[auto-ap.graphql.utils :refer [cleanse-query strip-special]]
|
||||
[auto-ap.logging :as alog]
|
||||
[auto-ap.solr :as solr]
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
[auto-ap.ssr.hx :as hx]
|
||||
[auto-ap.ssr.svg :as svg]
|
||||
[auto-ap.ssr.utils :refer [html-response]]
|
||||
[bidi.bidi :as bidi]
|
||||
[clojure.data.json :as json]
|
||||
[clojure.string :as str]
|
||||
[datomic.api :as dc]
|
||||
[hiccup2.core :as hiccup]
|
||||
[iol-ion.query :refer [can-see-client?]]))
|
||||
|
||||
|
||||
(defn dropdown-search-results* [{:keys [options]}]
|
||||
@@ -46,22 +48,35 @@
|
||||
|
||||
|
||||
(defn get-clients [identity query]
|
||||
(if (str/starts-with? query "g:")
|
||||
(let [search-query (str "groups:(" (subs query 2) ")")]
|
||||
[{:group (subs query 2)
|
||||
:name (str "All clients matching " (subs query 2))}])
|
||||
(if-let [query (not-empty (cleanse-query query))]
|
||||
(let [search-query (str "name:(" query ")")]
|
||||
(let [raw-query (not-empty (strip-special query))
|
||||
cleansed-query (not-empty (cleanse-query query))
|
||||
cleansed-search-query (str "name:(" query ")")
|
||||
exec-search (fn []
|
||||
(for [n (pull-many (dc/db conn) [:client/name :db/id]
|
||||
(for [{:keys [id name]} (solr/query solr/impl "clients" {"query" cleansed-search-query
|
||||
"fields" "id, name"})
|
||||
:let [client-id (Long/parseLong id)]
|
||||
:when (can-see-client? identity client-id)]
|
||||
client-id))]
|
||||
{:id (:db/id n)
|
||||
:name (:client/name n)}))]
|
||||
(cond (str/starts-with? query "g:")
|
||||
[{:group (subs query 2)
|
||||
:name (str "All clients matching " (subs query 2))}]
|
||||
|
||||
(for [n (pull-many (dc/db conn) [:client/name :db/id]
|
||||
(for [{:keys [id name]} (solr/query solr/impl "clients" {"query" search-query
|
||||
"fields" "id, name"})
|
||||
:let [client-id (Long/parseLong id)]
|
||||
:when (can-see-client? identity client-id)]
|
||||
client-id))]
|
||||
{:id (:db/id n)
|
||||
:name (:client/name n)}))
|
||||
[])))
|
||||
raw-query
|
||||
(let [code-matches (for [n (pull-many (dc/db conn) [:client/name :db/id]
|
||||
(for [{:keys [id name]} (solr/query solr/impl "clients" {"query" (format "code:\"%s\"" raw-query)
|
||||
"fields" "id, name"})
|
||||
:let [client-id (Long/parseLong id)]
|
||||
:when (can-see-client? identity client-id)]
|
||||
client-id))]
|
||||
{:id (:db/id n)
|
||||
:name (:client/name n)})]
|
||||
(or (seq code-matches) (exec-search)))
|
||||
|
||||
cleansed-query
|
||||
(exec-search))))
|
||||
|
||||
(defn dropdown-search-results [{:keys [identity] :as request}]
|
||||
(html-response
|
||||
|
||||
Reference in New Issue
Block a user