Filter files based on outlinks matching to current file inlinks not acting like expected

What I’m trying to do

Im trying to only returns the files that have matching outlinks to the inlink of the file the query is in. Instead im getting all the files regardless of out-/inlinks that are in the specified path.

Things I have tried

Bottom query contains the following:

TABLE file.inlinks, file.outlinks
FROM "Tasks"
WHERE contains(file.oulinks, this.file.inlinks)

Im expecting to get only “Task with phase” from the query but instead I get every file inside of the Tasks folder.


Im trying to have a query inside of a project that shows tasks that belong to phases linked to that project.

This is because you are querying all inlinks and outlinks from all files of the specified folder.

This actually means: the current file’s inlinks - no need to duplicate anything.

If I understand you correctly, the following query is what you’re looking for:

FROM "Tasks" AND [[]]
1 Like

Hmm maybe I am not understanding this correctly, but in my eyes it doesn’t look like I’m duplicating anything.

Tasks don’t link to the Project, the file that the query is in.
Tasks links to phases and phases point to projects.

Task → Phase
Phase → Project

file.inlinks for Project will be Phases while Task file.outlinks will point to Phases.

Your solution does work but it means I’ll have to add the phases to the query everytime a phase is added to a project, which is something im trying to avoid.

A solution I’ve been avoiding is to link or tag every tasks directly to the project itself but that feels clumsy.

Please feel free to correct me or ask if something is not clear.

Let me think about the solution - as I am a bit in a hurry, I possibly only will find the time for that later on. If noone else comes with a solution in the meantime, be patient a bit…

1 Like

You are aware that your written file.oulinks in that query example?

Other than that, my experience with contains of lists in lists is a little varying. I tend to rather do a contains() in combination with either a map() or filter(), and then afterwards do any()/all()/none() depending on my criteria for success.

Ah thats a typo I made on the forum, I didn’t copy the code from the vault, sharp.

Could you give me a little more explanation on your solution, im not too familiar with those functions.

Here is a query (which hopefully works as intended):

TABLE file.inlinks, file.outlinks, this.file.inlinks, matches, any(matches), all(matches)
FROM "Tasks"
FLATTEN array( map( this.file.inlinks, (il) => contains(file.outlinks, il) )) as matches
WHERE file.outlinks

What should happen is that we check each of the inlinks of this file, to see if they’re contained in the outlinks of the other file. This check is mapped to an array, matches, which we then can check on later to see if it has any() or all() values as true. In the query I list all values, so you should be able to see the behavior pretty clearly (if I’ve not done any typos as I’m on mobile).

I’ve also added a WHERE file.outlinks limit, as if there is no outlinks, then they’re not going to match any inlinks either… :slight_smile:

1 Like

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