So last night and this morning, I got a little into the querying in Logseq.
One of the problems I went into, was the following:
Task
Let’s say I have a page about some project TestProject.
Inside TestProject, I want to see all tasks that link to it, and sort them, and also be able to unfold them (for task-specific information and sub-tasks).
Tasks might be scattered, but for this small example, let’s say those are all the tasks:
and
Problem
In simple queries the main functionality works really well like this:
{{query (and (todo now later done) [[TestProject]]) }}
Now, within TestProject, it’s not that nice to link to itself. Also, as I said, I might want to filter or sort the output.
With advanced queries, I can search for stuff that links to TestProject (within the same page), and can also filter and sort, but the following query doesn’t put the whole block to the output. OR rather, It puts the block, but not the nested blocks.
#+BEGIN_QUERY
{
:query [
:find (pull ?b [*])
:in $ ?current-page
:where
[?p :block/name ?current-page]
[?b :block/path-refs ?p]
[?b :block/marker ?marker]
[(contains? #{"TODO" "DOING" "DONE" "NOW" "LATER" "WAITING"} ?marker)]]
:inputs [:current-page]}
#+END_QUERY
Solution
By doing as suggested by MeasuredTiredness in Query for pages with property value that contains specific word - #2 by MeasuredTiredness, I looked up what happens for a simple query, by checking the console log.
The secret is, in the simple query, it’s not (pull ?b [*])
, but instead a lot of stuff in the place of *
. Now, it turns out, the interesting part of this lots of stuff is {:block/_parent ...}
.
To be fair, I don’t know exactly, what this is, but it seems that it makes the block behave as an expandable block, as I wanted.
Thus, the wanted query (without sorting yet) is the following:
#+BEGIN_QUERY
{
:query [
:find (pull ?b [* {:block/_parent ...}])
:in $ ?current-page
:where
[?p :block/name ?current-page]
[?b :block/path-refs ?p]
[?b :block/marker ?marker]
[(contains? #{"TODO" "DOING" "DONE" "NOW" "LATER" "WAITING"} ?marker)]]
:inputs [:current-page]}
#+END_QUERY