# 改进 CJK帖子的 word\_count 计算，或使用 char count

**URL:** <https://meta.discourse.org/t/improve-word-count-calculation-for-cjk-posts-or-use-char-count/380085>\
**Category:** Bug\
**Created:** [2025年八月24日 15:10 UTC](https://meta.discourse.org/t/improve-word-count-calculation-for-cjk-posts-or-use-char-count/380085 "2025-08-24T15:10:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lhc\_fl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lhc_fl/32/268115_2.png) [@Lhc\_fl](https://meta.discourse.org/u/Lhc_fl)\
**Post date:** [2025年八月24日 15:10 UTC](https://meta.discourse.org/t/improve-word-count-calculation-for-cjk-posts-or-use-char-count/380085/1 "2025-08-24T15:10:01Z")

</div>

`Post` 和 `Topic` 的 `word_count` 列似乎是直接通过空格数量计算的，这对于不使用空格的中文、日文和韩文等语言来说是完全不合适的。

这并不是一个大问题，因为 `word_count` 很少被使用，但在 `AI summary backfill minimum word count` 中遇到了麻烦。长的中文帖子会被过滤掉，但夹杂着中文和英文（有很多空格）的短帖子却会被总结。

我认为我们应该使用支持多种语言的单词分词器，或者在 `AI summary backfill minimum word count` 等地方简单地使用字符计数。

---

<div class="post-metadata">

**Author:** ![Lhc\_fl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lhc_fl/32/268115_2.png) [@Lhc\_fl](https://meta.discourse.org/u/Lhc_fl)\
**Post date:** [2025年八月24日 15:10 UTC](https://meta.discourse.org/t/improve-word-count-calculation-for-cjk-posts-or-use-char-count/380085/2 "2025-08-24T15:10:35Z")

</div>

举个例子如果在数据资源管理器里检查这个帖子的单词数量会发现仅仅只有一个

---

<div class="post-metadata">

**Author:** ![Lhc\_fl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lhc_fl/32/268115_2.png) [@Lhc\_fl](https://meta.discourse.org/u/Lhc_fl)\
**Post date:** [2025年八月24日 15:14 UTC](https://meta.discourse.org/t/improve-word-count-calculation-for-cjk-posts-or-use-char-count/380085/3 "2025-08-24T15:14:46Z")

</div>

例如，如果在数据资源管理器中检查此帖子的单词数，您会发现只有一个。

这显然是错误的，并且可能影响了用户的阅读时间计算，因为 `read_time_word_count` 依赖于单词数。

---

<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:** [2025年八月24日 23:37 UTC](https://meta.discourse.org/t/improve-word-count-calculation-for-cjk-posts-or-use-char-count/380085/4 "2025-08-24T23:37:52Z")

</div>

嗯，如果我们能聪明地处理我们的管道，我们可以使用 cppjieba。

> <https://github.com/discourse/discourse/blob/a8ed5b19f95107a0dafc463e4cbf99d84ea42311/lib/search.rb#L137-L132>

这将需要 update\_index! 来处理这个：

> <https://github.com/discourse/discourse/blob/a8ed5b19f95107a0dafc463e4cbf99d84ea42311/app/services/search_indexer.rb#L32-L32>

* * *

考虑到阅读单词 `bla` 比阅读 `supercalifragilisticexpialidocious` 快得多，字符计数可能是最简单的方法。

我想知道你是否可以做一个 PR 来改变我们依赖字符计数，然后我们可以将字符计数除以 4（例如，对于英语）和 2（对于中文）？（通过一些设置）

@lindsey 这是你感兴趣的一个话题。

---

<div class="post-metadata">

**Author:** ![pangbo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pangbo/32/538562_2.png) [@pangbo](https://meta.discourse.org/u/pangbo)\
**Post date:** [2025年八月25日 11:24 UTC](https://meta.discourse.org/t/improve-word-count-calculation-for-cjk-posts-or-use-char-count/380085/5 "2025-08-25T11:24:46Z")

</div>

For Chinese, character count is the most commonly used method for measuring text length. In terms of implementation, we could use a regular expression to filter Chinese characters and then directly count them. This approach is efficient enough and aligns with Chinese usage habits. Although naming it `word_count` instead of `char_count` might seem a bit confusing, perhaps we could clarify this point in the description of the relevant settings.
