New search operator "not" for tags only

Over at Stonehearth we’ve started to have the want to search for topics that don’t have a certain tag on them, or that aren’t by a certain user. To the best of my understanding, this isn’t currently possible. As such, we’d like to request a negation operator for search, like Google support -.


So this just came up naturally from another user at Stonehearth:

Seems he was trying to search for “frog”, but we have a very active user named “froggy” so he had a hard time searching for posts that had frog but weren’t mentions.


I’m amazed this topic didn’t get any more traction…

As the Keyboard Maestro forum gains more and more threads it’s becoming increasingly difficult to find things efficiently.

A negation operator would be helpful.


You can use negation in Google searches with the site: operator, so try that. Visit the 404 page (type any random gobbledygook as a URL past the domain name) to get a pre filled google search form.

It is actually a pretty straight forward change (add support for -test) which would be only about 10-20 lines of code including tests (as long as its not in the advanced page with a fancy UI). Going to put a #pr-welcome on this, I don’t think it would do any harm.


It is super easy to search using Google with negation right now, just visit any 404 page and type the terms

Using google wont work for login-only forums, or secure categories


That does not apply to the forum in question at

So they can easily kick off a search with negation by going to

1 Like

Hi, I am quite new to the project, but I can try to add this feature.


That’s great @kasiabulat. Do you have a good idea of where to start with this or do you need some guidance?

Thank you @erlend_sh for offering help! I think that the best and easiest way to do it would be to perform two searches:

  • Firstly, search for the term before the not part
  • Then, in results, search for the ones containing the unwanted phrase and filter them out

Is discourse/search-menu.js.es6 at 87c334c06365f273f39038d91ab92488c4757041 · discourse/discourse · GitHub the correct file to make changes in?

1 Like

The larger part of your changes will be in


Thank you @cpradio for help with finding the correct file.

For the beginning, I added a simple version of search operator “not” (~) for tags. Currently it has the highest precedence and I implemented it as I described above. But I am wondering if it would be better for ‘+’ or ‘,’ to have higher precedence? And should it be possible to combine all operators? What way would be the best for users to construct their queries?

Pull request:


I added some tests and comments about the performance issue to my pull request.


I’m not sure about using ~ to represent NOT since it is usually used when matching against regular expressions. In Ruby, we use =~ /^some_regexp_pattern/ and it is similar in Postgres as well.


I agree that using ~ as operator probably isn’t a good idea.
@kasiabulat Why did you choose ~ instead of - as “not” operator?

I’d prefer tags:eggs-lunch+sandwiches or tags:eggs!lunch+sandwiches to tags:eggs~lunch+sandwiches

1 Like

Ah ha this was probably not chosen because - are allowed in tags.

Using quotes would help: tags:"boiled-eggs"-lunch+sandwiches

Probably not the best idea to require quotes as a naive search on tags:boiled-eggs would no longer do what you’d expect. Is there any conflict with !? That would be my preference here.


Should I change it into “!”, then?