3

I'm moving my project over to Firebase from Swift. Firebase user's don't have usernames but I'm allowing them to save a display name which works more like a attribute than an actual object. How can I get users to query for other users/"friends" using case in sensitive text?

Charles Jr
  • 8,333
  • 15
  • 53
  • 74
  • Firebase doesn't have built-in full-text search capabilities. See http://stackoverflow.com/questions/17853908/how-to-keep-firebase-in-sync-with-another-database, http://stackoverflow.com/questions/33867185/searching-in-firebase-without-server-side-code, http://stackoverflow.com/questions/10559191/firebase-and-indexing-search and https://www.firebase.com/blog/2014-01-02-queries-part-two.html – Frank van Puffelen Feb 11 '16 at 00:40
  • You can't move a project from Swift, a programming language to Firebase, a JSON data store, unless you are referring to how your data is stored (MySQL? CoreData?). – Jay Feb 11 '16 at 22:01
  • I'm sorry, Yes I'm moving to Firebase from Parse using Swift programming. If you're the same user that supplied the below answer - It works fine. – Charles Jr Feb 13 '16 at 21:04

1 Answers1

4

You can easily accomplish this task. We don't know how your current data is structured but here's an example

users
  user_id_0
    dsplay_name: "Smokey"
    lower_case_name: "smokey"
  user_id_1
    display_name: "Bandit"
    lower_case_name: "bandit"

When you create a user in Firebase, create a node in the /users node with their uid as the node name, and then display_name and lower_case_name as children

When you write your data to the users node, just lower case the display name when you are writing to the lower_case_name child:

let lowerCaseString = displayNameString.lowercaseString
let userRef = the users uid

let userData = ["display_name": "Bandit", "lower_case_name": lowerCaseString]
userRef.setValue(userData)

Then you query on the lower_case_name child using a lower case string.

ref.queryOrderedByChild("lower_case_name").queryEqualToValue("bandit")
   .observeEventType(.ChildAdded, withBlock: { snapshot in
}
Jay
  • 34,438
  • 18
  • 52
  • 81