Namespace query retrieve lower levels in the namespace hierarchy

Namespaces in queries for tasks, for example {{query (and (namespace [[Golf]]) (task TODO))}} not picking up lower levels in the hierarchy.

If I have TODOs in Golf/Level1 page then the query picks up the tasks without any problem. However if I put a task in Golf/Level1/Level2 page, the query doesn’t find the TODO. I’d like to find tasks at any level in the hierarchy.

Hierarchical pages are a great feature, but there is a bit of work to be done. When I search for “A/B” when there are lots of pages with the name “A/B/X” (A and B are single pages, X refers to multiple pages), often the search does not find “A/B”. this is not quite the same as your Feature Request, but related, I think.

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.

1 Like

Those queries work perfectly for me. Thank you