# 用标题中的关键字搜索已删除的主题

**URL:** <https://meta.discourse.org/t/searching-for-deleted-topics-with-a-keyword-in-title/173271>\
**Category:** Support\
**Created:** [2020年十二月14日 18:24 UTC](https://meta.discourse.org/t/searching-for-deleted-topics-with-a-keyword-in-title/173271 "2020-12-14T18:24:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Loki](https://avatars.discourse-cdn.com/v4/letter/l/3be4f8/32.png) [@Loki](https://meta.discourse.org/u/Loki)\
**Post date:** [2020年十二月14日 18:24 UTC](https://meta.discourse.org/t/searching-for-deleted-topics-with-a-keyword-in-title/173271/1 "2020-12-14T18:24:57Z")

</div>

如何搜索标题中包含特定关键词的已删除帖子？

在基础搜索 URL 中添加 ?status=deleted 似乎不起作用。

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2020年十二月14日 19:39 UTC](https://meta.discourse.org/t/searching-for-deleted-topics-with-a-keyword-in-title/173271/2 "2020-12-14T19:39:00Z")

</div>

> [@Loki](#):
>
> 如何搜索标题中包含特定关键词的已删除帖子？

我认为无法通过 Discourse 搜索页面实现这一功能。不过，我理解添加一个用于搜索已删除帖子的过滤器对站点管理员来说可能会很有用。

可以使用 [Data Explorer](https://meta.discourse.org/t/32566?silent=true) 查询来返回已删除的主题和帖子。类似于下面的查询可能会有所帮助：

```sql
--[params]
-- string :term

SELECT
id AS topic_id
FROM topics
WHERE deleted_at IS NOT NULL
AND title LIKE CONCAT('%', :term, '%')

```

对于使用我们托管服务的站点，您还可以联系我们的支持团队，我们将为您找到相关主题。

---

<div class="post-metadata">

**Author:** ![altoom\_yamen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/altoom_yamen/32/203198_2.png) [@altoom\_yamen](https://meta.discourse.org/u/altoom_yamen)\
**Post date:** [2020年十二月14日 20:12 UTC](https://meta.discourse.org/t/searching-for-deleted-topics-with-a-keyword-in-title/173271/3 "2020-12-14T20:12:46Z")

</div>

🙂

---

<div class="post-metadata">

**Author:** ![Loki](https://avatars.discourse-cdn.com/v4/letter/l/3be4f8/32.png) [@Loki](https://meta.discourse.org/u/Loki)\
**Post date:** [2020年十二月14日 21:42 UTC](https://meta.discourse.org/t/searching-for-deleted-topics-with-a-keyword-in-title/173271/4 "2020-12-14T21:42:43Z")

</div>

感谢您的回复。我们的版主不太熟悉数据浏览器。目前，我们可以通过搜索所有已删除的帖子（/latest?status=deleted）并结合页面搜索关键词来查找。如果是近期删除的内容，我们就能通过这种方式找到。否则，我们可以向大家寻求帮助。

我们能否将此视为一个（低优先级）请求，即未来为工作人员在搜索面板中添加“已删除”筛选功能？

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2020年十二月14日 21:58 UTC](https://meta.discourse.org/t/searching-for-deleted-topics-with-a-keyword-in-title/173271/5 "2020-12-14T21:58:15Z")

</div>

> [@Loki](#):
>
> 我们的版主不熟悉数据探索器（[Data Explorer](https://meta.discourse.org/t/32566?silent=true)）。

为了让版主能够使用查询，您需要先添加该查询，然后授予您网站版主的访问权限。如果您未来希望尝试此功能，我们可以通过私人支持协助您完成设置。

> [@Loki](#):
>
> 我们能否将此视为一个（低优先级）请求，以便将来在工作人员的搜索面板中添加“已删除”筛选器？

当然可以。这可能有一些技术原因导致该功能尚未实现，但我曾多次需要搜索已删除的主题和帖子。

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [2020年十二月17日 07:58 UTC](https://meta.discourse.org/t/searching-for-deleted-topics-with-a-keyword-in-title/173271/6 "2020-12-17T07:58:36Z")

</div>

@sam 反对这一做法，因为它可能会导致全文索引膨胀，我也倾向于同意这一观点，认为该功能实用性不高。

---

<div class="post-metadata">

**Author:** ![Paracelsus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paracelsus/32/164912_2.png) [@Paracelsus](https://meta.discourse.org/u/Paracelsus)\
**Post date:** [2022年二月21日 10:30 UTC](https://meta.discourse.org/t/searching-for-deleted-topics-with-a-keyword-in-title/173271/7 "2022-02-21T10:30:38Z")

</div>

您好，这在一般情况下运行得非常好，但在以下情况下却不行：  
我们碰巧隐藏了某个主题的第一篇帖子，因为它被标记了，这意味着整个主题都被隐藏了。这没什么奇怪的，但这个主题无法通过查询找到，尽管它存在于 `/latest?status=deleted` 列表中。有没有办法也能通过查询找到这些主题？（比如，它们被删除了，但不是 _真正_ 删除了 😁 ）

---

<div class="post-metadata">

**Author:** ![IAmGav](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/iamgav/32/235598_2.png) [@IAmGav](https://meta.discourse.org/u/IAmGav)\
**Post date:** [2022年二月21日 10:39 UTC](https://meta.discourse.org/t/searching-for-deleted-topics-with-a-keyword-in-title/173271/8 "2022-02-21T10:39:19Z")

</div>

请查看此查询并根据需要进行修改。

> [@Delete deleted-posts permanently in bulk?](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/57):
>
> Excellent, glad to hear that did the job for you. So for the sake of combining the answers, one can use the following in the Rails console to destroy all topics that were deleted more than 90 days ago, repeating as many times as necessary if there are more than 1000 topics: Topic.with\_deleted.where(deleted\_at: ...90.days.ago).limit(1000).destroy\_all After that has completed, the following can be used to destroy all posts that have been orphaned from destroyed topics: Post.find\_by\_sql("select …
