Recursively filtering bases

Hi all,
I have a couple of use cases for recursively filtering bases.

First, I’d like to list all notes that link directly to a given note. Here I’d like to also show notes that link to the notes that link to the parent note (this should be done recursively). I’ve been able to do this in dataviewjs, but I’d like to make use of base’s better performance and in-place YAML editing. Can this be done in bases?

Second, assuming this can be done, I’d like to take that recursively generated list of notes and filter another set of notes with that list. I.e., a note is only displayed in that base, if a specific property contains a link to at least one of the above generated list of notes.

The Obsidian bases documentation mentions recursive filtering but I can’t seem to find an example.

I hope this is understandable.
In any case, I’d appreciate any input.

Best,
M

Which of these do you want the rows to be?

  1. Each row is a note that has a first- or second-degree link to one specified note, such as the current note.
  2. The rows contain various notes, with columns that show their first- and second-degree backlinks.

For the first one, and presuming you’re talking about the currently active note, use these two filters:

filters:
  or:
    - file.hasLink(this)
    - file.links.filter(value.asFile().hasLink(this))


For the second one, click Properties and select file backlinks, and then click Add formula and add this formula:

file.backlinks.map(value.asFile().backlinks)

thanks for the input.

I meant the first option. Is it possible to do higher degree connections, too?

Yes. Continue the pattern to extend to an arbitrary number of degrees.

If you plan to go far, you could change tactics to use the repeat() and reduce() functions. But note that hasLink() seems to not refresh swiftly (this is not documented; it’s just from observation), so you’ll probably end up having to manually close and reopen notes/bases to force refreshes.

Almost forgot, I meant to address the other part once you said which version you wanted:

Add these two filters to your OR group:

note["your property"].filter(file(value).hasLink(this))

note["your property"].filter(file(value).links.filter(file(value).hasLink(this)))

Replace your property with your property key.

This too can be expanded to an arbitrary degree of your choosing.

@dawni thanks a lot and sorry for the late response

I can’t quite seem to figure it out yet.

Could you give me an example how to filter to include also second degree backlink neighbors to a given note?
I tried file.links.filter(value.asFile().hasLink(file.links.filter(value.asFile().hasLink(this)))) but that passes a list when hasLink expects a single link. Playing around with .some didn’t get me much further either, unfortunately.

Filter for notes that have a…

Link to the current file:

file.hasLink(this)

Link to a link to the current file:

file.links.filter(value.asFile().hasLink(this))

Third-degree link to the current file:

file.links.filter(value.asFile().links.filter(value.asFile().hasLink(this)))

Fourth-degree link to the current file:

file.links.filter(value.asFile().links.filter(value.asFile().links.filter(value.asFile().hasLink(this))))

Awesome thanks, it works perfectly!