Exclude frontmatter (or certain frontmatter keys) from search results

Use case or problem

I have a large number of markdown files in Obsidian, and many of them have a lot of frontmatter. When I search for a string, I often get results found in the frontmatter, and these are not relevant for my use. For example, the frontmatter can contain references to other notes, and these references can swamp the actual note that I am looking for in the search results.

I would like a way to either ignore frontmatter entirely in seach, or provide a way to ignore frontmatter keys that match a given pattern.

Proposed solution

I would be happy for search to ignore frontmatter entirely - but I imagine that will be a problem for others. Perhaps that could be optional, through an extra icon on the search bar?

As an alternative, could we have something in the plugin API to control the search indexer? Perhaps a hook to control how a file is read when it gets indexed, so the frontmatter could be removed or filtered to remove unwanted keys. Then I could write a plugin to get the behaviour I want.

Please let me know if this is already achievable with the Obsidian plugin API - I couldn’t see an obvious method, but I’m not very familiar with it.

1 Like