How to create a link to a org-roam search?

Imagine you’re working on a project or research (in org-mode), and you’d like to see your notes that are tagged T or Y, and have links to or from Notes A, K or M. Not a hand-made list, but the updated-for-now list.

Of course, that link runs a search on org-roam.

How do we make a search link like that?

Sorry if it’s obvious and I just didn’t catched it, I’m learning as I go forward. :slight_smile:

Thanks a lot…

Right now you would write your own SQL query for the db. Getting the SQL right isn’t the most fun, but once you have it you’re done.

org-mode helpfully has an elisp: link-type that will run any elisp command you use as its ‘path’, eg. elisp:(find-file "Elisp.org") See here

Running a query is actually pretty easy if you look in a function like org-roam-db--get-titles (do C-h f in emacs), or just look through the source code in org-roam-db.el.

Once you decide on a query you can either link to it or else use a code block in org-mode to write the code and display the results (see here, this is why org-mode is awesome). Something like:

#+BEGIN_SRC elisp
(org-roam-db-query 
  [:select [from] :from links :where (= to $s1)] "path/to/NoteA")

#+END_SRC

That will return all of the filenames to notes that link to Note A. To add more filters (Notes K, M, tags) you can add more SQL or elisp until you get what you want. You can also add things that will output them as file: links to make them functional and navigable if you want (sidenote: I’d be interested if this would work for literally any language that has a SQLite package, if people wanted to rabidly avoid learning elisp).

There should probably be an easier way to do all of this in the future. I would guess it would mostly involve the graph abilities people are working on :slight_smile:

EDIT: I should add that org-roam-db--connected-component also exists, and may suit your needs!

1 Like

I just discovered that emacs Deft can be a big help with this. There’s some integration info in the org-roam manual. Use underscores in Deft in place of spaces in titles (since org-roam makes that conversion for filenames which will show up in the links) and you’ll be good to go.