Question about users_get_username

Hello, I have a problem, as you know in nakama in the browser you can search for a user using the % prefix to obtain a better search via username but using this function in lua I do not get the same result, it is mandatory to search for the same name.

Is there any way that I can have a better search with that function how does % work in the browser?

Hello @luishd23,

The runtime function to get accounts by username does not allow the use of wildcards (%) as this would require specialised indices to perform at scale.

It’s allowed in the console as this is useful for admin purposes and not to be used very frequently.

Best.

So there is no way that using this or another function to find users that, for example, if I search for luis, I get users like luis25 luis23?

No at the moment we do not expose this intentionally for the reason above. You can use custom queries but you’d also need to add the needed indices to ensure it performs well.

Can you elaborate on what use case are you implementing that would require fuzzy search by username?

@sesposito I might need something like this in the near future but for me example and use case would be:

  • Give an option for user to enter any desired displayName but that displayName must be unique on the server.
  • A slight variation with given subset of characters are available…

Another use case is suggest friend system like for instance have coin master or idle heroes.
Or even search friend by displayName.

Exactly, I’m making a friend system so that’s the problem to find it if or if I should put the name exactly with the exact characters, the system is fine but it lacks to be a 100% good system

im agree with you bro

The username in Nakama is guaranteed to be unique, displayName exists to optionally allow users to display a different nickname which does not require to be unique.

If it has to be unique, then you should use usernames. You do not need fuzzy search to provide suggestions for unused usernames.

Friend suggestions are usually done by account linking with third party providers such as Facebook, or by using Storage Search to give suggestions based on some criteria (e.g.: player level). Alternatively, you can suggest random users with usersGetRandom.

While it could provide a better user experience, the reality is that a user not being able to find their friend because the string is not an exact match should happen seldom and is not worth the support because of the performance implications. The db is not the best place for fuzzy-search in highly concurrent scenarios.

If this is really important to you, it’s easy to implement with a custom query and a custom index (not required, but highly recommended).

Yeah well aware of these scenarios :slight_smile: Just instead of username hassels down the road that can happen and then verification it is proven more easier to not mess around with it, with relog/re-session and just keep updating displaynames, at least in my case but this might not be the correct use case for displaynames/usernames.

UsersGetRandom can work for a while when i want to display suggested friends based on recent activity/level or some other factor and that is great choice :slight_smile:

We don;t want to go third party way with FB as it is not cross platform in terms it is not available everywhere, and more and more people are less using it. Since we are targeting different markets FB is out of question for us, thus getting friends through it is not possible, we can only use game server and its services for that functionallity.

So in the end that gives me at least 2 choices:

  • Search by direct user ID → with some fluff that would get discarded in custom rpc call so it can be fetched and somewhat secured to be shared.
  • Search by username + displayName.

here have the same username if a player find tiosam get 1 of them, that why I want it, I decide to edit all name if you join to my game put it upper if the name uppers is already registered so add some random number that is bad, too bad make it.

sorry idk too much about sql can you give a reference o somethings I can do it? I use getrandom but I must do it for a specific search that my game have.