【发布时间】:2016-03-18 19:31:44
【问题描述】:
当我调用refreshResults("test") 时,仍会显示所有搜索结果,而不是在 Parse 的 business_name 列中仅包含“test”的搜索结果。我使用过滤器时打印的数组包含数据,但数据有误。
这样做的目的是进行简单的搜索 - 它是返回包含过滤器的所有结果。示例:搜索“face”将返回 face、facebook、face、faces 等,因为这些结果都包含过滤器“face”。我正在将过滤器与 business_name 字段进行比较,以查看是否有任何过滤器返回匹配项。
is_person 值始终为 false,因为我正在搜索企业而不是人员。
代码如下:
func refreshResults(strFilter: String) {
let progressIndicator = MBProgressHUD.showHUDAddedTo(self.view, animated: true)
progressIndicator.labelText = "Loading..."
resultsCompEmailArray.removeAll(keepCapacity: false)
resultsCompNameArray.removeAll(keepCapacity: false)
resultsCompProfilePicArray.removeAll(keepCapacity: false)
if (!strFilter.isEmpty) {
print("searching with filter: ", strFilter)
let q1 = PFQuery(className: "_User")
q1.whereKey("is_person", equalTo: false)
let q2 = PFQuery(className: "_User")
q2.whereKey("business_name", containsString: strFilter)
let otherQuery = PFQuery.orQueryWithSubqueries([q2, q1])
otherQuery.findObjectsInBackgroundWithBlock({ (objects: [PFObject]?, error:NSError?) -> Void in
MBProgressHUD.hideAllHUDsForView(self.view, animated: true)
if (error == nil) {
for obj in objects! {
self.resultsCompNameArray.append(obj.objectForKey("business_name") as! String)
self.resultsCompEmailArray.append(obj.objectForKey("username") as! String)
if let profilePic = obj.objectForKey("profile_picture") as? PFFile {
self.resultsCompProfilePicArray.append(profilePic)
}
self.resultsTable.reloadData()
print(self.resultsCompNameArray)
}
}
})
}
}
感谢任何有用的 cmets,将愚蠢留给其他人。谢谢。
【问题讨论】:
-
那么,你不想要
is_person=false没有过滤的business_name的数据,对吧? -
我需要搜索结果显示任何业务名称,只要它在搜索过滤器中。示例:搜索 fo 会返回 foo、foos、food、fodey,因为它们都包含 fo。 is_person 部分总是错误的,因为我在我的数据库中搜索企业而不是人员 - 这就是我将它们分开的方式。 -- 所有这些都非常类似于简单的谷歌搜索,所有包含搜索词的结果都会弹出。
标签: arrays swift search parse-platform filter