Refresh Sort Order for Advanced Query Results

I managed to create a query that sorts pages into created-at chronological order. Then I clicked on the “page” title in the results table which sorted the page titles alphabetically. Now I can’t go back to chronological order.

Is there a way to “reset” the result ordering back to chronological? I tried Refresh and Re-index but Logseq remembers that I chose to re-order by page title.

Here’s the query if it helps:

#+BEGIN_QUERY
{:title "YouTube Videos - Newest First"
 :query [:find (pull ?p [*])
         :where
         [?p :block/name ?name]
         [?p :block/tags ?t]
         [?t :block/name "youtube video"]
         [?p :block/created-at ?created]
         ]
 :sort-by (fn [p] (get p :block/created-at))
 :result-transform (fn [result] (reverse result))}
#+END_QUERY

Welcome. Add in the block the following line:

query-sort-by::

Sorry I’ve got no experience with advanced queries, could you paste the complete code block @mentaloid?

  • This is not part of the advanced query.
    • i.e. it doesn’t affect its results
  • It is part of the block’s properties.
    • i.e. it affects the block’s rendering
  • Therefore, should add the suggested line outside the body of the query, i.e. either:
    • above #+BEGIN_QUERY
    • below #+END_QUERY

Thank you @mentaloid - how do you specify what field to order by? Would I use the variable created or block/created-at ?

I’ve noticed that in the results of the query all the results in the created-at column are exactly the same date and time so the query doesn’t work after all. :cry:

  • Logseq is beta software.
    • You’ve been unfortunate-enough to face two of its issues at once.
  • query-sort-by:: is a hidden property
    • It’s not meant to be directly used under normal circumstances.
      • The reason of usage in this occasion is because the user interface misses the removal of sorting (that’s the first issue).
  • :block/created-at is not reliable.
    • It gets updated on every re-index (that’s the second issue).
    • For its proper usage should wait for the DB version.
      • Meanwhile can use the journal and sort by :block/journal-day

Thanks for being so helpful @mentaloid. I’m happy to wait for the DB version for this to work, it’s not something I need urgently just a nice-to-have.