Dataview search for specific yaml value regardless of field its in?

What I’m trying to do

Search for a YAML value that could be in multiple fields without having to specify every field.

When I take a class or have a work project, I store people involved in YAML. The same person could be in multiple YASML fields - presenter, meeting attendee, etc - and would like to be able to list all of those notes in a people note I keep.

Things I have tried

All my queries right now are a long sequence of contains() checks which is fine but unwieldy.

In most cases it would be the easier option to actually specify the list of fields to check, but possibly make some loop related to which fields to check, I’m thinking something like the following:

```dataview
TABLE presenter, meeting_attendee
FLATTEN array(map( 
  list(
    "presenter", 
    "meeting_attendee"
  ), 
  (field) =>
    econtains(
      choice( row[field] = "string", list(row[field]), row[field]),
      "Bob"
    )
  )) as matches
WHERE any(matches)
```

This looks through all files trying to find “Bob” as either a presenter or a meeting_attendee. If found it returns the file, the presenter and all meeting attendees.

A variant over this query, where it only would list the role of “Bob” and in which files he matched could be written as:

```dataview
TABLE match[0] as Role
FLATTEN map( 
  list(
    "presenter", 
    "meeting_attendee"
  ), 
  (field) =>
    [ field,
      econtains(
        choice( row[field] = "string", list(row[field]), row[field]),
        "Bob"
      )
    ]
  ) as match
WHERE match[1]
```

With an additional query at the top showing all information from my test vault, these queries produces this output:

Hopefully, it’s something you can take further and make work in your setting. It might seems a bit excessive, but listing the various fields do still allow for a single variant of the actual test. And I’ve also built in a safe guard to make it work against both single and multiple values in the field.

Finally, if you truly would like to skip all field names, there is a possibility using dataviewjs to use something like Object.keys(file.frontmatter) to get all field names defined within the frontmatter. But this would also include tags and aliases, and what-not, and it would not include inline fields (defined in the body of the text).

Another variant of that last query could be:

```dataview
TABLE WITHOUT ID file.link as "Frank's meetings",  match[0] as Role
FLATTEN map( 
  list(
    "presenter", 
    "meeting_attendee"
  ), 
  (field) =>
    [ field,
      econtains(
        choice( row[field] = "string", list(row[field]), row[field]),
        "Frank"
      )
    ]
  ) as match
WHERE match[1]
```

Which displays as:
image

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