使用部分字符串匹配查询Firebase

时间:2017-09-28 04:09:16

标签: android firebase firebase-realtime-database

假设我有一个简单的firebase实时数据库结构,其中键为username,值为userid。现在我想通过userid搜索username。如果用户名匹配,这很容易。但如何获得部分匹配的答案。为了更清楚,如果我使用SQL编写它,它将类似于:

SELECT userid FROM tablename WHERE username LIKE 'abc%'

它会向userid username abc开始#include <iostream> #include <bits/stdc++.h> using namespace std; class Scooty { int cc ; string model, brand; bool goodBrands(); public: Scooty () : cc(0), model(""), brand("") { cout << "\n Enter the following scooty details: \n\n"; cout << "\n \t Brand: "; cin >> brand; transform(brand.begin(), brand.end(), brand.begin(), :: tolower); cout << "\n \t Model: "; cin >> model; transform(model.begin(), model.end(), model.begin(), :: tolower); cout << "\n \t CC: "; cin >> cc; } Scooty (Scooty &s) { if (brand == s.brand) cout << "You will get a discount!\n"; } void computeDataAndPrint (); }; bool Scooty :: goodBrands() { if (brand == "honda" || brand == "tvs" || brand == "yamaha") return true; return false; } void Scooty :: computeDataAndPrint () { if (cc > 109 && goodBrands()) cout << "\n Good Choice!\n"; else cout << "\n Its okay!\n"; } int main() { Scooty s; Scooty s1, s1(s) // This gives error s.computeDataAndPrint(); return 0; } 。 如何为firebase编写这种类型的查询?了解我在Android设备上使用它,可能有很多用户。

1 个答案:

答案 0 :(得分:3)

根据Java Admin的文档,您可以执行类似的操作,它也适用于Android

对于以abc开头的数据,

yourRef.orderByKey().startAt("abc").endAt("abc\uf8ff")

\ uf8ff位于Unicode中的大多数常规字符之后,因此查询应匹配以abc开头的所有值。

相关问题