Implement CaseSensitiveQuery #39

Merged
Felisp merged 12 commits from CaseSensitiveQuery into stable 2024-09-24 02:07:26 +02:00
Showing only changes of commit ee3ad0a6e9 - Show all commits

View file

@ -20,7 +20,8 @@
[clojure.string :as s] [clojure.string :as s]
[rss-thread-watch.watcher :as watcher] [rss-thread-watch.watcher :as watcher]
[rss-thread-watch.utils :as ut] [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)) (:gen-class))
(def boards-enabled-cache (def boards-enabled-cache
@ -56,12 +57,48 @@
(:last-modified thread) (:last-modified thread)
(:chod 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 (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
;;resume
READS FROM GLOBALS: watcher.time-of-cache" READS FROM GLOBALS: watcher.time-of-cache"
[query-vec chod-treshold repeat? board-cache] [query-vec chod-treshold repeat? board-cache]
(let [{time-of-generation :time (let [{time-of-generation :time
cache :data} board-cache cache :data} board-cache
guid-fn (case repeat? guid-fn (case repeat?
@ -72,6 +109,7 @@
cache)) cache))
;; So we don't have to search thru everything we have cached ;; So we don't have to search thru everything we have cached
needed-cache-part (subvec cache cache-start-index) needed-cache-part (subvec cache cache-start-index)
;; Here we gonna run fmap but not really
actuall-matches (keep (fn [t] actuall-matches (keep (fn [t]
(let [title (:title t)] (let [title (:title t)]
;; Todo: Man, wouldn't it be cool to know which querry matched the thread? ;; Todo: Man, wouldn't it be cool to know which querry matched the thread?
@ -130,10 +168,11 @@
query :query-string query :query-string
scheme :scheme scheme :scheme
server-name :server-name} rqst server-name :server-name} rqst
qrs (prms "q") filters (make-filters prms)
;; qrs (prms "q")
self-uri (str (s/replace-first scheme ":" "") self-uri (str (s/replace-first scheme ":" "")
"://" server-name uri "?" query) "://" 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) real-chod (if-let [ch (or (and (vector? chod)
(first chod)) (first chod))
chod)] chod)]
@ -167,7 +206,7 @@
(when-not (prms "q") (when-not (prms "q")
(throw (ex-info "400" {:status 400 (throw (ex-info "400" {:status 400
:header {"Content-Type" "text/plain"} :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'" "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.")}))) " in their title that are about to die.")})))
;; Whether cache has been generated yet ;; Whether cache has been generated yet