Searching using Obsidian Query Language

Using the Obsidian Query Language plugin, and the API of that you could do the following dataviewjs query, and get a link to all the files mention your search query.

```dataviewjs 
if ( 'obsidian-query-language' in this.app.plugins.plugins ) {
  const oql = this.app.plugins.plugins['obsidian-query-language']
  
  // Setup and execute search
  const query = "'M01L01"
  const searchResults = await oql.search(query, { template: "list" } )
  
  // Filter away files _starting_ with the query
  const filteredList = searchResults
    .filter(t => !t.path.split("/").pop().startsWith(query.substring(1)))
    .map(t => t.path)
  
  dv.list(filteredList)
}
```

I’ve set this up to remove files starting with the query, so that a file name “M01L01”, wouldn’t show up in the list. If you want those included, then remove the .filter line.

Similar code should also be possible to do with an execution command of Templater, but this depends whether you want dynamic searching which would refresh itself every time you visit this file, or a static search the first time. If you want dynamic searches, then you could just add this query as is to your template, and change the query to something like const query = "'" + lessonNumber (or whatever you stored your key term in).

1 Like