# 搜索应将特殊字符与其“常规”等效字符匹配

**URL:** https://meta.discourse.org/t/the-search-should-match-fancy-characters-with-their-regular-equivalent/162064
**Category:** UX
**Tags:** search
**Created:** [2020年八月25日 23:04 UTC](https://meta.discourse.org/t/the-search-should-match-fancy-characters-with-their-regular-equivalent/162064 "2020-08-25T23:04:10Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [2020年八月25日 23:04 UTC](https://meta.discourse.org/t/the-search-should-match-fancy-characters-with-their-regular-equivalent/162064/1 "2020-08-25T23:04:11Z")

</div>

我在搜索中复制粘贴了一个主题标题（按显示的原样，包含特殊字符）：  
`New Lowe's commercial with UniGeezer`

 ![image](https://global.discourse-cdn.com/meta/original/3X/2/4/2483771bb41fa02220d33248cf02c60557307e21.png)

没有结果：

 ![image](https://global.discourse-cdn.com/meta/original/3X/8/e/8ee4089932b78cf95638842a22460f2ad58fd4c4.png)

我将搜索框中的特殊引号替换为“普通”引号：  
`New Lowe's commercial with UniGeezer`

现在主题出现了。

 ![image](https://global.discourse-cdn.com/meta/original/3X/5/5/55610d1a29d7603ea472e53b4983b44e7e6fee85.png)

我的建议是，搜索应将每个特殊字符与原始字符进行匹配。

---

<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年八月26日 02:19 UTC](https://meta.discourse.org/t/the-search-should-match-fancy-characters-with-their-regular-equivalent/162064/2 "2020-08-26T02:19:25Z")

</div>

好问题，@sam，我们该如何处理这个问题？

---

<div class="post-metadata">

### Author: ![TheBestPessimist](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thebestpessimist/32/247704_2.png) [@TheBestPessimist](https://meta.discourse.org/u/TheBestPessimist)
#### Post date: [2020年八月26日 04:29 UTC](https://meta.discourse.org/t/the-search-should-match-fancy-characters-with-their-regular-equivalent/162064/3 "2020-08-26T04:29:33Z")

</div>

那变音符号呢？

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2020年八月26日 08:00 UTC](https://meta.discourse.org/t/the-search-should-match-fancy-characters-with-their-regular-equivalent/162064/4 "2020-08-26T08:00:15Z")

</div>

我们已经有针对变音符号的规范化处理，因此或许也可以采用类似的方法来解决这个问题。

@tgxworld 可以思考一下。

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [2020年十二月22日 03:03 UTC](https://meta.discourse.org/t/the-search-should-match-fancy-characters-with-their-regular-equivalent/162064/6 "2020-12-22T03:03:07Z")

</div>

@Canapin 你还能复现这个问题吗？我尝试在本地复现但未能成功。搜索数据中的撇号已被移除，因此不应影响搜索功能。

```plaintext
discourse_development=# SELECT TO_TSVECTOR('english', 'New Lowe’s commercial with UniGeezer') @@ PLAINTO_TSQUERY('english', 'New Lowe’s commercial with UniGeezer');
 ?column? 
----------
 t
(1 row)

```

你能否指出你遇到此问题的具体站点，以便我能进行复现？谢谢！

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [2020年十二月22日 13:01 UTC](https://meta.discourse.org/t/the-search-should-match-fancy-characters-with-their-regular-equivalent/162064/7 "2020-12-22T13:01:19Z")

</div>

我仍然遇到这个问题，问题出在我搜索用 `"` 包裹的精确字符串时：

`https://unicyclist.com/search?q=%22New%20Lowe%E2%80%99s%20commercial%20with%20UniGeezer%22`

与

`https://unicyclist.com/search?q=%22New%20Lowe%27s%20commercial%20with%20UniGeezer%22`

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [2020年十二月23日 03:54 UTC](https://meta.discourse.org/t/the-search-should-match-fancy-characters-with-their-regular-equivalent/162064/8 "2020-12-23T03:54:16Z")

</div>

感谢提供复现步骤。这主要影响使用 `"` 包裹的精确术语搜索。问题在于，话题的实际标题是 `New Lowe's commercial with UniGeezer`，而美化后的标题是 `New Lowe’s commercial with UniGeezer`。在进行精确术语搜索时，我们仅将给定术语与话题的实际标题进行匹配，而未考虑美化后的标题。

这里的难点在于，我们不能无条件地将 `’` 替换为 `'`，因为包含 `’` 的话题标题将无法匹配。我有点不确定该如何处理，因为在客户端显示话题标题时，我们展示的是不同的字符。

@gerhard @sam 你们之前似乎解决过类似的引号问题，对此有什么建议吗？老实说，这只是一个边缘情况，只会影响极小部分的搜索查询。我倾向于暂时搁置这个问题。

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2020年十二月23日 04:26 UTC](https://meta.discourse.org/t/the-search-should-match-fancy-characters-with-their-regular-equivalent/162064/9 "2020-12-23T04:26:00Z")

</div>

> [@tgxworld](#):
>
> 我倾向于直接在这里玩个 **双关语** 。

这可不是什么笑话！😜

我想我们可以在索引和搜索词中将 `’` 规范化为 `'`。但老实说，我不确定是否值得为此付出巨大的精力去修复这个问题。

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [2020年十二月23日 05:42 UTC](https://meta.discourse.org/t/the-search-should-match-fancy-characters-with-their-regular-equivalent/162064/10 "2020-12-23T05:42:15Z")

</div>

> [@sam](#):
>
> 我想我们可以在索引和搜索词中将 `’` 规范化为 `'`。

这与搜索索引无关。对于精确匹配，我们会将其与 `Post#raw` 和 `Topic#title` 进行比对：

> <https://github.com/discourse/discourse/blob/755627caa512058ebee332f40f9743024bb262f3/lib/search.rb#L942>

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2020年十二月23日 05:45 UTC](https://meta.discourse.org/t/the-search-should-match-fancy-characters-with-their-regular-equivalent/162064/11 "2020-12-23T05:45:02Z")

</div>

明白了，是啊……这里确实没有简单的解决方案，我想这只能是我们不得不忍受的一个小问题了。
