There's got to be an easier way to query pages, right?

I have been searching for hours to find how to build a simple query that returns the pages where the frontmatter includes custom tags like
“type:: essay”
“status:: draft”
Every variation of a simple one line query only returned blocks. Eventually, I found this example:

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

Can someone please help me understand why I can’t just use something like:

query{{ page type essay }}

And have it return a table of where the columns are “Title (of page)” and “status”?

The learning curve on this seems surprisingly steep and all of the examples suffer from nested explanations. (That is, the examples seem to read like “Tag the tag with “tag” and the tag tags to the tag”.)

1 Like

You need to use page-property for that.

{{query (page-property type essay)}}

@schmy, this is your answer. It’s explained in the documentation (although it lacks a thorough explanation):

What you stumbled upon is an advanced (Datalog) query. You won’t need it to query simple properties, but you do need to use the correct filter.

For example, for properties that appear in the first block of the page, you need to use page-property, whereas properties that are given to individual block/branches can be found using the property filter:


Thank you for the reply, @Ramses

Unfortunately, that link seems to have expired.

If I ever get my head around this stuff, I hope I can contribute to the documentation and the rest of the community.

@Ramses was actually linking to some specific blocks on this page, which contains most of the information about simple queries. Maybe the IDs that are used to refer to those blocks have changed.

1 Like

Thank you for pointing it out @starryveshch :pray:

Weirdly enough, the URL of the block changed. No idea why, but definitely search the queries page for the property heading.

1 Like

Thanks again, Ramses and @starryveshch.

I hope you don’t mind if I provide a little more feedback on the examples on that page because I think I see now why that page is very confusing to a beginner.

The table that’s generated by the page-properties query is a list of terms that are both page names and other LogSeq functions, and so it’s not immediately clear which functions are required and which are just the results. For example, I’m looking for pages, but the first result is called “Page embed”, so do all pages have to start with “Page”; or does this query only work if the page is embedded? So while I’m trying to understand queries, I’m also now reading up on embedding to see why this is required. (It’s not, but that’s not clear from the example.)

More succinctly, the examples are too self-referential.

Can I make the suggestion of creating a section of the docs site that is entirely unrelated to LogSeq, programming, or even computers, but that is still well linked enough to demonstrate the query functions?

For example, people seem to like pets; people generally have an understanding of what dogs and cats are without having to read up on additional features of mammals, etc. So perhaps the queries could look like:

{{query (page-property colour black)}}

and the results would be a table to the pages about Bobby the bobcat and Nero the wolf because they are both black. That is, I am less likely to confuse the terms “colour”, “black”, “bobcat”, etc., for other functions in LogSeq.

Thank you again for your time in reading and responding to my concerns. I do appreciate the work you are all putting in, and I want to see you succeed. I just hope that my comments can take the edge off the learning curve and open up the service to a broader community.

1 Like