silverbulletmd / silverbullet

The hackable notebook
https://silverbullet.md
MIT License
2.01k stars 138 forks source link

BUG/QUESTION - Querying pages using the contained built-in function #889

Open STSMHQ opened 2 weeks ago

STSMHQ commented 2 weeks ago

Hi, everyone,

I'm currently experimenting with the query language of SilverBullet (what an incredible feature) and I faced an issue that I honestly don't know if it's a bug or if I'm only being a noob here. For instance, I have this note:

image

And then in another note, I've this:

image

But, the following error is presented when I try to render the above query:

image

Is this normal behavior? And if yes, how can I query tags for specific keywords?

zefhemel commented 2 weeks ago

What I think the issue is that likely not all your pages have a hum attribute, so for many hum will be undefined and undefined is not a string :) The question is how to best fix this. One way I can easily implement is have contains simply return false whenever the first argument is undefined. I think this would not be such a bad solution. What will probably fix this for you is adding a hum check before, so where hum and contains(hum, "hotfix"). Not tested, but that should work.

STSMHQ commented 2 weeks ago

First of all, thank you for the quick reply and you're totally correct, @zefhemel. When I try the same query with the name field/directive it works (as the name field is present on all notes). Also, I tested your workaround - where hum and contains(hum, "hotfix") - it also worked perfectly. Of course it would be better to have the first approach that you described - the false return - implemented, but this workaround will serve my purpose, at least for now. Thank you for suggesting it and have a nice day!

P.S: Feel free to close this issue if you want.