Hi,
I’m trying to create a block search query that will return results in chronological order by reference to its journal page.
The block search is for a specific [[name]] as the value for the block key ‘who’. For each block identified by the search, I want to produce a table with the various block keys for the block (these are ‘matter’, ‘who’, ‘organisations’, and ‘document’).
But the table also needs to include the name (i.e. the displayed date) for the journal page.
In theory, I could achieve all of this by just writing {{query (property who [[name]] )}} . But, annoyingly, the page column does not organize itself by reference to its true date but by reference to the start number of its displayed date (so the journal page 28th April appears above 3rd May when sorting for the most recent first).
Is there a means of keeping the linkable journal page name in the table but having the entries sorted in their true date order?
Hope this makes sense!
Mark
Something like this:
#+BEGIN_QUERY
{
:query [:find ?date (pull ?b [*])
:keys date b
:where
(property ?b :who "name")
[?b :block/page ?p]
[?p :block/journal-day ?date]
]
:result-transform (fn [results] (map :b (sort-by :date results)))
}
#+END_QUERY
Thanks for the reply (and the code).
This generates the table of information but has the same problem I’m running up against. Sorting the entries by date does not result in them being listed by date order. The higher date numbers of any month are listed above the lower date numbers of other months.
I attach a screenshot to show what I mean. The first entry for 28 April should appear below the 7th entry for 18 May, not above it.
It seems an odd glitch. I assume I’m missing something obvious 
The order can be easily inverted. Try this variation:
#+BEGIN_QUERY
{
:query [:find ?date (pull ?b [*])
:keys date b
:where
(property ?b :who "name")
[?b :block/page ?p]
[?p :block/journal-day ?date]
]
:result-transform (fn [results] (reverse (map :b (sort-by :date results))))
}
#+END_QUERY
- But you should not click on the title of the page column, because then it sorts alphabetically.
- Mind that the sorting persists, so should either:
- use a new block
- remove the hidden sorting property (
query-sort) by editing the raw file
That’s brilliant!! (maybe not for you
)
Thanks so much.
Mark