每个Firestore文档中都有两个数组。在我的应用程序中,你可以根据这些数组中的值进行搜索。如果我在基于所选选项创建的数组之间查找精确匹配,并在文档中像这样查找完全匹配,我就能够使我的搜索正常工作。
let _ = circleQuery.observe(.documentEntered, with: { (key, location) in
if let key = key {
Constants.firestore.collection("facilities").whereField("facility_type", isEqualTo: self.type!)
.whereField("insurance_accepted", isEqualTo: self.insurance!).getDocuments { (querySnapshot, error) in
if let err = error {
print(err.localizedDescription)
} else {
for document in (querySnapshot?.documents)! {
if document.documentID == key {
self.facilities?.append(document.data())
self.addFaciltiesToMap()
}
}
}
}
}
})
这基本上就是我要达到的目标。
for value in self.type! {
Constants.firestore.collection("facilities").whereField("facility_type", arrayContains: value).getDocuments { (querySnapshot, error) in
if let err = error {
print(err.localizedDescription)
} else {
for document in (querySnapshot?.documents)! {
if document.documentID == key {
self.facilities?.append(document.data())
}
}
}
}
}
for value in self.insurance! {
Constants.firestore.collection("facilities").whereField("insurance_accepted", arrayContains: value).getDocuments { (querySnapshot, error) in
if let err = error {
print(err.localizedDescription)
} else {
for document in (querySnapshot?.documents)! {
if document.documentID == key {
self.facilities?.append(document.data())
}
}
}
}
}