this post was submitted on 17 Jun 2023
10 points (100.0% liked)

ObsidianMD

4100 readers
1 users here now

Unofficial Lemmy community for https://obsidian.md

founded 1 year ago
MODERATORS
 

I have a number of individual notes for various books I've read, with a YAML field for "author." This works great with Dataview, except when there are multiple authors of a book. I assumed I could just add another YAML line "author: Sample Author" to add the second author, but then Dataview does not return results for either author.

Does anyone know how to change my query so it will return results for either author? Is this possible?

My current search is:

dataview TABLE without ID link(file.link, title) as "Title", author FROM #books Where author = "Sample Author"

you are viewing a single comment's thread
view the rest of the comments
[–] surrendertogravity@wayfarershaven.eu 6 points 1 year ago (3 children)

Just mentioning to cover all the bases: you'll want to make sure you're using the correct multi-value YAML syntax in your front-matter when you include multiple authors (eg. single line or multi line array). I like using the Linter plugin to help me out with this.

# single-line array
author: [Sam Jones, Mary Apple]

# multi-line array
author:
- Sam Jones
- Mary Apple

Once you have something like the above, using flatten should enable returning results for either author; with one test file in my vault, this worked for me:

TABLE WITHOUT ID
link(file.link, title) as "Title", author FROM #books FLATTEN author WHERE author = "Sam Jones"
[–] Windexhammer@lemmy.world 5 points 1 year ago (1 children)

I used this for my recipe notes:

ingredients:
- name     : Carrots
  quantity : 2
  units    : ""
  format   : grated
- name     : Curry Powder
  quantity : 1
  units    : tbsp
- name     : Onion
  quantity : 1
  format   : sliced

And then use FLATTEN ingredients to create a nicely formatted table of ingredients.

Ooo, nice tip! I’ve got a few recipes in my vault I’ll have to try this out on.

That did it! Thank you so much!

[–] tenebrisnox@feddit.uk 2 points 1 year ago (1 children)

Do the variables in the single-line array need square brackets?

[–] surrendertogravity@wayfarershaven.eu 3 points 1 year ago (2 children)

my understanding is that’s a required part of the YAML syntax, yes

[–] tenebrisnox@feddit.uk 3 points 1 year ago (1 children)

Sorry. I just looked through the Dataview documentation and found that my inline data needed double-quote marks rather than brackets. Like this:

Writer:: "John Byrne", "Mike Mignola"

It works now and solves an issue I was having. Thank you.

ah yeah, I haven't used Dataview's inline data before. Glad you figured it out! :)

[–] tenebrisnox@feddit.uk 1 points 1 year ago

Thanks.

I tried it out and if it's placed in the front-matter at the top of the note like this it works:

Writer: [John Byrne, Mike Mignola]

Unfortunately, most of my data is in the body of the notes using double-colon syntax like this - and it doesn't get picked up by the Dataview query:

Writer:: [John Byrne, Mike Mignola]

Am I missing something?