I am sharing this, it is the first advanced query I have designed & written, as I thought it would be very helpful for my workflow. It took me a lot of frustration as I think the resources around learning advanced queries are lacking. I also think discord is a terrible medium for sharing group knowledge, which is why I’m posting this here - anyway, here we are, presented in case its useful to others and/or for critique from those that know better.
I use a small, well-defined range of page type
s such as Source
, Question
, Statement
, and Output
.
I wanted to be able to create a new Question
page, such as, “How can we design better onboarding for our game?”, give it tags:: onboarding, game design, tutorials
and then quickly grab all Source
s that relate to (any of) those tags. So here it is:
#+BEGIN_QUERY
{:title "Sources for Current Page"
:query
[:find
(pull ?p [*])
:in $ ?type ?currentpage
:where
[?cp :block/name ?currentpage]
[?cp :block/tags ?ct]
[?ct :block/name ?tag2]
[?p :block/tags ?t]
[?t :block/name ?tag1]
[(= ?tag1 ?tag2)]
[?p :block/name]
[?p :block/properties ?prop]
[(get ?prop :type) ?v]
(or [(= ?v ?type)] [(contains? ?v ?type)])
]
:inputs ["Source" :current-page]
}
#+END_QUERY