Query for any time [[some page]] mentions <% current page %> or <% current page %> aliases

I cannot figure out how to include the current page’s aliases (dynamically) for the life of me, is there a way to do this with a simple query, or do I have to learn advanced queries? My job is taxing enough on my brain, I don’t want to learn advanced queries, please help! :joy:

Unfortunately it indeed seems to not be supported for simple queries.
Here’s a basic advanced query that searches as specified in the title. (I assume with mention you mean a linked reference)
Let me know if you have any more specific needs and maybe we can come up with some good queries together :slight_smile:

#+BEGIN_QUERY
{:title ["Query by page & alias"]
 :inputs [:current-page]
 :query [:find (pull ?page [*])
   :in $ ?name
   :where
     [?current :block/name ?name]
     (or-join [?block ?current]
       [?block :block/refs ?current] 
       (and 
         [?current :block/alias ?alias] ; this attribute is available only when alias:: has been specified as a page property.
         [?block :block/refs ?alias]
       )
     )
     [?block :block/page ?page]
 ]
}
#+END_QUERY
2 Likes

Hey, this is above and beyond helpful, thank you!

1 Like

I do need help refining this though. The more specific use is:

  • I have a page called Timeline that houses a long list of blocks, each block may reference a single or multiple characters.
  • I have pages for those characters.
  • I want those character pages to query the Timeline and return blocks that reference the current character page or its aliases. The goal being to build personal timelines from the source timeline.

Does that make sense? I think we’re close but I don’t know how to adjust the query to search that specific page and return those blocks.

Yes that makes total sense :slight_smile: and we are nearly there indeed.
We need to add that the block is on a specific page.
Let me know if this gives the result you need.

#+BEGIN_QUERY
{:title ["Query by page & alias"]
 :inputs [:current-page]
 :query [:find (pull ?block [*])
   :in $ ?name
   :where
     [?page :block/name "timeline"] ; name is always lowercase.
     [?current :block/name ?name]
     (or-join [?block ?current]
       [?block :block/refs ?current] 
       (and 
         [?current :block/alias ?alias] ; this attribute is available only when alias:: has been specified as a page property.
         [?block :block/refs ?alias]
       )
     )
     [?block :block/page ?page] ; the block that we found needs to be on the timeline page.
 ]
}
#+END_QUERY
2 Likes

This worked perfectly and it’s absolutely glorious. I suppose this is proof I need to put time in and get comfy with clojure. Thank you so much Siferiax!

1 Like