Wild card symbol for the subtopic of a tag

What I’m trying to do

I see this post but do not understand how I would use it.
TABLE map(file.etags, (t) => split(t, “/”) [length(split(t, “/”))

Where would the main topic of my tag be indicated? Or is it another idea?

I want to find a symbol to indicate the subtopic of a tag as any word. For example I have a tag called main_topic. The Main topic is divided into several subtopics. I want to find all the subtopics in a dataview query. What symbol could I use as my wild card?

Things I have tried

I tried astrik. But that does not work. It has other uses.

Tags

Please show some examples of how you’ve set your main_topic, and an sample search of what you want to search for.

Thank you for your suggestion. I am very unfamiliar with dataview and the following example is only copy-paste from the work of someone who understands dataview better than I do. I want to set up dataview for my typical searchs.

TABLE WITHOUT ID
  file.link as "Project",
  up,
  created-date,
  summary,
  tags
FROM !"Templates"
WHERE icontains(tags, "type/project")
AND !icontains(tags, "status/complete")
SORT filename DESC

I want all tags where the main tag is "type" or "status"   In this case, the subtag is project and complete, but there are others.

Let’s try to expand on this expression which is kind of hefty. First of all the “simple” explanation is that it’ll only return back the last element of any nested tag. But how did it get there?

  • map( file.etags, (t) => ... ) - Essentially this creates a loop, where it loops over each of the tags found in file.etags, and presents a single tag at the time to the looping (the ... part) as t
  • split(t, "/") - This divides the t into a list, using / as the divider
  • ...[ ... ] – Using the square brackets on a list, the first ..., select the index on the number given by the second expression
  • length( split(t, "/") ) – This resplits the t as already done to get the list a second time, and then it uses length to count the elements of this list

Therefore this expression loops over the entire file.etags, and for each element t, it splits that into a list of its separate parts, and select the last (or one after the last(?) ) in that list.

This is not entirely what you want! :slight_smile:


Conceptually you want to scan the list of tags and see if the main tag (or the start of the tag) is either type or status. Another way to phrase that, is if you filter the list of tags, file.etags, does any of those match type or status. This can be written as follows:

WHERE   any(filter( file.etags, 
  (t) => startswith(t, "#type/") OR startswith(t, "#status/")  ))

Here is a sample query listing file.etags, the filtered list, and whether the clause would have matched or not. Play around with the LIMIT 30 (possibly reducing it at start), and also maybe limit to some given folders where you know you’ve got these kind of files.

```dataview
TABLE
  file.etags,
  filter( file.etags,
     (t) => startswith(t, "#type/") OR startswith(t, "#status/" )) as "Filtered list",
  any(filter( file.etags,
     (t) => startswith(t, "#type/") OR startswith(t, "#status/" ))) as "Any found?"
WHERE contains(file.etags, "/")
LIMIT 30
```

This is so nice. Thank you.

I must not be filling in the blanks correctly, so to speak. What I typed does not work. I am expecting a table to appear. But I do not see one when I click on the glasses icon in the upper right corner.

dataview TABLE file.etags, filter( file.etags, (t) => startswith(t, "#sx/") OR startswith(t, "#rx/" )) as "Filtered list", any(filter( file.etags, (t) => startswith(t, "#sx/") OR startswith(t, "#rx/" ))) as "Any found?" WHERE contains(file.etags, "rx/") LIMIT 30

I have many tags #rx/ and #sx/

The meaning of this last part is not clear to me.
WHERE contains(file.etags, “rx/”) LIMIT 30 ```
Should I be adding rx? Or something else.

Did you keep it on one line? At least the start with ```dataview and the end, ```, needs to be on separate lines, and you do need to have the dataview plugin installed and enabled.

This query is somewhat expensive to execute as it scans through all tags of all files (unless you limit it to some folder or similar), so using WHERE contains(file.etags, "/") would limit the query to only look further into files which actually has nested tags.

The second part LIMIT 30 just gives the first 30 entries matching our query. This was used in my test vault to verify the correctness of the query, and when you start getting the wanted result, you could most likely remove this part all together. It’s mostly useful when debugging and ironing out all the details of the query.

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