Given Firebase is case-sensitive, how to handle user @mentions

6,156 views
Skip to first unread message

David Notik

unread,
Nov 14, 2014, 1:57:36 AM11/14/14
to fireba...@googlegroups.com
Ok, so Firebase is case-sensitive so if you're users/Kai is not same as users/kai. If I have an @kai it won't find you... I'm not sure best way around it except to force lowercasing of all usernames (at least in the Firebase location, and I can keep the correct case in a key/value)? Ideas?

Thanks!

--D

David Notik

unread,
Nov 14, 2014, 2:06:09 AM11/14/14
to fireba...@googlegroups.com
I can just store an index. lowercase_users_index -> points to proper user. It's another hop but I guess best approach? Doesn't look like there's a way to query case-insensitively.

--D

Beni Cherniavsky-Paskin

unread,
Nov 14, 2014, 5:03:27 AM11/14/14
to fireba...@googlegroups.com

With the new query support, you could store lowercased name in a subkey (/users/Kai/case_folded_name == “kai”).
Then something like usersRef.orderByChild(“case_folded_name”).equalTo(“kai”) should give you the matching user(s).
Don’t forget .indexOn in rules to actually make the query efficient.

It’s becoming standard to offer autocompletion for user mentions. I think using startAt("kai").limit(10) instead of equalTo("kai") would easily support (somewhat dumb) prefix-based autocompletion (you just have to filter the results to those actually starting with “kai”).
But if you want to also complete based on full first/last names, or any substrings, and show the best N matches based on some metric (this matters if you want to already give relevant completions for @k or even @), it will require more work…

Caveats:

  • will you allow users to change their (nick)name? then you might have to structure around some persistent id that isn’t the username anyway.
  • if you allow both “KaI” and “kAi” as users, who does @kai refer to? Perhaps it’s simpler to force lowercase usernames but show user-chosen display name in UI. But then what do you do when a user accustomed to display names assumes that just typing @Display Name works (ignorign autocomplete’s offer of @username Display Name). SE has a complex DWIM algorithm, but I wouldn’t go there if I can avoid it…

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jacob Wenger

unread,
Nov 14, 2014, 12:43:18 PM11/14/14
to fireba...@googlegroups.com
Hey David,

First off, Beni is exactly correct (thanks Beni!) and I would follow his advice on this, with one change. I would just store all your keys names in lowercase. As Beni said, you cannot have different users "kai" and "Kai" and "kAi" since they all map to @kai. So just store your key names as lowercase, and then have a key called "username" which stores it in the case-sensitive way your user wants. Then, to query usernames, you can just do an orderByKey() instead of having to use orderByChild("case_folded_name").

Beni's solution works, but I think this is a bit more straightforward.

Jacob

David Notik

unread,
Nov 14, 2014, 1:50:12 PM11/14/14
to fireba...@googlegroups.com
Awesome answers. Thank you Beni and Jacob!

You received this message because you are subscribed to a topic in the Google Groups "Firebase Google Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebase-talk/IEQhQrMaGro/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebase-tal...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages