Hi all, I have a number of pages which have a name as the Page Name (for example [[A Person]]), and for each page there is a property called company, which specifies the company they work for, e.g. company:: "ACME". I am trying to create a query to list all team members for a given company alphabetically. The following query returns all the team members but they seem to be listed according to the Journal entry date rather than alphabetically. Am I missing something obvious here?
(sort-by (fn [r] (get-in r [:block/page :block/name])) result))
sorts according to the name of the page that each found block (r) is in. If they are in the journal, then they are sorted according to the journal name (which may not be alphabet-aware itself).
But even the rest of your query doesn’t follow your description, even though it happens to return the team members. More specifically, it is not clear:
whether the value of property company:: is ACME or [[ACME]]
whether the property company:: of each person is assigned:
in that person’s page-properties
per “for each page there is a property called company”
in a block of some random journal entry
per “the Journal entry date”
Going by your current query, if you want to return (sorted) the team members, should probably do this:
Hi @mentaloid - many thanks for your help and apologies if my initial post was a little garbled. I’m still finding my way with Logseq. Essentially what I want to set up is a Page for a company (ACME) and a page for each Employee. On the Employee page, the “company::” tag will link to the ACME page. To answer your questions:
the value of the property company:: is [[ACME]]
each person’s page will have a proper called company::
Thanks again @mentaloid . I’m not sure that this works exactly how I want as it appears to sort based on the block (i.e. company:: [[ACME]]) is I use [:block/name] to sort, rather than on the Page name (Wile Coyote, Roadrunner etc):
Thanks for all the pointers @mentaloid, it’s a massive help to me. I’ve dug further into this based on your last feedback and it appears that I was missing “title:: Pagename” in the first block of each page. I had simply added “company:: [[ACME]]” and so even though it was the first block, it appears that it was treating it as a block property, not a page property. As soon as I added the ‘title’ property as well, the output comes out in alphabetical order as expected.