Exclude title/heading from the results of `org-roam-node-find` but show the aliases

Sometimes I create a headline note inside a regular file. Here is an contrived example:

#+title: Cars

Cars are ...

* Classification
:ID:  <some uuid here>
:ROAM_ALIASES: "Classification of Cars"

A car can be a Supermini, a large family car, ...

Now when I do a org-roam-node-find I get the following suggestions:

Classification of Cars

The second one is as desired but I don’t want to see the the rather generic suggestion “Classification”. On the other hand I don’t want to change the heading since it is already in a note called “cars” so it would be needlessly verbose to expand the title itself to “Classification of Cars”. In a real example the difference in verbosity can be more extreme (most of the time I find my nodes by just searching for the title and hence the title must be at least a bit verbose, on the other hand I try to be brief inside my notes).

I know about ROAM_EXCLUDE but it seems to be just a boolean flag which can only “turn off” the whole node. Is there an option which lets org-roam-node-find ignore the heading but still show the aliases? I couldn’t find something.

So… you want to list nodes only by aliases. Correct?

I believe this below should work (it works on my end).

It’s not easy. You need to do two things:

  1. Override function org-roam-node-list to list only aliases (without including title)
  2. Adjust org-roam-node-display-template to show aliases instead of title

Below, the two above are done temporarily without interfering your normal functions

I think you need lexical binding.

;; -*- lexical-binding: t; -*-
(defun my/org-roam-node-find-alias-only ()
  "It's like `org-roam-node-find' but only aliases without title.
This means if a node does not have an alias, it is not shown."
  ;; Temporarily replace `org-roam-node-list' to get only nodes from
  ;; aliases table
  (cl-letf (((symbol-function 'org-roam-node-list)
             ;; Anonymus function. Return list of nodes from aliases table
             ;; only.
             (lambda () (mapcar (lambda (e)
                                  (org-roam-node-from-id (car e)))
                                 [:select [node-id alias]
                                          :from aliases])))))
    ;; Temporarily set `org-roam-node-display-template' to show aliases
    ;; instead of title by replacing ${title with ${aliases
    (let ((org-roam-node-display-template
           (string-replace "${title" "${aliases" org-roam-node-display-template)))

@nobiot many thanks for your quick reply.

It goes in the right direction but it is not exactly what I want. I want an explicit way to say that for a particular node I want to ignore the title. In the Car Example it is the heading “Classification”. In fact, my use case - so far - only involves nodes which are just headings - because only for them it can happen that I choose a short title which is meaningless without context (of the “Parent-Node” - the file-node - which contains it).

Almost all my nodes are files, and often I do not use aliases. So a lot of nodes would be effectively “hidden” when I do my/org-roam-node-find-alias-only (I tried it).

I was hoping to accomplish the goal by writing something like this in my node:

* Classification
:ID:  <some uuid here>
:ROAM_ALIASES: "Classification of Cars"

I mean the :EXCLUDE_TITLE_FROM_NODE_FIND: t. I suppose for this to be efficiently doable the database had to be aware of this property - don’t know how it works. Do you think this could be doable, maybe some adaption of your my/org-roam-node-find-alias-only?

For this, I would probably avoid using aliases, and instead I’d show the “context” for heading-node titles with something like this.

1 Like

Thanks @nobiot this is a very good solution which solves the core problem!