How to do a negated search, excluding specific terms?

[I am not allowed to put more than two links into the body even though they are local, sorry… I used the search terms below on Search results for '' - Discourse Meta without quotes.]

There supposedly is a operator to negate search terms, according to New search operator "not" but the thread is very unclear what symbol was chosen in the end and there are no final examples. It is the first and pretty much only thing I could find online about it.

The thread talks about “-”, “!” and “~” so I tried them all:

  • “negative search” gives me 43 results with “negative” and/or “search” in them, the terms are highlighted
  • “-negative search” gives me 43 results with “negative” and/or “search” in them, “search” is highlighted
  • “-negative -search” gives me 43 results with “negative” and/or “search” in them, neither is highlighted

So whatever the highlighting means, the “-” symbol is not the operator.
I repeated the same tests with “!” instead, same results.
With “~” I get the same as before for “negative ~search” but zero results for “negative search”.

So how can I exclude specific terms in a search?

4 Likes

Agreed that topic is quite confusing. Can we clarify here Monday @jomaxro?

1 Like

That topic definitely went through numerous changes. Sorry it is so confusing.

At this time, the negation operator is -, and it only applies to tags. So you can search for topics that do not have a certain tag, but cannot search for topics without a word, or category, etc.

The negation operator is used like so:

green tags:eggs -tags:ham - search for posts containing the word “green”, tagged with eggs, but not tagged with ham.

The following is not a valid search:

-green tags:eggs. While the intent may be to search for posts without the word green tagged with eggs, it will instead search for posts with the word “green” and tagged with eggs.

9 Likes

Oh, that explains my struggles. Thanks for updating the topic of that thread, this will help other’s who look for this functionality.

Would be OK and in any way useful if I added a feature request in feature - Discourse Meta?

5 Likes

Please do! At the time I created the feature request 3 years ago, tag negation was all I needed, so that’s all I requested.

2 Likes