Advanced query for multiple links/tags

I have two types of structure for my gratitude journals:

  • [[journal]]
    • [[gratitude]]
      • For the wind in my hair…


for a page tagged as journal:

  • tags:: journal
  • [[gratitude]]
    • For the smell of coffee in the morning…

If I use {{query (and [[gratitude]] [[journal]])}} this only returns the first scenario. The page tag method does not work.

My attempt at an advanced query looked like this:

{:title "Find: journal2 and gratitude2"
:query [:find (pull ?b [*])
[?b :block/ref-pages ?p]
[?p :block/name ?tag]
[(contains? #{"journal" "gratitude"} ?tag)]]

But the logic works as an OR statement - and so I get results for journal, or gratitude, which I don’t want, as well as the journal AND gratitude results that I do want…

Any ideas? Thanks.

Welcome Nick!

{:title "Find: journal2 and gratitude2"
 :query [:find (pull ?b [*])
   [?b :block/path-refs [:block/name "journal"]]
   [?b :block/path-refs [:block/name "gratitude"]]

Thanks! This matches the first type of my gratitude journal structure, but not the second - i.e. it doesn’t match where I have a page tag. Maybe I’m mistaken with how page tags work…

Could you maybe post something you would like to be matched?

Thanks for your help so far. My test page looks like this:

tags:: [[journal]]

- [[gratitude]] for...
	- dhjlfa
	- fjal
	- fjhaiskohjofasd
	- fashj
	- fsahj

I want to search for [[gratitude]] AND [[journal]], but am struggling to return this when the ‘journal’ part is a page-tag.