Show Random Note (incl. keyboard shortcut)

Hello community, hope you’re all doing good :slight_smile:

A feature request: It should be possible to display a random note / page at the touch of a button (even better: via short command).

This functionality is very useful for periodically reviewing my notes. In fact, for me, it was a key feature which persuaded me to, first, work with the program ZKN3 and now, Obsidian. (And now, as I really feel comfortable with Logseq, I want to have it in Logseq :slight_smile:) Also, to randomly show a note / page can be a second way of slow, but efficient repeated learning – apart from cards. (which are now included - yay!)

Use case (example): When you work with a Zettelkasten-approach – as I do –, notes tend to be forgotten. With time, there are too many of them and in fact, the method relies on forgetting and then rediscovering interesting notes, pages and snippets. Also, you will most certainly not consistently use the same key words for the same phenomena over a sustained period of time – this, quiete naturally, changes with you gaining knowledge and your PKM and workflow building up. As a consequence, one ends up with duplicates, unfinished notes or notes one would like to reformulate, etc. It is useful to be aware of that and to have some counter-measures at hand.

So, apart from having a) an index, MOCs and other handy tools for a structured hierarchy, b) the graph for my visual pleasure and rough overview of ‘what is there’, I periodically open a random note – and quiete often re-discover something which I’d written a long time ago but which I’d completely forgotten about. Often, these notes / pages come in handy and turn out to be either useful for my current projects or open up new connections to other areas of my thinking.

Apart from that: It is a fun way of roaming about your knowledge garden. :+1:

What are your thoughts on that? Would you like to see something like that in Logseq too?

You can almost do what you want using Logseq Advanced Query that you put on any page, say Random Page Query and include this query by Weihua on Logseq Discord Datalog channel. It’ll show a link to a random page each time the block refresh.

#+BEGIN_QUERY
{:title "Give me a random page!!!"
 :query [:find ?name
         :where
         [?b :block/name ?name]]
 :result-transform (fn [result]
                     [(rand-nth result)])
:view (fn [result]
       [:div.flex.flex-col
        (for [page result]
          [:a {:href (str "/#/page/" page)} (clojure.string/capitalize page)])])
 :collapsed? false}
#+END_QUERY
2 Likes

Oh wow, that’s nice. Thank you very much. Unfortunately, it does not seem to work properly with my set-up… don’t know – a while ago I switched from Windows to Mac, so maybe the problem is hidden there somewhere? (See screenshots: The query seems to link to a file that can’t or shouldn’t exist on Mac. Namely c:/users/Anwender… etc.)

So, first all looks well:

Then, when I click on a file (in this case another one, a page which should exist, namely ‘Work’):

When Logseq does that, nothing helps anymore. Logseq will not close, nor refresh, nor can I quit the program. It just stays like that. Hm. I’ll look into the problem of why Logseq refers to files, that shouldn’t exist (C:/users/Anwender…) and then report again. Maybe you have an idea?

In any case – the query itself is very neat! Thank you.

It worked on Windows in v0.2.7. Sorry, can’t help much more, I’m only a copy&paste Logseq query coder. Perhaps @weihua can give a hand?

No problem, thank you! I’ll look into the issue of Logseq refering to files, which existed on my Windows-Computer, but shouldn’t anymore on MacOS.

Some how the query shows a link but clicking it does not go to the page

#+BEGIN_QUERY
{:title "Random page: "
 :query [:find ?name
         :where
         [?b :block/name ?name]]
 :result-transform (fn [result]
                     [(rand-nth result)])
:view (fn [result]
       [:div.flex.flex-col
        (for [link result]
         [:a {:href (str "#/page/" link)} link]
    )])
 :collapsed? false}
#+END_QUERY

This works for me. Partially based on what’s here, and what’s at Advanced query for a list of all the links in current page