Breadcrumbs in query with result-transform/sort-by?

Sorting by date, prio etc. in advanced queries removes grouping by page. Is there a way to add it back, or to insert link to original block next to each result. This is sometimes useful for context for e.g. a task.

Based on this: Separate query result sorting logic from result transform and other stuff linked there this might not be possible.

One of the default queries can be an example

#+BEGIN_QUERY
{:title "🔨 NOW"
    :query [:find (pull ?h [*])
            :in $ ?start ?today
            :where
            [?h :block/marker ?marker]
            [(contains? #{"NOW" "DOING"} ?marker)]
            [?h :block/page ?p]
            [?p :block/journal? true]
            [?p :block/journal-day ?d]
            [(>= ?d ?start)]
            [(<= ?d ?today)]]
    :inputs [:14d :today]
    :result-transform (fn [result]
                        (sort-by (fn [h]
                                   (get h :block/priority "Z")) result))
    :collapsed? false}
#+END_QUERY
1 Like

I’m interested in this too, I have a page for general todos on which I want to list todo’s from other pages too:

#+BEGIN_QUERY
{:title "TODOs from other pages"
 :query [
         :find (pull ?b [*])
         :where
         [?b :block/marker _]
         (not [?b :block/marker "DONE"])
         [?b :block/page ?p]
         [?p :page/journal? false]
         (not [?p :page/name "Misc todos"])
    ]
    :result-transform (fn [result]
        (sort-by (fn [r]
            (get r :page/name)) result))
}
#+END_QUERY

Without the :result-transform I get the page names in the blocks, but they disappear when the :result-transform is added.

I have the same problem! It would be great to conserve the breadcrumbs even with :result-transform

A trick I saw somewhere (Discord maybe) is the following:

(fn [result] 
  (sort-by (fn [h] (get h :block/priority)) 
           (map (fn [m] 
                  (update m :block/properties (fn [u] 
                                                (assoc u :page 
                                                       (hash-set (get-in m [:block/page :block/original-name])))))) result)
           ))