Improve account search

This commit is contained in:
arne 2025-11-23 08:51:39 +01:00
commit e77a2a9ed3

View file

@ -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]
; 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]
(str/starts-with? (j/get-in post [:account :acct]) term))))
(or (begin-match? (j/get-in post [:account :acct]))
(fuzzy-match? (j/get-in post [:account :display_name])))))))
(defn mention-matcher [term]
(let [term (str/replace term #"^@" "")
begin-match? (partial re-find (->regex (str "^" term)))]
(filter (fn [post]
(some #(str/starts-with? (j/get % :username) term) (j/get post :mentions)))))
(some #(begin-match? (j/get % :acct)) (j/get post :mentions))))))
(defn date-before-matcher [term]
(filter #(< (j/get % :created_at) term)))