I am porting an app over from Parse to Firebase and I used to be able to query using matchesRegex
and putting the search into "(?i)\(searchBar.text!)"
. By doing this, the user could search "p" and the database would return (for example) "person", "People", "pot", etc.
I can't seem to find a way to query like this using Firebase that allows a user to search part of a String and Firebase looks for the substring within the database.
I am using:
databaseReference.child("Schools").queryOrderedByKey().queryEqualToValue("(?i)\(searchBar.text!)").observeSingleEventOfType(.Value, withBlock: { (snapshot) in
for childSnapshot in snapshot.children {
print("SANP \(childSnapshot)")
}
}) { (error) in
print(error)
}
If I do this, nothing is printed. I know the code above works if I search for a specific value that is character-for-character the same as it is in the database.
How can I search using parts of a String within the Firebase database?