Can we: Dataview table that list files that have tags in common with current file

Is there a way to make a dataview table that automatically lists other files that share tags with the current file?

What I’m trying to do

For a certain kind of file I have (song charts), I’m trying to add to each a dataview list with links to all the other songcharts that have at least one tag in common with the current one. Some of these tags change over time such as to describe the current state of a chart’s development, and there are a few hundred of these song charts. So not the end of the world to enter this manually for each one– But curious.

Things I have tried

I honestly have no idea where to start, on this one, and suspect the answer to my question is "no.”

Could you give an example of typical tags used in some of your files, and which should match or not?

And this should indeed be doable using dataview, I think.

1 Like

You can join this feature request.

For now, try this dataview query (supposed your songchart files are tagged with “#songchart”, otherwise simply adapt the FROM statement with a path to a folder or any other selector):

TABLE WITHOUT ID "" + link(file.link,title) AS "related songcharts"
FROM #songcharts
WHERE !contains(file.path, this.file.path) AND any(contains(file.tags, this.file.tags))
2 Likes

I don’t think doing contains on two arrays will work very well, @alltagsverstand ,if both have multiple values. At least, I’ve usually had to use map in combination with all and any.

What are you referring to? Anyway, I have tried this query and it is working as expected.

Can both file.tags and this.file.tags have multiple values, and still work? Can either also be a sub- or superset of the other?

If they can, there is something truly hairy going on behind the scenes of dataview, which might very well be the case…

this.file.tags is per definitionem a subset of file.tags - if you would like to query a specific tag (and not use the most obvious query via the ‘FROM’ statement), you would write WHERE contains(file.tags,"#example-tag") .

I’m sorry for the confusion I brought to the table, @alltagsverstand , my brain just shortcutted somewhere, failing to accept that contains() could work with arrays as both arguments. Not sure why, but in the recent past I’ve presented some answers where I needed to do map() on one of the arrays, to get it to work somehow. (Or I’ve been mistaken in doing so, as well).

Truly sorry for the misbelief, and the confusion I brought to the table. I was falsely under the belief that contains() would only return a single value related to whether it contained the last argument in the first argument, and not that it worked like a matrix returning an array of boolean values related to each element of the last argument being contained or not within the first argument.

A test case showing various combinations
```dataview
TABLE WITHOUT ID tmp[0], tmp[1], contains(tmp[0], tmp[1])
FLATTEN list(
 [ 0, 0 ],
 [ 0, [1] ],
 [ 0, [1, 2] ],
 [ 0, [1, 2, 3] ],
 [ [1], 0 ],
 [ [1], [1] ],
 [ [1], [1, 2] ],
 [ [1], [1, 2, 3] ],
 [ [1, 2], 0 ],
 [ [1, 2], [1] ],
 [ [1, 2], [1, 2] ],
 [ [1, 2], [1, 2, 3] ],
 [ [1, 2, 3], 0 ],
 [ [1, 2, 3], [1] ],
 [ [1, 2, 3], [1, 2] ],
 [ [1, 2, 3], [1, 2, 3] ]
) as tmp
 WHERE file.path = this.file.path
```
Result of this query

I could convolute the test queries even more by introducing letters and partial matches, but it does show the main point of splitting the last argument, and doing singular matching related to the first argument. Which I falsely believed it wouldn’t do. Sorry…

Thank you for this!
Out of curiosity, is there a way to query dataview to ignore results where the only tag in common is #songchart?
If not I could remove the #songchart from all files and pull from the folder path.

Anyone?

Use filter() to remove the #songchart tag before you do the other comparisons.

1 Like

Thank you!

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