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