Is there any easy way to exclude the current file from an inline query

What I’m trying to do

I have a project template setup with a basic query search to pull in any notes containing the keywords from that project, but it always returns the note I am on because typically the note title is the same as the query keywords. Is there any easy way to exclude the current note?

If you’re talking about a search query try something like: -file: "your filename"

If you’re talking about a dataview query you add a line near the bottom with WHERE file != this.file

Thanks for the quick reply. I’m talking about the inline query…

``` query
"Search Term"
``

When I add -file: “your filename” it also removes any filename with that word in too, so if the note was called “test” and other notes existed such as “test-2” and “test-3” then those would be removed which is not what I need. I just need the current note to be excluded if that makes sense?

In fact - just adding .md to your suggestion seems to have sorted it!

1 Like

Is there any way to define the title using a variable? just thinking if the document gets renamed the query might be wrong then

You could most likely also use -file: /^test-1$/, but if it works with adding .md, then do that. The regex here could easily get some special characters disturbing the regex.

Appreciate the help!

I don’t think so in a query like that. In dataview you can use [[]] but I don’t think that’s possible in these queries.

If you’re worried about that, you could consider adding a “random” tag to the current file, and do the search with excluding that tag. Do however make sure that tag is unique across your vault, so as not to exclude other than the current file.

One way of doing this could be to have tags like unique/something, and if you view them in the tags side pane, there should only be one of each nested tag.

In search, no, but in templates you can use {{$title}}. So you could make a template that just outputs the current note name, or one that includes the search stuff too, and use it to remake the search when you find it returns wrong results.

1 Like

Perfect - this sorted it!

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