# 搜索用户自定义字段遇到问题

**URL:** https://meta.discourse.org/t/trouble-searching-user-custom-fields/404800
**Category:** Bug
**Created:** [2026年六月8日 22:34 UTC](https://meta.discourse.org/t/trouble-searching-user-custom-fields/404800 "2026-06-08T22:34:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2026年六月8日 22:34 UTC](https://meta.discourse.org/t/trouble-searching-user-custom-fields/404800/1 "2026-06-08T22:34:36Z")

</div>

我有几个用户自定义字段，客户希望能够通过它们搜索用户。

如果我输入 `/` 或使用页面顶部的搜索框，它会搜索自定义字段并找到预期的用户；但在 `/u` 处搜索时，却只搜索用户名。

该搜索调用的是类似以下内容：

```
https://hostname/directory_items?period=all&order=likes_received&name=cutr&cards=yes&user_field_ids=6%7C7%7C8%7C1%7C3&plugin_column_ids=15%7C11

```

我相当确定这之前是有效的，现在这是一个回归问题。

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2026年六月9日 20:46 UTC](https://meta.discourse.org/t/trouble-searching-user-custom-fields/404800/3 "2026-06-09T20:46:38Z")

</div>

> [@pfaffman](#):
>
> 我相当确定这以前是有效的，现在是一个回归问题。

我没能找到它曾经有效的时间点，但我能够修复（或者更确切地说，使两者保持一致）这两条代码路径

> <https://github.com/discourse/discourse/pull/40698>
>
> Previously, the user directory (\`/u\`) search only matched usernames -- it never …found people by their \*searchable\* user custom field values (e.g. "Company" or "Member ID"), even though the quick search did. The gap appeared whenever \`enable\_names\` was off or the term contained \`\_\`, \`.\` or \`-\`, so member IDs, emails and phone numbers never matched.
> 
> This change lets the directory search those fields too, via an opt-in \`search\_custom\_fields:\` option on \`UserSearch\` that searches the \`user\_search\_data\` tsvector (mention autocomplete and chat are unchanged). It also escapes \`LIKE\` wildcards in the search term with \`sanitize\_sql\_like\`, and adds a tooltip warning that the "Searchable" toggle makes a field's value publicly findable in search.
> 
> Reported at https://meta.discourse.org/t/trouble-searching-user-custom-fields/404800

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2026年六月15日 10:21 UTC](https://meta.discourse.org/t/trouble-searching-user-custom-fields/404800/4 "2026-06-15T10:21:23Z")

</div>


