Advanced query for pages with a tag

This will pull all the pages that have #inbox in their properties definition (tags:: #inbox).

#+BEGIN_QUERY
  {:title [:h6 "Pages tagged #inbox"]
   :query [:find (pull ?h [*])
           :in $ ?target
           :where
           [?h :block/page ?bp]
           [?bp :page/properties ?pp]
           [(get ?pp :tags) ?t]
           [(get ?t ?target)]] 
   :inputs ["inbox"]
   :table-view? false}
#+END_QUERY

This will pull all the blocks that are tagged with #inbox.

#+BEGIN_QUERY
  {:title [:h6 "Blocks tagged #inbox"]
   :query [:find (pull ?h [*])
           :in $ ?target
           :where
           [?p :block/name ?target]
           [?h :block/refs ?p]] 
   :inputs ["inbox"]
   :table-view? false}
 #+END_QUERY

An interesting gotcha with the first query is that [(contains? ?t ?target)] will fail to return true, even if the page has the tag we are looking for. ?t yields a Set and apparently the way to confirm that some tag exists is by going through its hash: we get an exact match or the function call returns nil, which is evaluated as either true or false in Datomic as it seems. (Gotcha Reference)

On a side note: What keeps trowing me off is that I cannot specify a more complex predicate, or fetch condition, for the tag I’m querying. For instance, I would like to match some tag if my ?target is a substring of that tag or if the tag begins with or ends with it.

For example, instead of [(get ?t ?target)], I would expect to somehow be able to match a page property tag with [(some #(str/includes? % ?target) ?t) _] or [(some #(str/starts-with? % ?target) ?t) _].

Perhaps someone else can help out here?