There’s a lot of information scattered about and a lot of specific situations to cover. So don’t worry about it!
There are two ways. Regular expressions or clojure string functions. I went with the clojure one as it is easier.
#+BEGIN_QUERY
{:title [:h3 "abc tasks (TODO)"]
:query [:find (pull ?b [*])
:where
(task ?b #{"TODO"})
[?b :block/page ?p]
[?r :block/original-name ?name]
[(clojure.string/includes? ?name "abc")]
(or [?b :block/path-refs ?r]
[?p :block/tags ?r])]}
#+END_QUERY
We need an extra check and a result-transform for the sorting.
#+BEGIN_QUERY
{:title [:h3 "abc tasks (TODO)"]
:query [:find (pull ?b [*])
:where
(task ?b #{"TODO"})
(or
[?b :block/scheduled _]
[?b :block/deadline _]
)
[?b :block/page ?p]
[?r :block/original-name ?name]
[(clojure.string/includes? ?name "abc")]
(or [?b :block/path-refs ?r]
[?p :block/tags ?r])
]
:result-transform (fn [result]
(sort-by
(min
(fn [d] (get d :block/scheduled 99999999) )
(fn [d] (get d :block/deadline 99999999) )
)
result
)
)
}
#+END_QUERY
I used the sorting from here for this:
PS. Sorry if something doesn’t work. I didn’t check. Let me know if you experience any issues.