Attempts to fix searching problems

This commit is contained in:
2022-06-03 12:13:56 -07:00
parent cf25340ad0
commit 9dbc14977e
3 changed files with 26 additions and 10 deletions

View File

@@ -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)))))

View File

@@ -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})))))

View File

@@ -34,7 +34,7 @@
"country_codes" ["US"]
"language" "en"
"user" {"client_user_id" client-code}
"products" ["transactions" "liabilities"]})})
"products" ["transactions"]})})
:body
:link_token))