# About searchcode concept

**URL:** https://discuss.tryton.org/t/about-searchcode-concept/4959
**Category:** Ideas
**Created:** [January 27, 2022, 4:16am UTC](https://discuss.tryton.org/t/about-searchcode-concept/4959 "2022-01-27T04:16:45Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![tumashu](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/t/b487fb/32.png) [@tumashu](https://discuss.tryton.org/u/tumashu)
#### Post date: [January 27, 2022, 4:16am UTC](https://discuss.tryton.org/t/about-searchcode-concept/4959/1 "2022-01-27T04:16:45Z")

</div>

In order to quickly search and select the CJK strings, In China, most softwares have the concept of search code. For example, if we want to search for “感冒”, CJK user can type: gm, ganmao, dgjh or other search codes to search, no need to active Input method to input “感冒”, these search codes are predefind or auto generated from CJK string.

My question is: how to define these concepts in gnuhealth and Tryton, which software level is more appropriate to implement this function？

searchcode is different ID, many CJK string will have same searchcode.

Does pyson support user defined function? for example:

(get\_search\_code(‘cjkstring’) “like” “gm”)

---

<div class="post-metadata">

### Author: ![nicoe](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/nicoe/32/2880_2.png) [@nicoe](https://discuss.tryton.org/u/nicoe)
#### Post date: [January 27, 2022, 1:55pm UTC](https://discuss.tryton.org/t/about-searchcode-concept/4959/2 "2022-01-27T13:55:07Z")

</div>

> [@tumashu](#):
>
> In order to quickly search and select the CJK strings, In China, most softwares have the concept of search code. For example, if we want to search for “感冒”, CJK user can type: gm, ganmao, dgjh or other search codes to search, no need to active Input method to input “感冒”

In those software how do they search for “gm” as in the word “pra **gm** atic”?

> [@tumashu](#):
>
> these search codes are predefind or auto generated from CJK string.

I tried to find a way how to infer that “感” is (I presume but I may be wrong) “gm”. I guess it comes from the way it’s pronounced but it’s not in the unicode data of the glyph. It’s probably a database or something.

> [@tumashu](#):
>
> which software level is more appropriate to implement this function？

I would say that the client level have to somehow understand that you’re inputting searchcode and then turn them into their character using this database before sending the data to the server.

But then I wonder why would this way be easier than activating another input method? As I never needed to do that I don’t know how painful switching from one input method to another is in reality 🙂.

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [January 27, 2022, 2:00pm UTC](https://discuss.tryton.org/t/about-searchcode-concept/4959/3 "2022-01-27T14:00:49Z")

</div>

The problem is that we have a mix of locale strings (which may be Chinese) and non-locale. So the client can not really know if it needs to make conversion or not.

So for me we have to look at the fulltext search features. There are maybe options to match using phonetic comparison.

---

<div class="post-metadata">

### Author: ![tumashu](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/t/b487fb/32.png) [@tumashu](https://discuss.tryton.org/u/tumashu)
#### Post date: [January 27, 2022, 2:22pm UTC](https://discuss.tryton.org/t/about-searchcode-concept/4959/4 "2022-01-27T14:22:55Z")

</div>

> [@nicoe](#):
>
> I would say that the client level have to somehow understand that you’re inputting searchcode and then turn them into their character using this database before sending the data to the server.

I think this seem to be not a simple way, because “gm” maybe can link to 1000 possible Chinese Words

while a chinese word may be have only \<10 search codes

---

<div class="post-metadata">

### Author: ![tumashu](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/t/b487fb/32.png) [@tumashu](https://discuss.tryton.org/u/tumashu)
#### Post date: [January 27, 2022, 2:27pm UTC](https://discuss.tryton.org/t/about-searchcode-concept/4959/5 "2022-01-27T14:27:45Z")

</div>

> [@ced](#):
>
> match using phonetic comparison

maybe this is a good idea

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [January 27, 2022, 2:54pm UTC](https://discuss.tryton.org/t/about-searchcode-concept/4959/6 "2022-01-27T14:54:21Z")

</div>

There are [PostgreSQL: Documentation: 17: F.16.&nbsp;fuzzystrmatch — determine string similarities and distance](https://www.postgresql.org/docs/current/fuzzystrmatch.html) extension but unfortunately it does not combine with tsvector: [https://stackoverflow.com/a/20439153/687601](https://stackoverflow.com/a/20439153/687601)

---

<div class="post-metadata">

### Author: ![tumashu](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/t/b487fb/32.png) [@tumashu](https://discuss.tryton.org/u/tumashu)
#### Post date: [January 28, 2022, 6:12am UTC](https://discuss.tryton.org/t/about-searchcode-concept/4959/7 "2022-01-28T06:12:10Z")

</div>

A poor man’s approach maybe: adding a searchcodes field to models, this search\_codes auto update and no view.

---

<div class="post-metadata">

### Author: ![nicoe](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/nicoe/32/2880_2.png) [@nicoe](https://discuss.tryton.org/u/nicoe)
#### Post date: [January 28, 2022, 7:59am UTC](https://discuss.tryton.org/t/about-searchcode-concept/4959/8 "2022-01-28T07:59:53Z")

</div>

You could indeed use a function field with two underlying fields one with the data the other with the searchcodes of the data and searching on it would search on both.
