# User mention full name search is not working for Unicode names

**URL:** https://meta.discourse.org/t/user-mention-full-name-search-is-not-working-for-unicode-names/53691
**Category:** Bug
**Created:** [2 december 2016 om 15:44 UTC](https://meta.discourse.org/t/user-mention-full-name-search-is-not-working-for-unicode-names/53691 "2016-12-02T15:44:11Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![ibnesayeed](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ibnesayeed/32/120427_2.png) [@ibnesayeed](https://meta.discourse.org/u/ibnesayeed)
#### Post date: [2 december 2016 om 19:15 UTC](https://meta.discourse.org/t/user-mention-full-name-search-is-not-working-for-unicode-names/53691/3 "2016-12-02T19:15:23Z")

</div>

> [@Full name @mentions](https://meta.discourse.org/t/full-name-mentions/23896/23):
>
> Nope, we are not ever adding spaces to matches for mentions. Sorry. That’s never gonna happen on my watch.

I wont’t be too certain about saying `never` when it comes to software features. Software is to help people, not to punish them. There are good examples out there to learn from, how to implement something that caters to the needs of a broader audience. I understand that sometimes architectural design decisions, that were made earlier, may limit the ability to do specific things in specific ways, but user needs and good experience should always be the priority.

> [@Falco](#):
>
> That being said, after using a board with 5.000 people with the same first name, I would like an option to allow spaces.

I am not well aware of the codebase, but here is one approach that could work efficiently while allowing full name searches with spaces in many languages. I am supposing here that the server looks up for matches in the user ID and full name fields for the mention queries. Here is a pseudo-code to illustrate how the client could behave (expressed in Ruby-ish syntax, though it would be JavaScript eventually, if implemented):

```ruby
MAX_SUGGESTIONS = 6

result_cache = [] # use a set for deduplication, do not clear often to maximize reuse
prefix_match_exhausted = false # whether server returns less results than MAX_SUGGESTIONS
mention_mode = false
query_prefix = ""

def reset_mention
  prefix_match_exhausted = false
  mention_mode = false
  query_prefix = ""
end

def request_server
  results = response_from_server(query_prefix)
  result_cache.add(results)
  if results.length < MAX_SUGGESTIONS
    prefix_match_exhausted = true
  end
end

def populate_suggestions
  # cancel previous trigger if the timer is not up yet
  suggestions = find_in_cache(query_prefix)
  unless prefix_match_exhausted || suggestions.length >= MAX_SUGGESTIONS
    suggestions = request_server
    if suggestions.length.zero?
      reset_mention
    else
      render_auto_suggest(suggestions)
    end
  end
end

case typed_char
when "@"
  mention_mode = true
when "\r", "\n" # or any character that is neither allowed user IDs nor in full names
  reset_mention
when "\b"
  at_pos = position_of_at_sign_in_the_current_line
  if at_pos >= 0
    prefix_match_exhausted = false
    mention_mode = true
    query_prefix = current_line[at_pos..cursor_pos]
    populate_suggestions
  else
    reset_mention
  end
else
  if mention_mode
    query_prefix += typed_char
    populate_suggestions
  end
end

```

This is a rough illustration. There are other places that might improve the performance and reduce server queries, such as:

- asking server to return more results for each query than required to populate the suggestions, this way successive queries can be avoided by spatial locality in the cache
- there could be a `min` and/or `max` number of characters to trigger the `mention_mode`
- the `result_cache` can use the [trie data structure](https://en.wikipedia.org/wiki/Trie), with some flags on nodes that represent prefixes that were actually queried from the server to allow `prefix_match_exhausted` state
- server may return results prioritized based on recent activity and/or reputation

---

_[View the full topic](https://meta.discourse.org/t/user-mention-full-name-search-is-not-working-for-unicode-names/53691)._
