我正在尝试从firebase查询用户名,它没有获取查询,我得到这个日志有没有人知道这意味着什么?
使用未指定的索引。考虑添加“.indexOn”: / contacts / users对您的安全性的“contacts / t25ha71bw0gRIU9HRhY2ecGSAS03” 提高绩效的规则
Firebase规则
{
"rules": {
".read": "(auth != null)",
".write": "(auth != null)",
"location":{
"$uid": {
".indexOn": ["lat","long"]
}
},
"events": {
"$uid": {
".read": "(auth != null) && !data.child('deleted').exists()",
".write": "(auth != null)",
".indexOn": ["name", "owner"]
}
},
"groups": {
"$uid": {
".read": "(auth != null) && !data.child('deleted').exists()",
".indexOn": ["name", "members", "owner"]
}
},
"users": {
"$uid": {
".read": "(auth != null) && !data.child('deleted').exists()",
"contacts" : {
".indexOn": ".value"
},
".indexOn": ["username"]
}
}
}
}
搜索查询
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
updateSearchResult(text: searchText)
guard !searchText.isEmpty else { return }
DispatchQueue.global(qos: .userInteractive).asyncAfter(deadline: DispatchTime.now() + .seconds(1)) {
if self.contactType == .contact {
AppFirRef.userRef.queryOrdered(byChild:"username")
.queryStarting(atValue: searchText)
.queryEnding(atValue: searchText+"\\uf8ff")
.observeSingleEvent(of: .value, with: { (snapshot) in
var contacts = Set<LAContact>()
for case let snap as FIRDataSnapshot in snapshot.children {
guard let value = snap.value as? [String : Any] else { continue }
let item = LAContact(value: value)
contacts.insert(item)
}
let filteredItems = self.filteredItems as! [LAContact]
let filtereSet = contacts.union(filteredItems)
self.filteredItems = Array(filtereSet)
self.tableView.reloadData()
})
}
}
}
AppFirRef
final class AppFirRef {
static let baseRef = FIRDatabase.database().reference()
static var currentUserRef: FIRDatabaseReference! {
guard let user = FIRAuth.auth()?.currentUser else { return nil }
return userRef.child(user.uid)
}
static var userRef = baseRef.child("users")
static var eventRef = baseRef.child("events")
static var groupRef = baseRef.child("groups")
static var messageRef = baseRef.child("messages")
}