Searching ROAM_TAGS (or properties generally)

I’m curious how one would use ROAM_TAGS in terms of searching or aggregating based on those values.

A basic example is just related to ROAM_TAGS. Let’s say I’ve marked a bunch of recipe files with #+ROAM_TAGS: recipe. How would I then search for all the files with that tag? If that’s not possible, what is the actual use of marking files with ROAM_TAGS?

A more complex example: imagine a set of recipe files that have other properties in them like, say, #+MEAL_TYPE. How could I search this property to get, say, all the soup recipes?

I’m new to org generally so it could be that my confusion here is also stemming from a confusion about basic org-mode. My sense is that in regular org-mode the practice would be more along the line of having fewer files with multiple entires in them, and that you might filter a single document to show only certain matching entries. Wth org-roam, my sense is that the tendency is rather to create smaller “atomic” files. But if that’s the case in org-roam, you’d want to be able to filter/match on these properties/tags across the files no?

Hopefully someone can set me down the right path here…

I am not completely sure in my answer, but that could be a starting point.

Partly answer to your question is in org-roam documentation:

tags are firstly for elist functions and commands, they allow to add metadata to the file that would influence for example how is that file displayed in an interactive command.

Overall in Org Mode #+something is a file property
Here #+roam_tags is a specific property that is created specifically for org-roam functioning
(And I don’t know specific examples for how it is used)


For your situation you could use org-roam linking
i.e have a separate org-roam file for “soup”
and from inside of each soup recipe link to the “soup”

Then on the “soup” page the backlinks would contain all the recipes

There is a nice roundabout way to do what you want to do using the Hugo website generator.

Hugo understands Org Mode files by default.

If you store all your org files in the content folder of a Hugo setup, then you can create tags as you see them fit, i.e.

#+title: This is a recipe
#+tag: recipe
#+ingredients[]: potatoes cream chicken bread

When you generate the website, Hugo creates category pages. You don’t have to publish the site s Hugo has its own web server.

Just a thought…

I also don’t understand what the purpose of #+roam_tags is.

ox-hugo uses #+HUGO_TAGS, I don’t think this is an Org-mode thing. Afaik, Org-mode uses #+filetags. It’s easy to add more sources of obtaining tags (e.g. you can also add a source to include items from #+tag).

Basically if you don’t see the need for tagging, then you don’t really have to worry about it. I don’t manually tag my notes, I just use the directory name as a tag, so as to separate literature notes from concept notes.

The original question wasn’t about tags specifically as much as it was about properties, and how you might use them to do searching/filtering in a org-roam workflow. I suppose I discovered along the way that I don’t know what you would do with roam_tags once applied, but the question is maybe better thought of in terms of the recipe example I gave. Let’s say I’d I added a property meal_type to a set of files and wanted to view all recipes where that property included the value “dinner”? I guess one could add to that scenario that all the recipes had a roam_tag value “recipe”…

So it seems like you want to be able to perform bulk queries on your Org-roam files. This seems like a task that org-ql already neatly solves.

I’m not sure either, since I don’t tag manually at all. But I’m happy to hear from people who use it extensively in their workflows.

@jethro org-ql looks very promising! Thank you for the tip.

On the matter of roam_tags: so when you organize thing into sub directories that isn’t necessarily for the purpose of “tagging” the files within, but just file system organization? You never query the tags in any way?

@jethro I wonder if you have something you could share in terms of how you use org-ql with org-roam. I’ve installed org-ql, but am having a hard time understanding how it can be configured to look at the files in my org-roam notes directory. I have things laid out as:

~
|--org
   |--notes ;; org-roam notes

org-ql does not search recursively and so I somehow need to point it to the org/notes directory. I was playing around with directory-files but was struggling to get this to work since this fn seems to pull in directory file paths as well as file file paths, causing org-ql to fail.

Wonder if you’ve solved this already in some way…?

I’m also curious how you create files as it appears from this thread that there’s now easy way to create an entry in a subdirectory.

I don’t use org-ql myself, my workflows are much simpler (and perhaps suboptimal). I just write down things that seem important, and try to make sure they can resurface when they should later on. I don’t query tags in any way, yes. They are just a visual guide in the interactive commands for me.

I create all files through the org-roam-capture interface, you can specify the sub directory via the :file-name attribute in the capture template.

2 Likes

if you already use org-roam then you can search the database org-roam generates. for example to find all files with tag “people”.

    (setq-local db (emacsql-sqlite3 (expand-file-name "org-roam.db" org-roam-directory)))
    (defun my/org-roam-files-with-tag(tag)
      (emacsql  db
                [:select [file]
                         :from tags
                         :where (like tags  $r1)] (format "%%%s%%" tag)))
    (print (-flatten ( my/org-roam-files-with-tag "people")))
1 Like