Advanced Query that pulls all reference AND recursive name spaces

You’re not being mean at all. I highly appreciate the fact that anyone is even remotely engaged with something I invested so much time in.

Let me go over the differences.
Let us have the following setup:


It’s a hierarchy of Company/Project/Meeting. I’ve added one task tagged inline for every page, indented for every page and living on the pages itself. So 9 tasks in total (+2 alias-tagged tasks, I’ll come back to those at the end).

For the page: Company/Project/Meeting, our queries are the same:

For the page: Company/Project, my query has one task more. Namely the one that lives in it’s subpage “Meeting” itself.

Lastly, for the Company page, my query has two more: the task living on Company/Project and the task living on Company/Project/Meeting

All the additional namespace complexity was necessary to make the namespace search recursive. If i’m not mistaken, it’ll grab all the tasks of any depth hierarchical children.
I think I added the (or) around path and refs because I was under the impression that it would otherwise miss inline tags, but that doesn’t seem to be the case.
Lastly, as you can see, both our searches are missing the tasks that are indented beneath an alias-tag, which is a pitty. It tends to clutter my experience, but it’s not a biggie.

I did however, clean up my query based on your first two points of feedback. This is cleaner indeed.


#+BEGIN_QUERY
{:title [:b "Complex Tasks list"]
:query [:find (pull ?b [*])
     :in $ ?currentpage %
     :where
     ; Unified condition: Either it's from namespace or it references the page
     [?b :block/marker ?marker]
     [(contains? #{"NOW" "LATER" "TODO" "DOING"} ?marker)]
     (or
       (and
         [?b :block/page ?p]
         [?ns :block/name ?currentpage]
         (check-ns ?ns ?p)
       )
       (and
         [?p :block/name ?currentpage]
         [?ns :block/name ?currentpage] 
         [?b :block/path-refs ?p]
       )
     )
    ]
:result-transform (fn [result]
                  (let [sorted-result (sort-by (fn [h] (get h :block/marker)) > result)]
                    (map (fn [m] (assoc m :block/collapsed? true)) sorted-result)))
:group-by-page? false
:breadcrumb-show? false
:inputs [:current-page]
:collapsed? false
:rules [
[(check-ns ?ns ?page)
 [?page :block/namespace ?ns]
]
[(check-ns ?ns ?page)
 [?page :block/namespace ?t]
 (check-ns ?ns ?t)
]
]
}
#+END_QUERY
2 Likes