diff --git a/src/cljs/auto_ap/views/components/vendor_dialog.cljs b/src/cljs/auto_ap/views/components/vendor_dialog.cljs index 770f2c32..9abd9b76 100644 --- a/src/cljs/auto_ap/views/components/vendor_dialog.cljs +++ b/src/cljs/auto_ap/views/components/vendor_dialog.cljs @@ -4,7 +4,7 @@ [auto-ap.views.components.modal :refer [action-modal]] [auto-ap.views.components.address :refer [address-field]] [auto-ap.views.components.typeahead :refer [typeahead]] - [clj-fuzzy.metrics :refer [jaccard]] + [clj-fuzzy.metrics :refer [jaccard jaro-winkler]] [clojure.spec.alpha :as s] [clojure.string :as str] [auto-ap.entities.vendors :as entity] @@ -14,17 +14,19 @@ (mapv #(.toLowerCase (str/join "" %)) (partition len 1 text))) -(defn partial-matches-vendor? [text vendors] - (when (> (count text) 4) - (let [text (.toLowerCase text)] +(defn partial-matches-vendor? [vendor vendors] + (when (> (count (:name vendor)) 5) + (let [text (.toLowerCase (:name vendor))] (->> vendors + (filter #(not= (:id %) (:id vendor))) (map :name) (mapcat (fn [v] (mapv - (fn [n] [v (jaccard text n )]) + (fn [n] [v (jaro-winkler text n ) n text]) (ngrams v (count text))))) #_(sort-by second) - (filter #(< (second %) 0.3)) + (filter #(> (second %) 0.9)) + #_(map (fn [x] (doto x println))) (map first) first)))) @@ -40,7 +42,7 @@ (when (:error vendor) [:span.icon.has-text-danger [:i.fa.fa-exclamation-triangle]])] - :warning (when-let [vendor (partial-matches-vendor? (:name vendor) all-vendors)] + :warning (when-let [vendor (partial-matches-vendor? vendor all-vendors)] (str "Are you sure you don't mean " vendor "?")) :action-text "Save" :save-event save-event @@ -127,7 +129,6 @@ :subscription vendor}]] [:span.icon.is-small.is-left [:i.fa.fa-phone]]]] - [horizontal-field [:label.label "Secondary"] [:div.control.has-icons-left @@ -157,7 +158,6 @@ :subscription vendor}]] [:span.icon.is-small.is-left [:i.fa.fa-phone]]]] - [horizontal-field [:label.label "Invoice Reminders"] [:div.control