Limit (or even remove) the text output in a query

Simple question (hopefully). In an advance query, is there a way to do the following

  1. Reduce the number of displayed rows in the block column. I do not want it to display long texts (I crossed out the lines I want to remove)

  2. Or even remove ALL the cell content of the “block” column when what we find at that row is a page, not a block. Sometimes when the query has mixed results (block a properties), the block column could become annoying and just noisy…

Thank you!

Could you provide the query and some example blocks?

Sure! I will reformulate it with a detailed example.
I have a query that searches for pages and blocks that contains the string “:mailbox_with_mail:/”
When the tag is found in a block usually it is not too noisy (visually speaking). BUT when the tag is found in a page-property, the block column of that page displays too many data.

PAGES AND BLOCKS EXAMPLE:

This page contains tags on its page-property and on one of its blocks

This page only contains tags on its page-property
image

QUERY CODE:

#+BEGIN_QUERY
{:title "INPUTS (blocks & pages)"
:query [:find (pull ?b [*])
:where

[?b :block/page]
[?b :block/properties ?props]
[(get ?props :tags) ?mytag]

;; I find a partial string with the tag (just because of my specific workflow)
[(str ?mytag) ?str]
[(clojure.string/includes? ?str "📬/")]

;; get and compare status
[(get ?props :status) ?mystat]
     (or
      [(= "🟥" ?mystat)]
      [(= "🟨" ?mystat)]
     )

]
}
#+END_QUERY

OUTPUT EXAMPLE:


:question:QUESTION: How could I either

  • Remove all the data in the block column BUT ONLY when the row belongs to a page? (tag was found on a page-property, not inside a block-property). And mantain the information it is belongs to a block row (tag was found on a block).

  • OR at least, reduce the content displayed. Ideally, showing only one line. That is, the tag

Thank you!

  • It doesn’t have to do with a difference between pages and blocks, but with the content of the first line.
    • If you remove the first line from the example block, it behaves like the page.
  • Try adding the following lines before the final closing } :
    • to show only the first line:
     :result-transform (fn [result]
       (map (fn [r]
         (assoc r :block/content (first (clojure.string/split (:block/content r) "\n")))
       ) result)
     )
    
    • to show nothing when the first line is a property:
     :result-transform (fn [result]
       (map (fn [r]
         (def content (:block/content r))
         (def line (first (clojure.string/split content "\n")))
         (assoc r :block/content (if (clojure.string/includes? line "::") "" content))
       ) result)
     )
    
    • to show the page name when the first line is a property:
     :result-transform (fn [result]
       (map (fn [r]
         (def content (:block/content r))
         (def line (first (clojure.string/split content "\n")))
         (def node (if (clojure.string/includes? line "::") (get-in r [:block/page :block/original-name]) content))
         (assoc r :block/content node)
       ) result)
     )
    

Like a charm! thank you so much.

This works nice and I can happily continue my workflow, but after testing the solutions I’ve thought about the next modification. (And as mentioned, if it is too tricky to tackle I can live with the previous one). But I had this idea:

  • Is it possible mix the page and block into only one column? I mean, to create a dedicated column (called “node” for example) and place there:
    • the page link (if the tag was found on a page)
    • the block link (if the tag was found on a page)

Like this

I suppose this would have something to do with the result-transform…

  • I have expanded my answer accordingly.
  • Column page can be hidden from the settings of the table (top-right).
  • If you want the column to be named node, should:
    • hide column block
    • replace (assoc r :block/content node) with and update, e.g. like this
    • replace (assoc r :block/content node) with and update, e.g. like this

You mean like this?

:result-transform (fn [result]
(map (fn [r]
 (def content (:block/content r))
 (def line (first (clojure.string/split content "\n")))
 (def node (if (clojure.string/includes? line "::") (get-in r [:block/page :block/original-name]) content))
 
(update (:parent r) :block/properties (fn [p]
   (assoc p "NODE" (:content r) )
 ) )

) result)
)

Or like this?

:result-transform (fn [result]
   (map (fn [r]
     (def content (:block/content r))
     (def line (first (clojure.string/split content "\n")))
     (def node (if (clojure.string/includes? line "::") (get-in r [:block/page :block/original-name]) content))

     (update (:parent r) :block/properties (fn [p]
       (assoc r :block/content node)
     ) )

   ) result)
 )

I am getting an error both ways…

Thanks

I mean like this:

 :result-transform (fn [result]
   (map (fn [r]
     (def content (:block/content r))
     (def line (first (clojure.string/split content "\n")))
     (def node (if (clojure.string/includes? line "::") (get-in r [:block/page :block/original-name]) line))
     (update r :block/properties (fn [p]
       (assoc p "node" node)
     ) )
   ) result)
 )
2 Likes

Ok. I am not a master of datalog/clojure as you can see :sweat_smile: Thank you!

btw, do you have Ko-fi or similar?

1 Like
  • Nobody here is a master of datalog/clojure.
  • No Ko-fi or similar, sorry.
1 Like