 
 (def manufacturer-matchers
   [(fn first-word? [manufacturers candidate]
-     (some #{(first-word candidate)} manufacturers))
+     (p/p :firstword
+          (some #{(first-word candidate)} manufacturers)))
    
    (fn levenshtein? [manufacturers candidate]
      ; This is mainly for things like "OPYMPUS" -> "Olympus"
      (p/p :levenshtein
-     (and (> (count candidate) 3)  ; Very short strings are not likely to be similar
-          (let [max-delta 2
-                [guess lev-dist] (->> manufacturers
-                                      (map (juxt identity (partial levenshtein candidate)))
-                                      (apply min-key second))]
-            (when (<= lev-dist max-delta)
-              guess)))))])
+          (let [min-length 4
+                max-lev-dist 2]
+            (and ; Very short strings are not likely to be similar
+                 (>= (count candidate) min-length)
+
+                 ; Levenshtein is expensive, so require the first letter to match
+                 ; before trying to compute it.
+                 ((set (map first manufacturers)) (first candidate))
+
+                 (let [[guess lev-dist]
+                       (p/p :lev-lev
+                            (->> manufacturers
+                                 (map (juxt identity (partial levenshtein candidate)))
+                                 (apply min-key second)))]
+                   (when (<= lev-dist max-lev-dist)
+                     guess))))))])
 
 (def match-manufacturer
   (memoize

                  matching-listings))))))




(defn test-random [products listings]
  (let [listing (rand-nth listings)]
    (or (match-title products listing)
        [nil listing])))



(defn -main
  [& args]
  ; We need to read all products into memory at once, but we

(defn match-title
  "Attempts to match listing's title to a product in products, returning the
  matched product if successful, else nil."
  [products title]
    (when-let [title (-> (or title "")
                         (str/replace #"[_-]+" ""))]
      (p/p :mt-filter
           (->> products
                (filter #(re-find (:regex %) title))
                first))))


(p/defnp match-listing
