Wildcard tags in searches - finding topics without certain tags?

I have the following situation:

I have a category containing many topics (900+), all of which have the same tag, say answered, which we use to track posts that have been responded to.

Many also contain other tags: deployment, cli, api, and so on, to denote the “theme” of the question.

How do I find all topics in my category that only have the answered tag, but none of the others?

I have tried the following syntax, for example tags:answered -tags:redirects while searching indeed gives me all things with the answered tag but NOT the ones with the redirects tag.

But to apply this to my situation I’d have to list out all the tags to NOT find individually - and I have many.

Is there a way to use wildcards in tag searches? something like: tags:answered -tags: *?

If not, is there another way it is possible to get a list of things that ONLY have the answered tag but none of the others?

thank you for your thoughts on this.

This is the only way I can see of excluding tags from a search.

It is possible to search for tag groups by using the category modifier with the tag group’s slug. For example, if you had a tag group called ‘topic status’, you can search for its tags with #topic-status, but tags can’t be excluded in this way, so -#topic-status doesn’t work.

1 Like

Thanks @simon - I think I’ll try adding all the tags I don’t want to search for to a tag group as suggested, and try that :muscle:

Sorry, I wasn’t as clear as I could have been. If it was possible to exclude a tag group from search, this approach would work, but I can’t see any way to exclude a tag group from search results.

1 Like

oh, i misunderstood. So its not possible - at all?

You could get a list of topics that only have a single given tag with a Data Explorer query. Something like this might work for you:

-- string :tag_name

with tagged_topics AS (
FROM topic_tags
JOIN tags
ON tags.id = topic_tags.tag_id
WHERE tags.name = :tag_name
counts AS (
COUNT(id) AS tag_count,
FROM topic_tags
JOIN tagged_topics
ON tagged_topics.topic_id = topic_tags.topic_id
GROUP BY tagged_topics.topic_id

FROM counts c
JOIN topics t
ON t.id = c.topic_id
WHERE t.deleted_at IS NULL
AND t.archetype = 'regular'
AND c.tag_count = 1
1 Like