Finding all blocks tagged within a specific decade range

I do a lot of history research and tag certain blocks with a year (e.g. #1975). I can easily find all the related #1975 pages by searching for that tag or looking at that page.

What I want to do is to look at a #1970s page and find all the blocks tagged with anything in the 1970s decade. I can build a query for each decade but that’s not really extensible, so wondering if there is a more elegant solution anyone can think of (outside of tagging each block with the year and decade).

I don’t know if this will help.

#+BEGIN_QUERY
  {
   :query [
         :find (pull ?b [*])
         :in $ ?decade
         :where
         [?b :block/page ?p]
         [?b :block/properties ?prop]
         [?p :block/name ?title]
         [(clojure.string/starts-with? ?title ?decade)]
         ]
    :inputs [199]
    :breadcrumb-show? true      
   }
#+END_QUERY

Thanks for the response. I think it’s part way there, even though it doesn’t return any results for me. Seems like I need to click on the link for each individual year first before it shows anything. Indexing issue?

Here is the result I’m currently getting.

Any way to add additional properties to the view? Feel free to point me to some resource (which I have yet to find). I’ve managed to get this far with the query, but no idea how to add say the page title that the block appears on.

query-table:: true
  #+BEGIN_QUERY
  { :title [:b "Blocks tagged in the 1970s"]
    :query [
      :find (pull ?b [*]) 
      :in $ ?decade
      :where 
        [?b :block/ref-pages ?p]
        [?p :block/name ?tag]
        [(clojure.string/starts-with? ?tag ?decade)]
    ]
    :collapsed? false
    :breadcrumb-show? true
    :inputs [197]
  } 
  #+END_QUERY

Finally, can the inputs value be dynamic? Say the title of the current page, or a property of the current page?

Thanks heaps!

I was studying logseq, Clojure and Datomic yesterday to get my head around queries. I’m running this query and in the table view, I have some properties I can select to view by clicking the cog.
(pull ?b [*]) uses patterns to decide what properties to return and [*] is all of them.
See Datomic Pull | Datomic
It looks like you removed the clause [?b :block/properties ?prop] so you will have no properties returned.
I was working through https://bgrolleman.gitlab.io/logseq_publish_toolsontech/#/page/logseq%2Fadvanced%20queries yesterday and still haven’t got a clear view of the basics. That’s the trouble being 62. In logseq use the command t o to open all the blocks on that page.

1 Like