Search Operators for LINKS (backlinks, forwardlinks)

Use case or problem

It seems that we cannot search for links in Obsidian. In other words, we can’t search for all files that link to a particular file.

For instance we can’t create a graph view or do a regular search that shows what links to all files in a given path. If I’m a project manager and want a graph overview of files that link to the contents of my manufacturing folder, I can’t do that.

Proposed solution

Solution

Create a LINKS: search operator.

  • links:path:manufacturing would show all files that link or backlink to files in the manufacturing path
  • links:file:manufacturing* would show all files that link or backlink to file names that start with manufacturing
  • links:manufacturing would show all files that link or backlink to files that have the word manufacturing in the content
  • links:(path:manufacturing AND aluminum) would show all files that link or backlink to files in the manufacturing path and mention the material “aluminum”

It may be useful to differentiate links from backlinks. Possible operators for this might look like:

  • linkto:path:manufacturing
  • linkfrom:path:manufacturing

Additional search capability like this should provide benefit for Global Search as well as in Graph View.

Note that Obsidian natively does a basic version of this in the backlinks pane. But there, results are limited to only one source file at a time.


Note, I’m removing the 2nd proposed solution below this line from this Feature request to exercise better (more atomic) forum management. It has been written as its own feature here Add a Depth Slider to Filtered Graph View

Consider it edited out but I’m not deleting it because some related comments have already been made.

Slightly less powerful solution

Satisfies the need, but only within the graph view.

Add a depth slider to the Filter section of the standard Graph View. Note that it would only make sense to activate if there’s a search term that results in a subset of the vault.

Current workaround (optional)

It’s possible to do this on a single file basis by opening a Local Graph. Currently, Local Graph only work for one file at a time.

6 Likes

As another current workaround, you could use Neo4j Graph View 0.2.5 Advanced Graph View in Obsidian using Neo4j to upload data to neo4j, then do cypher queries on links, for instance

MATCH (n)--(m)
WHERE n.name CONTAINS 'manufacturing'
RETURN m

Neo4j looks impressive and also significantly daunting. I’m pretty sure I’d lose a week of my life trying to get that installed correctly :sweat_smile:

I suspect that Obsidian already tracks links efficiently on the back end. Hopefully adding a UI element to search links would be relatively simple for the developers.

2 Likes

Related feature requests:

@goodsignal See also similar request Add option to search for Backlinks . Perhaps you will get an idea how to unify them into single request.

1 Like

I’m starting to wrap my head around your proposal. But my first thought was “isn’t that just the back links pane?” Then you wrote:

Note that Obsidian natively does a basic version of this in the backlinks pane. But there, results are limited to only one source file at a time.

So I guess what I’m trying to figure out is what exactly is the use case you need that the back links pane can’t do?

Support for showing back links for multiple items. Like back links for every item in a folder?

What if a simpler solution is simply adding a back links pane for folders?

Right-click a folder -> “See back links”

1 Like

Would a Regex search that includes links to files within a folder (also with headings and block references) be enough? That also works in the graph view when you use it as your search. (Make sure to include orphans.)

(?:\[\[(?:\.\.\/)?(folder\/.+)(?:#|^|\|)[\^]?.*\]\])|(?:\[\[(?:\.\.\/)?(folder\/.+)\]\])

This supports one level of nesting (at least that’s what I’ve built it for.)
It includes the links from files in the root level or files in one folder to another folder.
Exchange folder with your folder name.

This only works if you use relative links.

Don’t forget that you need to put the Regex between slashes.

You can use this Regex to find all the links to a particular file in a particular folder:

(?:\[\[(?:\.\.\/)?(folder\/(file))(?:#|^|\|)[\^]?.*\]\])|(?:\[\[(?:\.\.\/)?(folder\/(file))\]\])

Here file is the file name.
Let me know if that helps.

Is there a Regex that would simply list all outgoing links from a particular file?

The use case I have depends on another feature request:

I’d like to be able to compose a search query that lists all outgoing links from a specific file, then assign a tag to all of those notes.

@dsteinbock Some relevant regular expressions are in:

If I remember correctly, some initial version of the following plugin already did list all links (also in UI) in a file so you might save some effort: GitHub - mrjackphil/obsidian-jump-to-link: Quick jump between links using hotkeys

1 Like

This will get you all the links. It will only match the file name.

(?<=\[\[).*?(?=(?:\]\]|#|\|))

Use case or problem

I would like to be able to search all backlinks for the selected file and combine it with a filter for example by tag or other parameters

Proposed solution

  • add backlink parameter to specify a search backlink

Current workaround (optional)

I don’t know how to achieve it

1 Like

Alternative would be filtering directly in backlink pane, requested as part of Filtering Everywhere!

But having the option available in search has use cases too.
Desired in:

  • Obsidian url scheme
  • Embedded searches, with ability to reference containing note without breaking the search when the file is renamed and all backlinks updated.
    For example by accessing variable “filename” of current file, e.g. as link:{{filename}} or link:(!filename).

AFAIK, Embedded search is the only place where it makes sense to speak about “backlink:”, otherwise it is going to be just “link:”. E.g. “link:(file name)” as a convenience to match all links to corresponding file:

[[file name|wiki link]]
[[file name.md|wiki link]]
[markdown link](file name)
[markdown link](file name.md)
[some text](encoded%20file%20name)
<auto link file name.md>

Edit: this does not yet specify query for all unlinked mentions for a file identified by filename, i.e. ordinary matches for filename, title and all aliases.

Related feature requests:

1 Like

But you can also have unlinked mentions and this way it will be complicated to search

1 Like