Firebase App Search Feature - Query Using String Regex

烂漫一生 提交于 2019-12-31 01:45:07

问题


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?

来源:https://stackoverflow.com/questions/39606627/firebase-app-search-feature-query-using-string-regex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!