Provide API access to the results of Bases view

Bases is a fantastic first‑party way for users to define cohorts of notes. Allowing plugins to get a list of notes from a Base without the plugin being implemented as a Base view would significantly expand what plugins can do with Bases.

Many plugins implement their own query language, search system, or filtering to compile lists of notes, which requires users to re-write their custom filters across plugins. If users could point such plugins to a Base#view, they could reuse a native feature of Obsidian instead.

Proposed Solution

I’d love to see a supported, headless way for plugins to evaluate a given Base and view to get its matching notes.

Not prescriptive about naming, but something like:

await app.bases.getViewFiles(baseFile: TFile, viewName: string): Promise<TFile[]>;

Use Case

How popular plugins could use this

Note that I don’t use all these plugins myself, I just browsed through a few most-downloaded and considered how they could use this API - these are just ideas based on my first impressions and not necessarily something the developers of these plugins would/should implement:

  • Dataview could support Bases as another FROM source, e.g. LIST FROM "Books.base#To Read"
  • Tasks could filter by tasks in a given Base
  • Smart Connections could add additional filters (include and exclude rules)
  • Spaced Repetition could create decks from a Base view (currently done by folders or tags).
  • Projects could build projects from Bases (currently done by folders and Dataview queries).

How not-so-popular plugins could use this

My own plugin, Pairwise Elo Ranking, defines cohorts of notes you can compare against each other to easily rank them. One of the methods of creating cohorts of notes for comparison is to use a Base.

Current workaround

To accomplish this, I’m currently opening the Base in a new leaf and reading controller.results after it settles - which is more complex and fragile than it needs to be.

If there is already a better way to do this, please let me know!

3 Likes

This would be so helpful!

Yes please!

Plugins could also benefit from getting that list to provide a friendly and more integrated UX/UI that users are used to!

Real example use case: My grand mother wants to reset the ranking of all series she watched last year and rerank them one by one. She already know how to query that using base, but being able to provide her with a two lines of JS snippet in a Note toolbar button would be awesome!

That’s one use case from this week, but the other that I know I will be asked for sure is about running an API query for a selection of series. Giving a way to use a filtered view (Base) as input for a script loop would be so cool.