【发布时间】:2019-02-20 15:36:24
【问题描述】:
我在 firebase 数据库中有数据,数据的结构如附图所示。当用户在应用程序中输入搜索查询时,我正在尝试使用搜索栏搜索食谱的名称。当前设置的索引规则也显示在附图中。这是我的代码:
self.findRecipes(text: "Lemon")
func findRecipes(text: String)->Void{
ref.child("Categories").queryOrdered(byChild: "recipeName").queryStarting(atValue: text).queryEnding(atValue: text+"\u{f8ff}").observe(.value, with: { snapshot in
print(snapshot)
})
}
控制台中的输出是
Snap (Categories) <null>
有什么帮助吗?
【问题讨论】:
-
你错过了一个关卡。 recipeName 节点不是 /Categories/ 子节点的子节点。它是 /Categories/Beverages/ 中子节点的子节点,因此您需要将 /Beverages/ (或 /Breakfast & Brunch)添加到 ref 路径以进行查询。如果您需要执行较浅的查询,请考虑将所有节点保留在父类别节点中,并添加一个子节点来定义它是什么类型 /Categories/childByAutoId/recipeName: "xxxx" 和另一个子节点/recipeType: "饮料"
标签: ios swift firebase search indexing