# Search a term in Japanese

**URL:** https://meta.discourse.org/t/search-a-term-in-japanese/97359
**Category:** Support
**Created:** [17 בספטמבר,‏ 2018,‏ 1:58pm UTC](https://meta.discourse.org/t/search-a-term-in-japanese/97359 "2018-09-17T13:58:22Z")
**Posts on this page:** 7
**Page:** 2

<div class="post-metadata">

### Author: ![SSS](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@SSS](https://meta.discourse.org/u/SSS)
#### Post date: [13 ביולי,‏ 2020,‏ 5:50am UTC](https://meta.discourse.org/t/search-a-term-in-japanese/97359/21 "2020-07-13T05:50:36Z")

</div>

Thank you for your reply.

1. A sample paragraph here in katakana  
通報テスト9, 通報テスト11, 通報テスト8… etc.

2. A sample search term that you have that is not working  
テスト  
The “テスト” is not working.  

3. Confirmation that your site locale is in Japanese or that `search tokenize chinese japanese korean` is enabled  
Yes, I have confirmed that both settings are set correctly.

---

<div class="post-metadata">

### Author: ![SSS](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@SSS](https://meta.discourse.org/u/SSS)
#### Post date: [15 ביולי,‏ 2020,‏ 1:08am UTC](https://meta.discourse.org/t/search-a-term-in-japanese/97359/24 "2020-07-15T01:08:25Z")

</div>

An incredible thing happened. After changing the ‘min search term length’ from the default value of 2 to 1, we are now able to search for katakana. I don’t know why, but is this setting relevant?

---

<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: [24 באוגוסט,‏ 2020,‏ 9:01am UTC](https://meta.discourse.org/t/search-a-term-in-japanese/97359/26 "2020-08-24T09:01:13Z")

</div>

I can repro this and it is mainly due to a combination of

> <https://github.com/discourse/discourse/blob/e8a842ab8cbbabe92fe33cfc4bbe5f839d4543e9/lib/search.rb#L66-L69>

and

> <https://github.com/discourse/discourse/blob/e8a842ab8cbbabe92fe33cfc4bbe5f839d4543e9/lib/search.rb#L242-L243>

The term `テスト` is converted to `テ ス ト` after going through `CppjiebaRb` and this trips the min\_search\_length protector we have.

@sam This is tricky to fix because we need a proper tokenizer for Japanese to resolve search issues like this for good. We can do tweaks here and there but it is going to be a game of wack a mole.

---

<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: [28 בספטמבר,‏ 2020,‏ 7:14am UTC](https://meta.discourse.org/t/search-a-term-in-japanese/97359/27 "2020-09-28T07:14:51Z")

</div>

I don’t think there exists a proper Japanese segmentar we can use.

I think the best thing to do here is simply tone down these defaults to 1.

> <https://github.com/discourse/discourse/blob/580383dff342a9a12f2270a8224b91c12f0e6ca7/config/site_settings.yml#L1837-L1844>

Otherwise we are banning people from searching for house in Japanese which seems reasonable (家) … we allow people to search for house in English.

---

<div class="post-metadata">

### Author: ![yashi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yashi/32/241984_2.png) [@yashi](https://meta.discourse.org/u/yashi)
#### Post date: [2 בפברואר,‏ 2022,‏ 10:13am UTC](https://meta.discourse.org/t/search-a-term-in-japanese/97359/28 "2022-02-02T10:13:13Z")

</div>

I don’t use Ruby these days nor don’t know the requirement from Discourse but there seems to be a gem for “[mecab](https://en.wikipedia.org/wiki/MeCab)”.

> **[mecab | RubyGems.org | your community gem host](https://rubygems.org/gems/mecab/)**

I came to this topic because I found that searching some words doesn’t work on [my hosted public instance](https://forum.spacecubics.com/). I have

- min search term length: 1
- search tokenize chinese japanese korean: enabled
- default locale: Japanese

IIRC, I’ve initialized the site with English locale and changed the setting to Japanese later.

The words I found failed to search are “北側”, “真上”, “一般”. These words are in [this topic](https://forum.spacecubics.com/t/topic/27). Many words work but these don’t. I don’t see any pattern whether a word works or not.

Is there a way to check the generated search index on the hosted instance? I can read both Ruby and Japanese so if there is a way to see how Discourse generate search index for CJK, I might be some help.

[CppjiebaRb](https://github.com/erickguan/cppjieba_rb), or [cppjieba](https://github.com/yanyiwu/cppjieba/blob/master/README_EN.md), mentioned by @tgxworld seems to be for Chinese. Is it used for Japanese locale?

---

<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: [2 בפברואר,‏ 2022,‏ 10:21am UTC](https://meta.discourse.org/t/search-a-term-in-japanese/97359/29 "2022-02-02T10:21:26Z")

</div>

Mecab is sadly not an option, it is GPL and we prefer only to take on MIT and BSD licenses in dependencies

We have a PR that will add [TinySegmenter: Javascriptだけで実装されたコンパクトな分かち書きソフトウェア](http://chasen.org/~taku/software/TinySegmenter/) which has a compatible license. Can you try out the segmenting and let us know how well it works, there is a form on the website you can use to test

---

<div class="post-metadata">

### Author: ![yashi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yashi/32/241984_2.png) [@yashi](https://meta.discourse.org/u/yashi)
#### Post date: [2 בפברואר,‏ 2022,‏ 10:58am UTC](https://meta.discourse.org/t/search-a-term-in-japanese/97359/30 "2022-02-02T10:58:57Z")

</div>

I’ve tried [tiny\_segmenter](https://rubygems.org/gems/tiny_segmenter) from Rubygems and at least it does generate the words I’ve listed in the previous comment.

```ruby
# coding: utf-8
require 'tiny_segmenter'
require 'pp'

s = File.read('topic27.txt')

ts = TinySegmenter.new
sg = ts.segment(s, ignore_punctuation: true)
pp(sg)

```

```shell
bundle exec ruby test.rb | grep -e 北側 -e 真上 -e 一般
 "北側",
 "真上",
 "一般",
 "一般",
 "一般",
 "北側",
 "一般",

```

A quick search about TinySegmenter told me that the model it uses isn’t as good. There is model generator for it.

[https://github.com/shogo82148/TinySegmenterMaker](https://github.com/shogo82148/TinySegmenterMaker)

I haven’t tried it though.

[Previous page](https://meta.discourse.org/t/search-a-term-in-japanese/97359.md?page=1)
