diff --git a/src/computersandblues/lodestone/match.cljs b/src/computersandblues/lodestone/match.cljs index 818557c..0794dc1 100644 --- a/src/computersandblues/lodestone/match.cljs +++ b/src/computersandblues/lodestone/match.cljs @@ -20,6 +20,7 @@ (filter (fn [post] (or (match? (j/get post :content)) (match? (j/get-in post [:account :acct])) ; search for url + username of poster + (match? (j/get-in post [:account :display_name])) ; search for display-name of poster (some #(match? (j/get % :username)) (j/get post :mentions)) (some #(some-> (j/get % :description) match?) (j/get post :media_attachments))))))) ; search in alt text @@ -30,12 +31,22 @@ (some #(some-> (j/get % :description) match?) (j/get post :media_attachments))))))) ; search in descriptions of attachments (defn from-matcher [term] - (filter (fn [post] - (str/starts-with? (j/get-in post [:account :acct]) term)))) + ; the account of the person that created the account is usually displayed + ; slightly different compared to mentioned accounts. especially you'll see the + ; persons chosen display name only for the OP, and this matcher taks this into + ; account by allowing you to search for both handle and display name. + (let [term (str/replace term #"^@" "") + begin-match? (partial re-find (->regex (str "^" term))) + fuzzy-match? (partial re-find (->regex term))] + (filter (fn [post] + (or (begin-match? (j/get-in post [:account :acct])) + (fuzzy-match? (j/get-in post [:account :display_name]))))))) (defn mention-matcher [term] - (filter (fn [post] - (some #(str/starts-with? (j/get % :username) term) (j/get post :mentions))))) + (let [term (str/replace term #"^@" "") + begin-match? (partial re-find (->regex (str "^" term)))] + (filter (fn [post] + (some #(begin-match? (j/get % :acct)) (j/get post :mentions)))))) (defn date-before-matcher [term] (filter #(< (j/get % :created_at) term)))