# 关于法语搜索处理（“œ”和“æ”特殊字符）的改进建议

**URL:** <https://meta.discourse.org/t/suggestion-of-a-slight-improvement-regarding-french-search-processing-oe-and-ae-special-characters/218973>\
**Category:** Feature\
**Tags:** search, completed\
**Created:** [2022年二月21日 17:05 UTC](https://meta.discourse.org/t/suggestion-of-a-slight-improvement-regarding-french-search-processing-oe-and-ae-special-characters/218973 "2022-02-21T17:05:48Z")\
**Posts on this page:** 8\
**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:** [2022年二月21日 17:05 UTC](https://meta.discourse.org/t/suggestion-of-a-slight-improvement-regarding-french-search-processing-oe-and-ae-special-characters/218973/1 "2022-02-21T17:05:48Z")

</div>

一些法语单词使用以下字符：

- Œ, œ，例如在 œuf（鸡蛋）或 cœur（心脏）中，œuvre（有多种翻译和含义，此处不详述，无关紧要），[其他](https://www.motsavec.com/search.php?m=%C5%93)。
- Æ, æ，例如在 nævus（痣的科学术语（皮肤上的点，不是动物）或 [其他](https://www.motsavec.com/search.php?m=%C3%A6)）。

**æ** 很少使用（我认为它总是源自拉丁语的科学/医学术语？），但 **œ** 在法语中却相当常见。

遗憾的是，法语键盘布局中没有这些特殊字符，很多人干脆写“oe”或“ae”代替。  
但是，一些用户拥有自定义布局，智能手机的自动更正，或其他一些书写辅助系统经常会自动更正单词，使用正确的“合并字符”，例如“oeuvre” → “œuvre”。

目前，搜索会将“oe”和“œ”视为不同的字符串进行处理，这会导致不同的结果，而这些结果本应是相同的。

示例：  
[https://forum.monocycle.info/search?q=coeur](https://forum.monocycle.info/search?q=coeur)  
[https://forum.monocycle.info/search?q=cœur](https://forum.monocycle.info/search?q=c%C5%93ur)

我的建议是，“oe”和“œ”、“OE”和“Œ”应被视为相同的字符串进行处理。同样，“ae”和“æ”、“AE”和“Æ”也应如此。

---

<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:** [2022年二月23日 23:57 UTC](https://meta.discourse.org/t/suggestion-of-a-slight-improvement-regarding-french-search-processing-oe-and-ae-special-characters/218973/2 "2022-02-23T23:57:31Z")

</div>

@zogstrip / @j.jaffeux 这是一个非常有趣的问题，您怎么看？我们可以添加一个由站点设置支持的 normalizer。

---

<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:** [2022年二月24日 13:30 UTC](https://meta.discourse.org/t/suggestion-of-a-slight-improvement-regarding-french-search-processing-oe-and-ae-special-characters/218973/3 "2022-02-24T13:30:07Z")

</div>

```plaintext
SELECT to_tsvector('french', E'Cette oeuvre d\\'art n\\'est pas une œuvre.');
            to_tsvector             
------------------------------------
 'art':4 'cet':1 'oeuvr':2 'œuvr':9
(1 row)

```

出于某些原因，我认为处理重音符号、连字等是搜索中已解决的问题……我猜不是？🤷‍♂️

> [@sam](#):
>
> 我们可以添加一个由站点设置支持的正常化器。

作为一个 🇫🇷，我绝对支持这一点。看起来我们可以使用 [PostgreSQL 的 `unaccent`](https://www.postgresql.org/docs/current/unaccent.html)，它可以移除重音符号，还可以处理常见的连字。

```plaintext
SELECT to_tsvector('french', unaccent('œuvre poêle œuf Noël électroencéphalogramme æ Æ'));
                               to_tsvector                               
-------------------------------------------------------------------------
 'ae':6,7 'electroencephalogramm':5 'noel':4 'oeuf':3 'oeuvr':1 'poel':2
(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:** [2022年二月24日 13:33 UTC](https://meta.discourse.org/t/suggestion-of-a-slight-improvement-regarding-french-search-processing-oe-and-ae-special-characters/218973/4 "2022-02-24T13:33:51Z")

</div>

> [@zogstrip](#):
>
> 作为一名 🇫🇷

而且作为一个法国人，你是否和我一样讨厌这种（虽然有趣但却）无用的语言复杂性？ 😄  
 抱歉，有点离题的幽默

---

<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:** [2022年二月25日 02:09 UTC](https://meta.discourse.org/t/suggestion-of-a-slight-improvement-regarding-french-search-processing-oe-and-ae-special-characters/218973/5 "2022-02-25T02:09:23Z")

</div>

您认为我们应该直接修改 `search_ignore_accents` 的实现以使用 `unaccent`，还是需要一个全新的设置？

我比较倾向于直接更改忽略重音的实现，因为这与 PG 的做法保持一致。

---

<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:** [2022年二月25日 14:44 UTC](https://meta.discourse.org/t/suggestion-of-a-slight-improvement-regarding-french-search-processing-oe-and-ae-special-characters/218973/6 "2022-02-25T14:44:29Z")

</div>

> [@sam](#):
>
> 您认为我们应该直接修改 `search_ignore_accents` 的实现以使用 `unaccent`，还是需要一个全新的设置？

这是个好问题 🤔  
这对于 🇫🇷 肯定会起作用，但其他地区可能不符合预期？  
查看 `/usr/share/postgresql/13/tsearch_data/unaccent.rules` 文件后，看起来很安全。  
我绝对支持删除我们 `search_ignore_accents` 设置以使用 postgresql 的 `unaccent` 👍  
@nbianca 您能把它加到您的待办事项里吗？

---

<div class="post-metadata">

**Author:** ![nbianca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nbianca/32/157984_2.png) [@nbianca](https://meta.discourse.org/u/nbianca)\
**Post date:** [2022年三月8日 17:52 UTC](https://meta.discourse.org/t/suggestion-of-a-slight-improvement-regarding-french-search-processing-oe-and-ae-special-characters/218973/7 "2022-03-08T17:52:01Z")

</div>

我在这个 PR 中用 Postgresql 的 unaccent 替换了我们旧的 Ruby 实现：

> <https://github.com/discourse/discourse/pull/16100>
>
> The search\_ignore\_accents site setting can be used to make the search
> indexer r…emove the accents before indexing the content. The unaccent
> function from PostgreSQL is better than Ruby's unicode\_normalize(:nfkd).

---

<div class="post-metadata">

**Author:** ![nbianca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nbianca/32/157984_2.png) [@nbianca](https://meta.discourse.org/u/nbianca)\
**Post date:** [2022年三月12日 06:00 UTC](https://meta.discourse.org/t/suggestion-of-a-slight-improvement-regarding-french-search-processing-oe-and-ae-special-characters/218973/8 "2022-03-12T06:00:49Z")

</div>

此主题已在 3 天后自动关闭。不再允许回复。
