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.

46 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.

3 Likes

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”

2 Likes

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.

1 Like

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:
https://forum.obsidian.md/t/assign-tag-to-multiple-files/9750/8

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

2 Likes

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:

2 Likes

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

1 Like

I was just about to create another feature request Orpan Search Query and realized that this standing request could probably accommodate that use case if it was implemented. (Atomic requests are more manageable, so let me know if this seems like it should be it’s own feature request.)

Orpan Search Query

It would so be useful to see an ordered list of orphan files.

Proposed solution

Clearly Obsidian already has the capability to filter orphans, as demonstrated by the Graph View filter toggle.

I want some way to do the same thing in the search bar and inline queries.

Graph view is nice, but it’s so random and unwieldy in a large vault. We need a search query that provides a sorted list in the search bar and inline

` ` `query
is-orphan:
` ` `

Or in the style of the proposed solution above,

` ` `query
links:NULL
` ` `

Please note that to be an orphan file, it must not have any Obsidian links in the body nor any back-links. There are several posted regex queries on discord. None of them address the back-link side of the connection.

Current workaround

Progress clumsily using the Graph View filter.

Related feature requests

2 Likes

+1 for this.
A link search operator would also enable to search for all links with a special character (i.e mark transient notes not yet created with [[~ a special character to put in the writing inbox]]).

1 Like

I agree with the original proposal and just wanted to give a particular example.

Use Case:

If I’d want to find all Leetcode problems (tagged with: #leetcode/problem), which also have links to [[Stack]]. Similar things can be accomplished with the DataView plugin, but it’s not as dynamic as it would be by simply searching.

In General:

Making a search query which combines tags, links, and text content is something I often need to do.

Using Regex doesn’t seem like a natural way of accomplishing that.

5 Likes

+1 seems very valuable

As a search operator it would allow booleans (find all notes that are linked from one note, but not from another, or linked from multiple notes), filter in the graph view, and create very useful organization as an embedded search query.

What about “incoming:”, “outgoing:” as search operators?

incoming:Foo or outgoing:Bar or outgoing:"Note With Spaces In The Name"

And negative filter -incoming:Foo or -outgoing:Bar

7 Likes

+1.

I think “incoming” and “outgoing” are simple search operators here.

This would make it significantly easier to find files that have multiple links. Lets say I had two MOCs, one for a company I work for (i.e, Disney), and one for projects.

With this functionality, it’d be simple to do outgoing:Disney outgoing:projects to find all files that link to both. Now I have a list of all projects worked on at Disney.

6 Likes

+1

Combining several links and combining links and tags in the obsidian search would be invaluable. Otherwise tags remain a lot more useful for working with notes. Links, however, are great for Graphs and I don’t want to lose that functionality.

Am I right though that the Dataview plugin already includes a links search along with tags, etc.?

1 Like

yes, in dataview you can search/filter by links (inbound and outbound)

2 Likes