Namespace query retrieve lower levels in the namespace hierarchy

If you have a namespace like this: [[myspace/aaa/bbb]] with tasks on page aaaa and bbbb

Then this will find the tasks on page aaaa

 #+BEGIN_QUERY
 {:title [:b "my title"]
 :query [:find (pull ?b [*])
 :where
 [task ?b #{"TODO"}]
 [?b :block/page ?p]
 (namespace ?p "myspace")
 ]}
 #+END_QUERY

To also find tasks on page bbbb, use:

 #+BEGIN_QUERY
 {:title [:b"Namespace search"]
 :query [:find (pull ?b [*])
 :where
  (task ?b #{"TODO" "DOING"})
  [?b :block/page ?p]
  [?p :block/name ?name]
  [(clojure.string/starts-with? ?name "myspace/")]
 ]}
 #+END_QUERY

As alternatives to [(clojure.string/starts-with? ?name "myspace/")] there are also:

  • clojure.string/ends-with?
  • clojure.string/includes?

With combinations of these you can find any namespaced tasks you need.

3 Likes