-
-
Save zentrope/aea55ff520da2fad85837c4ce6514222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def question-search-rules | |
;; | |
;; Provides an "or" set of rules for finding a string inside some of | |
;; the question attributes: doesn't require all of the attributes to | |
;; be present. | |
;; | |
'[[(msearch? ?p ?q) ; search the question/description | |
[?q :question/description ?text] | |
[(clojure.string/lower-case ?text) ?s] | |
[(.contains ^String ?s ?p)]] | |
;; [(msearch? ?p ?q) ; search the category string | |
;; [?q :question/category ?text] | |
;; [(clojure.string/lower-case ?text) ?s] | |
;; [(.contains ^String ?s ?p)]] | |
[(mearch? ?p ?q) ; search question aspects | |
[?q :question/aspects ?a] | |
[?a :aspect/text ?text] | |
[(clojure.string/lower-case ?text) ?s] | |
[(.contains ^String ?s ?p)]] | |
[(msearch? ?p ?q) ; search choices | |
[?q :question/choices ?c] | |
[?c :choice/text ?text] | |
[(clojure.string/lower-case ?text) ?s] | |
[(.contains ^String ?s ?p)]]]) | |
(defn question-search | |
[db {:keys [pattern] :as query}] | |
(if (s/blank? pattern) | |
[] | |
(-> (d/q '{:find [[(pull ?e pat) ...]] | |
:in [$ % ?p pat] | |
:where [[?e :question/id] | |
(msearch? ?p ?e)]} | |
db | |
question-search-rules | |
(s/trim (s/lower-case pattern)) | |
question-spec) | |
de-refs | |
de-ns))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment