blacksmithgu / obsidian-dataview

A data index and query language over Markdown files, for https://obsidian.md/.
https://blacksmithgu.github.io/obsidian-dataview/
MIT License
7.04k stars 413 forks source link

containsword does not identify link text #2087

Closed edemko closed 9 months ago

edemko commented 1 year ago

What happened?

I am trying to find a list of notes that have a list property that is (well, contains) a given word, but that property is populated by links rather than plain text. (My goal is to auto-generate maps of content based on metadata, if you're curious.)

I found a workaround by enclosing the link in inline code markdown, but I'm honestly surprised that containsword does not simply search the markdown string, but instead appears to do something like understand markup and treat links differently.

DQL

Not working as expected:

LIST
WHERE any(map(function, (x) => containsword(x, "Loop")))

Workaround:

LIST
WHERE any(map(function, (x) => containsword("`"+x+"`", "Loop")))

JS

No response

Dataview Version

0.5.60

Obsidian Version

1.4.14

OS

Linux

edemko commented 11 months ago

Oof, no comment at all? I was hoping I was just missing something stupid and the issue would just close with an answer.

It's getting real annoying having to remember the magic incantation 😬

mitsuru793 commented 10 months ago

Hi, @edemko ! I have a near issues about link text. I found how to resolve from past issues. link is treated as object, not string. So I must convert the link to string and use contains.

This is a separate issue. Using contains() on a link is not doing what you probably think it is doing - links are essentially treated as full page objects, so contains(link, "value") is checking if value is present as a field on the page being linked to by link. Try contains(string(link), "value") instead. via: https://github.com/blacksmithgu/obsidian-dataview/issues/2036#issuecomment-1721895152

Related past issues

edemko commented 9 months ago

That's good to know!

In the meantime, I've recently gotten around the problem by learning my way around dataviewjs a bit better, and have actually a more accurate test for my needs anyway (for completeness: dv.pages().filter(p => p.function?.some(x => x.path === dv.current().file.path)).

Since the other issues are closed, and we've got some workarounds, I'll go ahead and close this one too. Thanks!

mitsuru793 commented 9 months ago

@edemko

It's good that you have solved your issue. I am also happy! You're welcome.

I like obsidian. Let's enjoy this application.