Prepare more complex matching

This commit is contained in:
arne 2025-11-22 00:25:56 +01:00
commit ce56fb65c6
2 changed files with 20 additions and 11 deletions

View file

@ -14,12 +14,17 @@
(->> (re-seq #"\"([^\"]+)\"|([^\s]+)" query)
(mapv (fn [[_ a b]] (or a b)))))
(defn query->matching-fn [query]
(let [match? (if query
(partial re-find (->regex query))
(constantly true))]
(fn [post]
(or (match? (j/get post :content))
(match? (j/get-in post [:account :acct])) ; search for url + username of poster
(some #(match? (j/get % :username)) (j/get post :mentions))
(some #(when-let [desc (j/get % :description)] (match? desc)) (j/get post :media_attachments)))))) ; search in alt text
(defn text-matcher [token]
(let [match? (partial re-find (->regex token))]
(filter (fn [post]
(or (match? (j/get post :content))
(match? (j/get-in post [:account :acct])) ; search for url + username 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
(defn query->matching-xform [query]
(if query
(->> (query->tokens query)
(mapv #(text-matcher %))
(reduce comp))
(filter (constantly true))))