Search for a links with tag inside a file

What I’m trying to do

Search for links that has a specific tag (inside a single file - not the whole vault)

Things I have tried

Regular search cannot limit the search to a single file

Anyone with an idea as to how to search for a tag inside a file?

What do you mean you can’t search within one file? You’ve got two searches available, one for the file Cmd/Ctrl Fand one across files from the left side pane.

They handle the search differently, but they’re there. If you don’t like the current file search, you can also use the global search with adding a path: to the local file, if I’m not mistaken.

For me, hitting Ctrl + F with the file open, and then typing # already will select the first tag. A second letter will continue to move the selection to the first matching tag.

I think I over-simplified the ‘search’ function I am trying to do: I’m trying to find a list of links(files) that has a specific tag in a single file.

ie: Let’s say I have a page that has links to 100 books. I need a list of those books that are tagged “non-fiction”.

Assuming that the tags are in the page with the list, a global search: tag:#tag path:"books/list of books" will show you all lines with that tag when you expand the result (a single note).

Sadly no: Typically the tags are not on the page - they are an attribute of the links (files) that are on the page.

You observe that answering your question becomes difficult if you reveal your precise setup only sparingly as the thread proceeds.

1 Like

I’m sorry for misreading and taking this thread in a direction focusing on the search within a document, instead of catching the bit about the links having a certain quality, aka the linked note having that give tag.

Now, that I (hopefully) understand your requirements lets try two queries:

```dataview
TABLE WITHOUT ID out, out.tags, out.file.etags
WHERE file = this.file
FLATTEN file.outlinks as out
```

```dataview
LIST WITHOUT ID out
WHERE file = this.file
FLATTEN file.outlinks as out
WHERE contains(out.file.etags, "#non-fiction")
```

In my test setup I’ve created some books with various tags, and linked to all of those from my main document where I ran these queries. The output of the first query is as follows:

This displays all of then linked item from this file, aka file.outlinks, split into the separate links, out, and I display the link, the tags and the file.etags of this file. This query serves two purposes, it shows my test setup, and it also shows the base for further exploration related to filtering on the outlinks. If I’ve understood your use case correctly, you would like to only see the last two books which are tagged with #non-fiction. (How book can be both #fiction and #non-fiction is a debate for someone else… :slight_smile: )

The second query outputs that list of the two (three including that strange book book :smiley: ) books:

image

Hopefully the query is kind of self-explanatory, and addresses your issue correctly.

1 Like

Thanks for the comprehensive answer :blush:

So the secret ingredient I could not think of is the “contains” function :slight_smile: Very clever. I desperately tried to find a way to tell dataview “has the tag of #non-fiction” which proved not possible :))

And the flattening of the file.outlinks into out to allow you to treat each link as an individual link.

1 Like