logseq / docs

Logseq documentation
https://docs.logseq.com
MIT License
124 stars 90 forks source link

Advanced query example with `:block/tags` #95

Closed gdw2 closed 1 year ago

gdw2 commented 1 year ago

I tried the advanced query below src here and it didn't return any results, despite having pages that have #programming tags.

      #+BEGIN_QUERY
      {:title "All pages have a *programming* tag"
       :query [:find ?name
             :in $ ?tag
             :where
             [?t :block/name ?tag]
             [?p :block/tags ?t]
             [?p :block/name ?name]]
       :inputs ["programming"]
       :view (fn [result]
             [:div.flex.flex-col
              (for [page result]
                [:a {:href (str "#/page/" page)} (clojure.string/capitalize page)])])}
      #+END_QUERY

I suspect the example is wrong, particularly the :block/tags part, for two reasons:

  1. When I right click on a page and select the "(Dev) Show page data" option, I see the page's attributes, but I don't see a :block/tags attribute.
  2. When querying logseq for any blocks or pages with the block/tags attribute, nothing is returned.
#+BEGIN_QUERY
{:title "All tasks"
 :query [:find (pull ?b [*])
         :where
         [?b :block/tags _]]}
#+END_QUERY

Could this example be wrong? If so, how would one do this query?

gdw2 commented 1 year ago

This seems to work for me:

#+BEGIN_QUERY
{:title "All pages have a *programming* tag"
 :query [:find ?name
         :in $ ?tag
         :where
         [?t :block/name ?tag]
         [?b :block/refs ?t]
         [?b :block/page ?p]
         [?p :block/name ?name]]
 :inputs ["programming"]
 :view (fn [result]
       [:div.flex.flex-col
        (for [page result]
          [:a {:href (str "#/page/" page)} (clojure.string/capitalize page)])])}
#+END_QUERY
logseq-cldwalker commented 1 year ago

Hi. The documented query works for me with the following md page:

tags:: programming

The command shows :block/tags:

Screen Shot 2023-04-20 at 10 14 47 AM
gdw2 commented 1 year ago

Thanks.

I'm relatively new to logseq and the advanced query page seems to use 'tags' to mean backlinks included in a block as well as putting the tags property on a page. I wasn't aware of the latter use.

I'll close this issue.