Excluding ref nodes from find-node

Hi Everyone,

Is there a way to do sort of the opposite of org-roam-ref-find? I want to keep my ref nodes in the database but I don’t always want to see them when I search with org-roam-node find.

I’d like something like “org-roam-node-find-non-refs” or maybe a way to filter the results from org-roam-node-find.

Can anyone point me in the right direction? What’s the best way to attain this functionality that fits with the rest of the org-roam philosophy.


I’d say copy org-roam-node-find and adjust the sql (write your own sql statement) to exclude refs.

Thanks for the suggestion! That was not even on my radar, so thanks for the quick response. I’ll look into it. I appreciate the help.

“Copy” might have been a little too sloppy an expression on my part; apologies if it was misleading somehow.

I could think of two general approaches – I haven’t examined either of them, so please verify them on your end; there might well be a better approach.

  1. Use filter-fn and create a custom command that wraps org-roam-node-read
    In the custom wrapper command, you can pass your custom filter function to org-roam-node-read via filter-fn argument.
    To me, a key question to be answered is, can you programmatically inspect each node and tell refs vs others. I guess yes, but I’m not sure.
    One obvious disadvantage would be performance. The program would get all the nodes including ref nodes first, then examine each of them, and finally filter out ref nodes. Dealing with a large volume of notes might result in noticeably slow performance.

  2. My “copy” idea. org-roam-node-find is a very standardized small command, so it is rather easy to copy or create a wrapper for. It seems to come with a caching mechanism, so you would want to keep it. The actual SQL statement is written in org-roam-node-list. The idea is to have a custom node-list function with your own SQL statement, and somehow swap them when you want it.
    The key investigation is to determine how you can achieve this swapping mechanism. My guess is that you could use cl-letf to temporarily replace the call to org-roam-node-list with your custom function. @arozbiz has shared a smart use of cl-letf in his post. I believe the same idea could be applied in this case, too.

No worries! I appreciate your help.

I currently have a solution similar to your first suggestion. When I create notes that aren’t reference notes, I have a capture template that includes a tag called “note.” I achieve this by passing a filter-fn directly to org-roam-node-find that uses member to find nodes in combination with org-roam-node-tags.

I suspect that this is not a scalable method. I have on the order of 100 notes and it’s fine, but I want something that will keep up as I create more notes.

Your second suggestion is appealing and I think I’ll give it a try. Thanks for the rundown. I’m quite new to org-roam, so I really appreciate your help. I’ll give it a shot and see if I can get it working.

1 Like