DatabaseReference databaseReference=mDatabase;
String queryText="Hotel";
databaseReference.orderByChild("Coupon")
.startAt(queryText)
.endAt(queryText+"\uf8ff");
Here I attached the code which I used to get child names of "Coupon" when I entered the "Hotel" query under the Coupon.But I got blank.I supposed to get Hotel1,Hotel2 object.I'm new to firebase.So hope your support .Thanks in advance.
最佳答案
在网络版本中,他们使用称为 ElasticSearch 的东西,您可以尝试在此处阅读更多内容:https://firebase.googleblog.com/2014/01/queries-part-2-advanced-searches-with.html
但是对于 Android,我认为没有任何功能可以执行这样的搜索。我要做的就是查询所有记录,然后自己过滤它们:
DatabaseReference databaseReference = mDatabase;
mDatabase.addValueEventListener(new ValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot val : dataSnapshot.getChildren()){
//I am not sure what record are you specifically looking for
//This is if you are getting the Key which is the record ID for your Coupon Object
if(val.getKey().contains("Hotel")){
//Do what you want with the record
}
//This is if your are querying for the hotel child
if(val.child("hotel").getValue(String.class).contains("Hotel")){
//Do what you want with the record
}
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
}
关于android - 如何在 firebase Android 中搜索 Child 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43511467/