Initial filter implementation attempt
This commit is contained in:
parent
2464a66ac7
commit
ee3ad0a6e9
1 changed files with 45 additions and 6 deletions
|
@ -20,7 +20,8 @@
|
|||
[clojure.string :as s]
|
||||
[rss-thread-watch.watcher :as watcher]
|
||||
[rss-thread-watch.utils :as ut]
|
||||
[rss-thread-watch.config :as conf])
|
||||
[rss-thread-watch.config :as conf]
|
||||
[rss-thread-watch.filters :as f])
|
||||
(:gen-class))
|
||||
|
||||
(def boards-enabled-cache
|
||||
|
@ -56,12 +57,48 @@
|
|||
(:last-modified thread)
|
||||
(: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)]
|
||||
(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
|
||||
))
|
||||
|
||||
|
||||
|
||||
(defn filter-chod-posts
|
||||
"Return list of all threads with equal or higher ChoD than requested
|
||||
|
||||
;;resume
|
||||
READS FROM GLOBALS: watcher.time-of-cache"
|
||||
[query-vec chod-treshold repeat? board-cache]
|
||||
|
||||
(let [{time-of-generation :time
|
||||
cache :data} board-cache
|
||||
guid-fn (case repeat?
|
||||
|
@ -72,6 +109,7 @@
|
|||
cache))
|
||||
;; So we don't have to search thru everything we have cached
|
||||
needed-cache-part (subvec cache cache-start-index)
|
||||
;; Here we gonna run fmap but not really
|
||||
actuall-matches (keep (fn [t]
|
||||
(let [title (:title t)]
|
||||
;; Todo: Man, wouldn't it be cool to know which querry matched the thread?
|
||||
|
@ -130,10 +168,11 @@
|
|||
query :query-string
|
||||
scheme :scheme
|
||||
server-name :server-name} rqst
|
||||
qrs (prms "q")
|
||||
filters (make-filters prms)
|
||||
;; qrs (prms "q")
|
||||
self-uri (str (s/replace-first scheme ":" "")
|
||||
"://" server-name uri "?" query)
|
||||
queries (if (vector? qrs) qrs [qrs]) ; to always return vector
|
||||
;; queries (if (vector? qrs) qrs [qrs]) ; to always return vector
|
||||
real-chod (if-let [ch (or (and (vector? chod)
|
||||
(first chod))
|
||||
chod)]
|
||||
|
@ -167,7 +206,7 @@
|
|||
(when-not (prms "q")
|
||||
(throw (ex-info "400" {:status 400
|
||||
:header {"Content-Type" "text/plain"}
|
||||
:body (str "400 You MUST specify query with one OR more'q=searchTerm' url parameter(s)\n\n\n"
|
||||
:body (str "400 You MUST specify query with one OR more'q=searchTerm' (or 'Q=SeARChteRm' for case sensitive) url parameter(s)\n\n\n"
|
||||
"Exmple: '" served-filename "?q=pony&q=IWTCIRD' will show in your feed all threads with 'pony' or 'IWTCIRD'"
|
||||
" in their title that are about to die.")})))
|
||||
;; Whether cache has been generated yet
|
||||
|
|
Loading…
Reference in a new issue