# Search does not seem to work for tags with emoji

**URL:** <https://meta.discourse.org/t/search-does-not-seem-to-work-for-tags-with-emoji/141458>\
**Category:** Bug\
**Created:** [February 13, 2020, 1:36am UTC](https://meta.discourse.org/t/search-does-not-seem-to-work-for-tags-with-emoji/141458 "2020-02-13T01:36:14Z")\
**Posts on this page:** 7\
**Page:** 1

## AI-generated summary

A user, [arnaud_sahuguet](/t/-/141458/1), reported an issue with search functionality on the forum, specifically with tags containing emojis. The search does not return topics correctly when using tags with emojis. 

[joffreyjaffeux](/t/-/141458/3) identified the problem being the regex used in `search.rb` does not allow emojis. A possible solution is to use a dedicated emoji regex, such as [ruby-emoji-regex](https://github.com/ticky/ruby-emoji-regex).

[sam](/t/-/141458/4) expressed concerns about supporting this edge case, while [joffreyjaffeux](/t/-/141458/5) pointed out that there is no validating regex for the Tag class. [neil](/t/-/141458/6) suggested looking into supporting this in version 2.5, as there are no tests for emoji tag names.

[lucasbasquerotto](/t/-/141458/7) further investigated the issue and found that search works partially when using only the tag or with certain keywords, but not with the expected topic.

<div class="post-metadata">

**Author:** ![arnaud\_sahuguet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arnaud_sahuguet/32/122538_2.png) [@arnaud\_sahuguet](https://meta.discourse.org/u/arnaud_sahuguet)\
**Post date:** [February 13, 2020, 1:36am UTC](https://meta.discourse.org/t/search-does-not-seem-to-work-for-tags-with-emoji/141458/1 "2020-02-13T01:36:14Z")

</div>

I have tags that contain emojis, e.g. `new-york-city-🇺🇸`.  
When using the search and advanced search, I don’t get the topics.

Here is an example:  
Query:  
[https://urbantech-forum.cornelltech.io/search?expanded=true&q=tags%3Anew-york-city-🇺🇸subway](https://urbantech-forum.cornelltech.io/search?expanded=true&q=tags%3Anew-york-city-%F0%9F%87%BA%F0%9F%87%B8subway)

And here is a topic that should be returned:  
[https://urbantech-forum.cornelltech.io/t/subway-accessibility-info-and-elevator-escalator-status-alerts/139](https://urbantech-forum.cornelltech.io/t/subway-accessibility-info-and-elevator-escalator-status-alerts/139)

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [February 13, 2020, 2:46am UTC](https://meta.discourse.org/t/search-does-not-seem-to-work-for-tags-with-emoji/141458/2 "2020-02-13T02:46:45Z")

</div>

Not sure if this is resolvable, what is your take @neil?

---

<div class="post-metadata">

**Author:** ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)\
**Post date:** [February 13, 2020, 9:40am UTC](https://meta.discourse.org/t/search-does-not-seem-to-work-for-tags-with-emoji/141458/3 "2020-02-13T09:40:22Z")

</div>

AFAIK it’s only because the regex we have here:

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

is not allowing emojis. If this was matching on emoji, it would work after.

We might want to consider using something like: [GitHub - ticky/ruby-emoji-regex: 💎 A set of Ruby regular expressions for matching Unicode Emoji symbols. · GitHub](https://github.com/ticky/ruby-emoji-regex) to have a good emoji regex.

what do you think @sam ?

---

<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:** [February 13, 2020, 10:22am UTC](https://meta.discourse.org/t/search-does-not-seem-to-work-for-tags-with-emoji/141458/4 "2020-02-13T10:22:48Z")

</div>

Oh my, this feels like one big monster to support for a major edge case, do we already have a validating regex on the Tag class?

---

<div class="post-metadata">

**Author:** ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)\
**Post date:** [February 13, 2020, 10:35am UTC](https://meta.discourse.org/t/search-does-not-seem-to-work-for-tags-with-emoji/141458/5 "2020-02-13T10:35:22Z")

</div>

I don’t think we do, might be wrong though @neil probably knows better  
AFAIK we just have this `clean_tag` function:

> <https://github.com/discourse/discourse/blob/main/lib/discourse_tagging.rb#L379>

Which is kinda copied in client side here:

[https://github.com/discourse/discourse/blob/master/app/assets/javascripts/select-kit/mixins/tags.js.es6#L80](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/select-kit/mixins/tags.js.es6#L80)

Also this would probably be useful at other places as we for example generate this client side: [https://github.com/discourse/discourse/blob/master/app/assets/javascripts/pretty-text/emoji.js.es6#L24](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/pretty-text/emoji.js.es6#L24)

---

<div class="post-metadata">

**Author:** ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)\
**Post date:** [February 13, 2020, 4:25pm UTC](https://meta.discourse.org/t/search-does-not-seem-to-work-for-tags-with-emoji/141458/6 "2020-02-13T16:25:49Z")

</div>

I doubt that we have any tests for emoji tag names. Maybe we can look into supporting this in 2.5?

---

<div class="post-metadata">

**Author:** ![lucasbasquerotto](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lucasbasquerotto/32/133376_2.png) [@lucasbasquerotto](https://meta.discourse.org/u/lucasbasquerotto)\
**Post date:** [February 13, 2020, 5:56pm UTC](https://meta.discourse.org/t/search-does-not-seem-to-work-for-tags-with-emoji/141458/7 "2020-02-13T17:56:29Z")

</div>

I see that the search returns only one topic when using only the tag (without the `subway` keyword) in the search (it’s not the topic posted in the OP):

[https://urbantech-forum.cornelltech.io/search?expanded=true&q=tags%3Anew-york-city-🇺🇸](https://urbantech-forum.cornelltech.io/search?expanded=true&q=tags%3Anew-york-city-%F0%9F%87%BA%F0%9F%87%B8)

It also works with other keywords (but only for that topic returned previously):

[https://urbantech-forum.cornelltech.io/search?expanded=true&q=tags%3Anew-york-city-🇺🇸%20personal](https://urbantech-forum.cornelltech.io/search?expanded=true&q=tags%3Anew-york-city-%F0%9F%87%BA%F0%9F%87%B8%20personal)

If I don’t use tags it returns correctly:

[https://urbantech-forum.cornelltech.io/search?expanded=true&q=new-york-city-🇺🇸](https://urbantech-forum.cornelltech.io/search?expanded=true&q=new-york-city-%F0%9F%87%BA%F0%9F%87%B8)

The topic returned previously, with the tag, is the 1st returned using a keyword with the tag name, but the post is another (but it might just be because of (maybe) a metadata or something like this in the post that is caught by the search, and not the tag itself, but I can’t say for sure).
