# Certain numerical substrings are ignored

**URL:** https://meta.discourse.org/t/certain-numerical-substrings-are-ignored/34207
**Category:** Feature
**Tags:** search
**Created:** [October 7, 2015, 3:25am UTC](https://meta.discourse.org/t/certain-numerical-substrings-are-ignored/34207 "2015-10-07T03:25:15Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Eric\_Toombs](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@Eric\_Toombs](https://meta.discourse.org/u/Eric_Toombs)
#### Post date: [October 7, 2015, 3:25am UTC](https://meta.discourse.org/t/certain-numerical-substrings-are-ignored/34207/1 "2015-10-07T03:25:15Z")

</div>

If a topic title has the string `CHEM894` and somebody searches for `894`, that topic will appear as you would expect. But if it were `CHEM123` and somebody searches for `123`, it doesn’t get found. It’s weird. Furthermore, if somebody searches for `chem 1`, the topic _will_ appear. `CHEM321` doesn’t work either with similar behaviour. It looks like the built-in search engine won’t search for certain numbers within words. There are other unexpected inconsistencies with the same theme, like “chem 123” _sometimes_ finds a title with “chem123” and sometimes doesn’t. Could somebody maybe try to reproduce this behaviour?

edit: adding ‘chem132’ to test this site’s search engine.

---

<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: [October 8, 2015, 8:15am UTC](https://meta.discourse.org/t/certain-numerical-substrings-are-ignored/34207/2 "2015-10-08T08:15:26Z")

</div>

![](https://global.discourse-cdn.com/meta/original/3X/8/c/8c0cc1bc3afdd042ce4038c8a22ac80ae012656c.png)

I have seen a similar request on a customer complaining about search ranking.

I wonder if we should give a special relevance bump for stuff that happened in the last 10 days or so.

Also… upgrade to latest, I fixed stuff here in the last release.

---

<div class="post-metadata">

### Author: ![Eric\_Toombs](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@Eric\_Toombs](https://meta.discourse.org/u/Eric_Toombs)
#### Post date: [October 8, 2015, 8:02pm UTC](https://meta.discourse.org/t/certain-numerical-substrings-are-ignored/34207/3 "2015-10-08T20:02:18Z")

</div>

I’m running [this](https://github.com/discourse/discourse/tree/81a48af1a3579c3f1ab5bc06b94dd98125f6f9d4) version. Is this before or after your changes? I upgraded just a few days ago. This has been happening with posts submitted and searched for after the upgrade.

Interesting screen cap. My post may have only been found because it had the string ‘123’ as well as ‘chem123’. If it only had ‘chem123’, it might not have been found at all.

---

<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: [October 8, 2015, 8:52pm UTC](https://meta.discourse.org/t/certain-numerical-substrings-are-ignored/34207/4 "2015-10-08T20:52:43Z")

</div>

It s being stemmed out, will have a look at why

---

<div class="post-metadata">

### Author: ![Eric\_Toombs](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@Eric\_Toombs](https://meta.discourse.org/u/Eric_Toombs)
#### Post date: [October 8, 2015, 9:01pm UTC](https://meta.discourse.org/t/certain-numerical-substrings-are-ignored/34207/5 "2015-10-08T21:01:43Z")

</div>

I added the string ‘chem132’ to this topic to further test this. I just confirmed that neither ‘A132A’ without the 'A’s nor ‘chemA132’ with the ‘A’ replaced with a space find this topic. Sorry about the 'A’s, but I wanted to make sure those strings stayed out of the topic so that others could test the same search strings under the same conditions.

In other words, I was right and the only reason 123 found this topic was because 123 was in it by itself. 123 would not have found chem123.

Thanks for your investigation, @sam!

---

<div class="post-metadata">

### Author: ![Eric\_Toombs](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@Eric\_Toombs](https://meta.discourse.org/u/Eric_Toombs)
#### Post date: [April 9, 2016, 7:45am UTC](https://meta.discourse.org/t/certain-numerical-substrings-are-ignored/34207/6 "2016-04-09T07:45:17Z")

</div>

Has any progress been made to address this? Our discourse website is otherwise ready, but we would really like to fix it before we release. I have some time to try help fix this bug. I am actually learning RoR specifically for this reason. Can I work with whomever is addressing this bug? Or else, could anybody just point me in the right direction?

---

<div class="post-metadata">

### Author: ![gdpelican](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gdpelican/32/81308_2.png) [@gdpelican](https://meta.discourse.org/u/gdpelican)
#### Post date: [April 9, 2016, 9:25am UTC](https://meta.discourse.org/t/certain-numerical-substrings-are-ignored/34207/7 "2016-04-09T09:25:06Z")

</div>

You’ll be interested in the `post_search_data` table, which stores `tsvector` information about each post (the tsvectors are weighted collections of lexemes / word roots, which postgres can compare to a search term much faster than a raw post body).

The class you’re looking for is `lib/search.rb` which is… well, a bit tangled, but the line which executes the search is here:

> <https://github.com/discourse/discourse/blob/main/lib/search.rb#L475>

If I had a wild guess, I would guess that converting the word ‘chem123’ to a lexeme results in `{'chem123':1}`, which doesn’t match the tsquery `123`

 ![](https://global.discourse-cdn.com/meta/original/3X/b/1/b18e0237d97de0949abd7ed5410493b64aad1656.png)

(The ‘f’ is for false, aka, the document ‘chem123’ isn’t a match for the search term ‘123’)

I definitely don’t have my head around a good fix for that, but I wish you luck! Maybe you could write a clause in there specifically for if the query is a number.

PS I found [this post](http://rachbelaid.com/postgres-full-text-search-is-good-enough/) to be a really great intro to how postgres does its fulltext search.

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [December 4, 2025, 11:37am UTC](https://meta.discourse.org/t/certain-numerical-substrings-are-ignored/34207/8 "2025-12-04T11:37:02Z")

</div>


