2016-11-04 119 views
0

我尝试为酒店预订创建ios应用程序。我所有的数据都存储在firebase中。我的酒店名称和位置存储在“HotelLocation”表中。如何使用复杂查询从Firebase检索数据?

{ 
"HotelLocation": { 
    "H1": { 
     "name": "Ghetu hotel", 
     "location": "shonargao,dhaka" 
    }, 
    "H2": { 
     "name": "BB hotel", 
     "location": "gulshan,dhaka" 
    }, 
    "H3": { 
     "name": "Shuvashish hotel", 
     "location": "uttara,dhaka" 
    }, 
    "H4": { 
     "name": "Bodi hotel", 
     "location": "uttara,dhaka" 
    } 
    } 
} 

这是表“HotelLocation”我的JSON格式,但我无法从该表中检索数据仅用于“郁多罗”,即如果我搜索郁多罗那我应该得到

  1. Shuvashish酒店

  2. 博迪酒店

我尝试用“queryEqualToValu e',但问题在于'uttara,dhaka',因为firebase区分大小写。所以'dhaka'正在造成问题。

有没有在Firebase中使用SQL命令“%LIKE%”的方法?

+0

Firebase没有通配符文本搜索操作。请参阅http://stackoverflow.com/questions/22506531/how-to-perform-sql-like-operation-on-firebase,http://stackoverflow.com/questions/39058119/firebase-database-requests-and-queries -like-sql-where-in和http://stackoverflow.com/questions/31036903/how-can-i-achieve-this-many-to-many-relationship-in-firebase –

回答

1

如果使用queryStartingAt(“uttara”)和queryEndingAt(“uttara”),它将返回所需的节点。

你只是无法对通配符字符进行精确搜索。

有一堆其他的方法来解决这个喜欢......

创建引用这样的酒店的位置的节点,那么你可以只读取该节点和你的列表酒店

uttara 
    H3: true 
    H4: true 

或者另一种选择是创建于位置的引用 - 假设Shuvashish酒店拥有两个郁多地点以及shonargao。深层查询Hotels节点的位置/ L1 = true会返回H3

locations 
    L1: "uttara" 
    L2: "gulshan" 
    L3: "shonargao" 


Hotels 
    H2 
     "name:": "BB hotel" 
     "locations" 
      L2: true 
    H3 
     "name": "Shuvashish hotel", 
     "locations" 
      L1: true 
      L3: true