搜索中的通配符标签——查找没有特定标签的主题?

我有以下情况:

我有一个包含许多主题(900+)的分类,所有这些主题都带有相同的标签,例如 answered,我们用它来追踪已得到回复的帖子。

许多主题还包含其他标签:deploymentcliapi 等,用以表示问题的“主题”。

我该如何找到我的分类中仅带有 answered 标签而不带其他任何标签的所有主题?

我曾尝试过以下语法,例如 tags:answered -tags:redirects,搜索确实会返回所有带有 answered 标签但不包含 redirects 标签的内容。

但要应用于我的情况,我就必须逐一列出所有要查找的标签——而我的标签数量很多。

是否可以在标签搜索中使用通配符?例如:tags:answered -tags: *

如果不能,是否有其他方法可以获取仅带有 answered 标签而不带其他任何标签的列表?

感谢您的建议。

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 个赞

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.

2 个赞

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:

--[params]
-- string :tag_name

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

SELECT
c.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 个赞