# What does posts.word\_count column mean in the database?

**URL:** https://meta.discourse.org/t/what-does-posts-word-count-column-mean-in-the-database/37719
**Category:** Support
**Created:** [11 januari 2016 om 01:02 UTC](https://meta.discourse.org/t/what-does-posts-word-count-column-mean-in-the-database/37719 "2016-01-11T01:02:38Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)
#### Post date: [11 januari 2016 om 01:02 UTC](https://meta.discourse.org/t/what-does-posts-word-count-column-mean-in-the-database/37719/1 "2016-01-11T01:02:38Z")

</div>

I need word count per topic for a badge query.  
I found the `word_count` column in the `posts` table, but it seems not what I need.

For instance, this raw text:

> так тут і питання, що якщо без вакцин ніяк, то обійдусь без кролів. Але є в деяких людей позитивний досвід, 3 роки без хвороб і вакцин один з них. Тримають в ямі.

Has a `word_count` = 1.

So, it is either a bug in how word counting works, or the column is simply supposed to do something else.

Please advise.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [11 januari 2016 om 01:27 UTC](https://meta.discourse.org/t/what-does-posts-word-count-column-mean-in-the-database/37719/2 "2016-01-11T01:27:54Z")

</div>

AFAIK `word_count` is the site setting used for the “too short” modal, not a count of the words in a post.

I doubt that data exists. Not that it couldn’t get got, but I fear it would be a massive resource hog to do retro.

---

<div class="post-metadata">

### Author: ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)
#### Post date: [11 januari 2016 om 01:32 UTC](https://meta.discourse.org/t/what-does-posts-word-count-column-mean-in-the-database/37719/3 "2016-01-11T01:32:00Z")

</div>

Not sure how a site setting is related to a column in the `posts` table.

---

<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: [11 januari 2016 om 09:13 UTC](https://meta.discourse.org/t/what-does-posts-word-count-column-mean-in-the-database/37719/4 "2016-01-11T09:13:45Z")

</div>

“`word_count`” is computed with “`raw.scan(/\w+/).size`” which unfortunately doesn’t work properly on non-latin sentences… ☹

I’m thinking of replacing it with “`raw.scan(/[[:word:]]+/).size`” which returns **32** for your example sentence. Is that correct?

```ruby
["так", "тут", "і", "питання", "що", "якщо", "без", "вакцин", "ніяк", "то", "обійдусь", "без", "кролів", "Але", "є", "в", "деяких", "людей", "позитивний", "досвід", "3", "роки", "без", "хвороб", "і", "вакцин", "один", "з", "них", "Тримають", "в", "ямі"]

```

**EDIT:** FYI this value is used to compute the “`read_time`” of the topic 😉

---

<div class="post-metadata">

### Author: ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)
#### Post date: [11 januari 2016 om 09:29 UTC](https://meta.discourse.org/t/what-does-posts-word-count-column-mean-in-the-database/37719/5 "2016-01-11T09:29:52Z")

</div>

Your fixed example looks good!

---

<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: [11 januari 2016 om 10:16 UTC](https://meta.discourse.org/t/what-does-posts-word-count-column-mean-in-the-database/37719/6 "2016-01-11T10:16:50Z")

</div>

Here’s the fix 🌻

> <https://github.com/discourse/discourse/commit/cf4cb2126a026f8240e5d0bc2ea97e8ebb206b81>

---

<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: [11 januari 2016 om 10:16 UTC](https://meta.discourse.org/t/what-does-posts-word-count-column-mean-in-the-database/37719/7 "2016-01-11T10:16:53Z")

</div>


