I have two blocks: “TODO Task A #[[DEMO PROJECT]” and “TODO Task B #[[DEMO PROJECT]]”
“TODO Task A #[[DEMO PROJECT]” is inline referenced in “DEMO PROJECT” while the other is not.
I want the query to show “TODO Task B #[[DEMO PROJECT]]”.
In other words, I need the query to show blocks with the following conditions:
It has a TODO, DOING, or DONE and;
It should have an inline tag #[[DEMO PROJECT]] and;
It should not be inline referenced in the “DEMO PROJECT” page.
So this is the code I got with the help of LLMs:
#+BEGIN_QUERY
{
:title "Unreferenced Tasks with DEMO PROJECT Tag"
:query [:find (pull ?b [*])
:where
;; Condition 1: Block must have a marker (TODO, DOING, DONE)
[?b :block/marker ?marker]
[(contains? #{"TODO" "DOING" "DONE"} ?marker)]
;; Condition 2: Block must contain the inline tag #[[DEMO PROJECT]]
[?b :block/content ?content]
[(clojure.string/includes? ?content "[[DEMO PROJECT]]")]
;; Condition 3: Block must not be inline-referenced in the DEMO PROJECT page
(not [?b :block/refs ?p])
[?p :block/name "DEMO PROJECT"]]
:collapsed? false
:breadcrumb-show? false
}
#+END_QUERY
However, when I applied the query it always gave “No matched results” no matter how many times I “troubleshooted” the query with the LLMs to the point that it already gave a bunch of errors (hence, why I asked here). Can someone help me fix this query? Anyway, thanks for helping.
Edit: Condition 4: I want the query to exclude also tasks written in the DEMO PROJECT page itself.
Then I told the LLM to rewrite the query so that it looks at the blocks in the DEMO PROJECT page and then if the block already exists, exclude it in the query result.
Here’s the result:
#+BEGIN_QUERY
{
:query [
:find (pull ?b [*])
:where
;; Condition 1: Block must have a marker (TODO, DOING, DONE)
[?b :block/marker ?marker]
[(contains? #{"TODO" "DOING" "DONE"} ?marker)]
;; Condition 2: Block must contain the inline tag #[[DEMO PROJECT]]
[?b :block/content ?content]
[(clojure.string/includes? ?content "[[DEMO PROJECT]]")]
;; Condition 3: Exclude blocks that are already listed in the "DEMO PROJECT" page
(not [?project :block/refs ?b])
]
}
#+END_QUERY