Make List of Similar Notes (with Dataview?)

What I’m trying to do

I am trying to discover notes that share a high amount of in-links and out-links with the current one (a “similar notes” query of sorts). I suspect Dataview is the plugin to do this, but I’m not sure about how to proceed. Any suggestions will be very much appreciated. Thanks in advance for your help!

Things I have tried

The Graph View already offers a similar functionality to what I am asking for. Maybe there is some simple way of showing “nearest notes in graph” in the note itself that I’m missing? I don’t really like to open the Graph View when I am writing…

Here are some queries which might help you on your way.

The first query (based upon a misreading of your request) list all notes where there are common links between inlinks and outlinks of a note:

```dataview
TABLE file.inlinks, file.outlinks, common
FLATTEN array(filter(file.outlinks, (ol) => econtains(file.inlinks, ol))) as common
WHERE length(file.inlinks) > 1 AND length(file.outlinks) > 1
WHERE length(common) > 1
SORT length(common) desc
```

After re-reading your request you’re asking for the most similarities between file.inlinks and this.file.inlinks and between file.outlinks and this.file.outlinks. Try this query in one of your files, and see if it doesn’t report back the correct information.

```dataview
TABLE 
  file.inlinks, this.file.inlinks, commonIn,
  commonOut, file.outlinks, this.file.outlinks
FLATTEN array(filter(file.inlinks, (l) => econtains(this.file.inlinks, l))) as commonIn
FLATTEN array(filter(file.outlinks, (l) => econtains(this.file.outlinks, l))) as commonOut
WHERE file != this.file
WHERE length(file.inlinks) > 1 OR length(file.outlinks) > 1
WHERE length(commonIn) OR length(commonOut)
SORT max(length(commonIn), length(commonOut)) desc
```

You could of course remove columns you don’t like at the start of query, so if you only wanted the actual link in common, you could use:

TABLE commonIn, commonOut
....

When inserted in a file this should show if this file has any in- or outgoing links in common with any other files. Files not having either type of links in common with the current file, are not shown at all.

2 Likes

@holroy your second query is really cool - lets you discover a different kind of connections between notes. Just one question: as in the result column (for example “file.outlinks”) it is sometimes quite difficult to see where one link ends and the next link begins - how can I show the results as a bulleted list? I tried map(rows, (r) => "* " + r.file.outlinks) but that doesn’t work…

@alltagsverstand , are you using Minimal theme? That theme, and some others I think, has made a point out of hiding the bullet points within tables. So I times need to change theme just to make sure the bullet points of these kind of lists actually show up. I tend to switch between Minimal and Prism just to re-display the bullet points (while I’m trying to figure out what I need to re-enable in a CSS snippet to get the bullet points when I’m using the Minimal theme).

@holroy good point - I will have a look at this tomorrow (though, in other dataview tables, my above solution works…)

This is great, thank you so much. It is definitely doing something because it gave me a list of over 300 links in a random note. Now I am going to have to limit the number of results for the query to see if the links are relevant (currently the query only freezes Obsidian). I’ll report back when I’ve found a way of limiting results and avoiding the overload. Thanks again!

1 Like

Ok, so I limited the results with the simple “LIMIT + a number” and it works, Obsidian no longer freezes. Also, the solution given by @holroy is definitely doing what I was looking for. Thank you so much :slight_smile: !!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.