From 5178ab7366e2f32c611346a62bb827e80a0db25a Mon Sep 17 00:00:00 2001 From: Felisp Date: Thu, 19 Sep 2024 16:57:22 +0200 Subject: [PATCH] Improve make-filters function --- src/rss_thread_watch/feed_generator.clj | 41 +++++-------------------- src/rss_thread_watch/filters.clj | 3 ++ 2 files changed, 10 insertions(+), 34 deletions(-) diff --git a/src/rss_thread_watch/feed_generator.clj b/src/rss_thread_watch/feed_generator.clj index 89aeb3f..f5689c4 100644 --- a/src/rss_thread_watch/feed_generator.clj +++ b/src/rss_thread_watch/feed_generator.clj @@ -58,41 +58,14 @@ (:chod thread)))) (defn make-filters - "Creates map of functions and filters from query string" - ;; In future predicates could return matched parts of string instead of - ;; t/nil values which could be used for coloring of results - [query-map] - (let [filtering-params '("q" "Q") ;Later add "r" for regex - filter-map (select-keys query-map filtering-params)] + "Creates map of functions and filters from query string. + Return format is: {filter-fun ['words' 'to' 'filter' 'using this function]}" + [query-string known-filter-map] + (let [filterable (select-keys query-string + (keys known-filter-map))] (ut/fkmap (fn [k v] - {(case k - ;; regex filter here - "q" f/case-insensitive-filter - "Q" f/case-sensitive-filter) v}) - filter-map))) - - -(defn x [cache filters] - ;;must return fitlered cache - ;; {fun [key dfe dw kwd"]} - (filter - (fn [thread] - ;; run every function for each thread - (let [title (get thread :title)] - (some (fn [filter] - (let [queries (get filters filter)] - (some (fn [q] - (filter title queries)) - queries) - ;; some again? - ;; try some-map? - )) - (keys filters))) - ;;RESUME - ) cache - )) - - + {(get known-filter-map k) v}) + filterable))) (defn filter-chod-posts "Return list of all threads with equal or higher ChoD than requested diff --git a/src/rss_thread_watch/filters.clj b/src/rss_thread_watch/filters.clj index afc7d7a..fe006c1 100644 --- a/src/rss_thread_watch/filters.clj +++ b/src/rss_thread_watch/filters.clj @@ -30,4 +30,7 @@ [s queries] (case-sensitive-filter (cs/lower-case s) (map cs/lower-case queries))) +(def known-filters + {"Q" case-sensitive-filter + "q" case-insensitive-filter})