# 是否启用仅限登录用户搜索的选项？

**URL:** https://meta.discourse.org/t/option-to-enable-search-for-logged-in-users-only/256772
**Category:** Feature
**Tags:** search
**Created:** [2023年三月2日 05:24 UTC](https://meta.discourse.org/t/option-to-enable-search-for-logged-in-users-only/256772 "2023-03-02T05:24:14Z")
**Posts on this page:** 1
**Showing post:** 12

<div class="post-metadata">

### Author: ![nat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nat/32/235063_2.png) [@nat](https://meta.discourse.org/u/nat)
#### Post date: [2026年九月4日 11:08 UTC](https://meta.discourse.org/t/option-to-enable-search-for-logged-in-users-only/256772/12 "2026-09-04T11:08:23Z")

</div>

这种情况确实令人遗憾。虽然我坚信搜索功能应该向所有人开放，但我也能理解这个机器人给大家带来的困扰。我认为，如果已知用户来自某些特定地区，那么上面提到的地理位置封锁建议作为第一道防线也非常实用。

起初我考虑过使用 `search_allowed_groups`，但我认为 `allow_anonymous_search`（默认值为 true）可能更好。如果基于群组来实现此功能，会使某些依赖 `search` 的内部功能变得过于复杂。

> <https://github.com/discourse/discourse/pull/43281>
>
> Related: https://meta.discourse.org/t/option-to-enable-search-for-logged-in-user…s-only/256772/4
> 
> Adds a new "Allow anonymous search" site setting that defaults true, keeping current application behaviour.
> 
> When set to false, anons going to \`/search\` will be sent to the login page.

基于上述方案，当 `allow_anonymous_search` 被禁用时，匿名用户将无法使用任何搜索功能（包括 API 和 UI）。站点设置的描述也会相应注明这一点。

有一点让我有些犹豫：虽然这个 PR 和站点设置的原因是为了应对恶意行为（griefing），但我想知道，当 `allow_anonymous_search` 被禁用时，是否仍然应该显示搜索框（即使它不起作用），并鼓励用户注册或登录。不过，我认为这不应该阻碍该 PR 的合并。

* * *

此外，我更倾向于不将其他功能混入这个目前仅针对 `/search` 的具体请求中。

---

_[View the full topic](https://meta.discourse.org/t/option-to-enable-search-for-logged-in-users-only/256772)._
