Org-roam-search

search org roam database using org-ql type syntax.
For example, the following query
tag:tag1,tag2 title:title1,title2 both:query1,query2 query3 query4

searches for file with tag tag1,tag2,query1,query2,query3 and query4 and has in titles/aliases title1,title2,query3 and query4.

alpha software. I have been using it daily as a drop-in replacement for org-roam-find-file.

works with org-roam version 1. It can be easily ported to org-roam verison 2.

4 Likes

Very cool! @KirillR and I have been thinking about something like this wrt org-roam-ui. Do you think this could somehow:

  1. Do queries like: have tag X and be linked to files/nodes with tag Y?
  2. Eventually be combined with org-ql like queries? So you could do something like: show all nodes with tag X and Deadline Y? This could probably already be done in here, since org-roam stores all org properties, but there are probably things org-ql can look for that aren’t stored in the org-roam-db
1 Like

@ThomasFKJorna

It uses org-ql like queries. Search string to sexp conversion code is from org-ql. Like org-ql, you can define custom search types.
Both features you propose are possible. You would need to define a search type and appropriate transform and stringify form for it.
Transfrom converts the search type into a searchable entity. For example, the search term
tag:tag1,tag2 is transformed to

(and  (like tags:tags tag1)
      (like tags:tags tag2))

which is a valid where clause for emacs-sql.

Stringify form displays the search term appropriately within helm or consult. for example, the search string tag:tag1,tag2 query1 query2
is stringified to
(tag1,tag2) query1 query2
look at org-roam-search/org-roam-search.el at 679da10768fb651bf74b6729c448b3dd74a24689 · natask/org-roam-search · GitHub

I have upgraded to org roam search to support org roam v2.

now supports out of the box filtering by titles, tags, olp, level properties of nodes.
sorting is also implemented but not at the prompt level. Users will need to write a sorting clauses compatible with order-by sql clause.

2 Likes

Looks cool! :ok_hand:

There’s no way to search for nodes that contain certain backlinks, is there? For example, to search for all nodes that link to Node A and Node B.

That is awesome! We could then maybe use this for Some dashboard-like extensions and 'overviews' for org roam - #34 by ThomasFKJorna

(I see you already commented there as well)

not yet.
However, It is straightforward to implement dest: and source: . org-roam-url already does the latter.
the issue is what type of interface to use. I have made the following issue to track the feature. feel free to discuss here or there.

1 Like

Yes. I currently have an integration between org-roam-search and delve.

My current workflow is search stuff with org-roam-search. Display results in a persistent fashion using delve-show which works like embark-export and can shuttle query string back and forth org-roam-search. And find nodes linking to urls from the browser using org-roam-url. I see that org-roam-ui and delve are now intergrated.

Currently filtering and sorting are conducted within the sql search. if view tables are merged into org-roam, I envision filtering and sorting within emacs will become viable.

neat. Is it possible to filter out notes with a tag, e.g.not tag:dontwant or -tag:dontwant?

yes. the default syntax for negation is !. eg !tag:dontwant
look at sexp-string/sexp-string.el at 20b49b2594e97f56729e7c043a2263c4f0e1d8f7 · natask/sexp-string · GitHub if you want custom syntax.

newbie question.
because I am new to emacs and org-roam.

i am used to installing packages from elpa/melpa

how do i install org-roam-search though?

because i really need its functionality.

i have just started my org-roam zettelkasten and am a hundred notes in and would love to search by tags or properties

any help appreciated. thank you.

One of these days I will try to place it on melpa. To quickly try it copy paste code in https://github.com/natask/sexp-string/blob/master/sexp-string.el and https://github.com/natask/org-roam-search/blob/master/org-roam-search.el into an empty buffer and run eval-buffer. After that read the readme on https://github.com/natask/org-roam-search to see how to use it.
To have it load with emacs it depends on which emacs distribution you are using. Follow the tutorials for the one you use. the core github repos to include are “natask/org-roam-search” and “natask/sexp-string”.

If you are on doom emacs, place the following code in packages.el in ~/.doom.d and run doom upgrade

(package! org-roam-search
  :recipe (:host github
          :repo "natask/org-roam-search"
          :branch "master"))

(package! sexp-string
  :recipe (:host github
          :repo "natask/sexp-string"
          :branch "master"))

I also set up the following in ~/.doom.d/config.el

(use-package org-roam-search
    :after (org-roam)
    ;:custom
    ;(org-roam-search-default-tags '("stub"))
    :bind (:map global-map
          (("C-c n f" . org-roam-search-node-find))
            :map org-mode-map
          (("C-c n i" . org-roam-search-node-insert)))
    )
1 Like

Thank you so much for helping out @savnk! will give it a whirl.

Hey, sounds really cool!

I wanted to give it a try right away, but I get an error message saying that delve-show is missing. This happens both when copying and evaluating the contents of the two files you pointed to and when adding your snippets to my Doom config.

I checked your GitHub repo, but only found delve, no delve-show.

same here, thought i made some mistake. probably i list of dependancies i need to have installed already? i use vanilla emacs with very few packages installed so far. and everything is currently installed using package.el

sorry guys, I forgot to include delve-show. It would be easiest to remove the line (require delve-show) from org-roam-search. delve-show is not critical for the core function of this package. I use it to export search results into a delve buffer, which is a buffer that is aware of org roam constructs, so that I can interact with multiple search results with ease.

I have updated the read me to include quick experimentation and installation guide.

1 Like

@savnk you sir, are a mensch! Thank you so much, but I think I am too new, to be doing this
Will return when I am a bit more experienced with installing stuff in emacs

Right now when I took your advice and put it all in a buffer and removed delve, and then ran org-roam-search-node-find or file-find then I get a

concat: Symbol’s function definition is void: s-downcase

and i don’t want to trouble you further without me knowing what I am doing wrong :slight_smile:

Cool, thanks! Works for me now using Doom :slight_smile:

I’m most excited about the ability to search for nodes with specific (sets of) backlinks.
I gave it a shot but couldn’t get it to work properly.

For example, which query would I use to get a list of all nodes linking to the nodes ‘foo’ AND ‘bar’? I get (only) false positives when I use source:foo or destination:foo.

1 Like

Doom Emacs is a good place to start if you’re new to Emacs. That got me off to a good start two years ago.

1 Like

s-downcase is a function within package called s.
install s from melpa. you may also need to install peg and dash from melpa. (use package-install command to install these).
like @wuqui said, starting out with doom emacs or in general with another distribution is wise because it comes with majority of the things you will need preinstalled. I started out with spacemacs and switch to doom because I

1 Like