Improve make-filters function
This commit is contained in:
parent
b88a471a0e
commit
5178ab7366
2 changed files with 10 additions and 34 deletions
|
@ -58,41 +58,14 @@
|
||||||
(:chod thread))))
|
(:chod thread))))
|
||||||
|
|
||||||
(defn make-filters
|
(defn make-filters
|
||||||
"Creates map of functions and filters from query string"
|
"Creates map of functions and filters from query string.
|
||||||
;; In future predicates could return matched parts of string instead of
|
Return format is: {filter-fun ['words' 'to' 'filter' 'using this function]}"
|
||||||
;; t/nil values which could be used for coloring of results
|
[query-string known-filter-map]
|
||||||
[query-map]
|
(let [filterable (select-keys query-string
|
||||||
(let [filtering-params '("q" "Q") ;Later add "r" for regex
|
(keys known-filter-map))]
|
||||||
filter-map (select-keys query-map filtering-params)]
|
|
||||||
(ut/fkmap (fn [k v]
|
(ut/fkmap (fn [k v]
|
||||||
{(case k
|
{(get known-filter-map k) v})
|
||||||
;; regex filter here
|
filterable)))
|
||||||
"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
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn filter-chod-posts
|
(defn filter-chod-posts
|
||||||
"Return list of all threads with equal or higher ChoD than requested
|
"Return list of all threads with equal or higher ChoD than requested
|
||||||
|
|
|
@ -30,4 +30,7 @@
|
||||||
[s queries]
|
[s queries]
|
||||||
(case-sensitive-filter (cs/lower-case s) (map cs/lower-case queries)))
|
(case-sensitive-filter (cs/lower-case s) (map cs/lower-case queries)))
|
||||||
|
|
||||||
|
(def known-filters
|
||||||
|
{"Q" case-sensitive-filter
|
||||||
|
"q" case-insensitive-filter})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue