Filter Global Search (inspired by RegEx Non-capturing match)

Use case or problem

Frequent situation: I search for term1 but only in context of term2. For example I search for “Linking” but only within files that mention also “Obsidian”.
Search string produces thousands of irrelevant results which I have to carefully scroll to visually find the relevant one.

Example:
linking Obsidian -path:(MyPath)

file1
- ...Obsidian...
- .....Obsidian.
- Obsidian......
- ..Obsidian....
file2
...
fileN
- ...Obsidian...
- Obsidian......
- ..Obsidian....
- ...linking...
- ..Obsidian....
...

Proposed solution

Take inspiration from regular expressions (Non-capturing match).
Implement search operator that does not modify interpretation of search string
except that associated/enclosed search terms are not listed in search results.
The operator could be named e.g. “filter:” or preferably concise “+”, the opposite of “-”.

Example from above would change to:
linking +Obsidian -path:(MyPath)
or
linking filter:(Obsidian) -path:(MyPath)

fileN
- ...linking...
fileM
- ...linking in Obsidian...

This approach might result in matching files without any captured results. List of search results needs to be able to report files without particular results.
Example:
( backlink OR +(linking OR linked) ) +Obsidian -path:MyPath

file1
- ...backlink...
fileN    // FileN matches query but does not contain any search result. 
fileM
- ...backlinks in Obsidian...

additional thoughts

The wordy method with “filter:” is easier to intuitively understand by new reader than “+”. But harder to read and edit and time consuming during frequent searches by experienced user. Both “filter:” and syntactic sugar “+” could work in parallel if there is no agreement on preferred syntax.


keywords: exclude, filter, global, hide, restrict context, search

Current workaround

Related feature requests

Not precisely what you’re asking for: you could try section:(Obsidian linking), block:(Obsidian linking) or line:(Obsidian linking). But they will exclude instances where “linking” is too far from “Obsidian” in the text — at their farthest apart they’d have to be under the same heading.

As another workaround you might consider tagging the sorts of things you’re likely to filter by (#Obsidian). That would reduce your irrelevant previews to 1 per file.

The opposite of - (exclude) would be + (include), not + (filter). “Include” is the default, so we don’t use +; it’s implied. I’d go with filter: (or some other interface).

I’d consider renaming the post to “Filter search”.

Another person has asked abut this, and @I-d-as posted a workaround that I should have thought of:

EDIT: The workaround doesn’t fully work, but I posted a version that does:

As mentioned in that post I also found a way to do what you want in principle, but it freezes Obsidian. 🫤

It might be possible to search the context term, copy the results, and run some kind of macro to search the main term using each of the results in a path: selector.

Obviously a built-in syntax would be better, or a way to chain searches (like a pipe in shell scripting).