Trouble querying page-tags and inline tags

My Test Page looks like this:

There are two inline references to the same tag in this journal entry:

When I write a simple query for the tag I don’t get all the blocks that are inheriting the tag1 reference from the page-tag, just a reference to Test Page:
{{query [[tag1]] }}

So I modified the query to look for page-tags or inline tags:
{{query (or [[tag1]] (page-tags [[tag1]]) )}}


But that fails like so:


That appears to be a bug, but I wasn’t able to find any reference to it.
I found a work around for the bug by wrapping the or clause in an and clause with a dummy argument that will always return true. This of course is not elegant, but it does bypass the bug and give the correct results by returning all the proper blocks:
{{query (and (or [[tag1]] (page-tags [[tag1]]) ) (not #blank) )}}


I don’t find it very intuitive that I have to specifically search for a tag as a page tag and an inline tag, but I can live with that. Though I’m sure it will be the source of many errors in the future.
Is the or clause issue with page-tags a known bug?
And most importantly is there a better way to do this?

Jay

  • The so-called simple queries are quite limited in what they can achieve.
  • Blocks do not inherit anything from the page they are in.
    • They just have a reference to their page.
  • Your query is (probably unintentionally) trying to mix BOTH pages and blocks.
    • This is NOT expected to work.
  • If you describe your actual need, we may come up with a better way.
    • Though it may end up being an advanced query.

I am most definitely trying to mix page-tags and inline tags.
My Test Page and my journal example show what I am actually trying to achieve.
I want to assemble all the blocks with tag1 associated with them, whether that be by page-tag or inline tag, onto one page.

Try this advanced query:

#+BEGIN_QUERY
{
 :query [:find (pull ?b [*])
   :where
     [?tag1 :block/name "tag1"]
     (or-join [?b ?tag1]
       [?b :block/refs ?tag1]
       (and
         [?p :block/tags ?tag1]
         [?b :block/page ?p]
       )
     )
 ]
}
#+END_QUERY

Thank you sir! That works beautifully. I guess it’s time to learn another language, so I can query my notes now.