Attempts to fix searching problems
This commit is contained in:
@@ -125,12 +125,15 @@
|
||||
(assert-not-locked client-id d)))
|
||||
|
||||
(defn cleanse-query [q]
|
||||
(let [parts (-> q
|
||||
(str/replace #"[\[\]\+\*]" "")
|
||||
(str/split #"\s+"))
|
||||
exacts (butlast parts)
|
||||
partial (last parts)]
|
||||
(as-> exacts e
|
||||
(mapv #(str "+" %) e)
|
||||
(conj e (str partial "*"))
|
||||
(str/join " " e))))
|
||||
(if (str/includes? q "&")
|
||||
(str "\"" q "\"~0.8")
|
||||
(let [parts (-> q
|
||||
(str/replace #"[\[\]\+\*]" "")
|
||||
(str/split #"\s+"))
|
||||
exacts (butlast parts)
|
||||
partial (last parts)]
|
||||
(as-> exacts e
|
||||
|
||||
(mapv #(str "+" %) e)
|
||||
(conj e (str partial "*"))
|
||||
(str/join " " e)))))
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
is-admin?
|
||||
result->page]]
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.api :as d]))
|
||||
|
||||
@@ -148,6 +149,17 @@
|
||||
(d-vendors/get-graphql-by-id (assoc args :id (:id context))
|
||||
(:id args))))
|
||||
|
||||
(defn partial-match-first [query matches]
|
||||
(if-let [best-match (->> matches
|
||||
(filter (fn [[n]]
|
||||
(str/starts-with? (str/lower-case n)
|
||||
(str/lower-case query))))
|
||||
first)]
|
||||
(cons best-match
|
||||
(filter (complement #{best-match})
|
||||
matches))
|
||||
matches))
|
||||
|
||||
(defn search [context args _]
|
||||
(let [search-query (cleanse-query (:query args))
|
||||
data (if (is-admin? (:id context))
|
||||
@@ -164,6 +176,7 @@
|
||||
search-query))]
|
||||
(->> data
|
||||
(sort-by (comp - last))
|
||||
(partial-match-first (:query args))
|
||||
(map (fn [[n i]]
|
||||
{:name n
|
||||
:id i})))))
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
"country_codes" ["US"]
|
||||
"language" "en"
|
||||
"user" {"client_user_id" client-code}
|
||||
"products" ["transactions" "liabilities"]})})
|
||||
"products" ["transactions"]})})
|
||||
:body
|
||||
:link_token))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user