[英]How to search Firebase database by any field?
Is there any way I could search by any Reatime Firebase Database field?有什么办法可以通过任何实时 Firebase 数据库字段进行搜索? Right now I know how to search by FP_CarNumber, but I would like to search by others as well like SP_CarNumber
or SP_CarNumber
and FP_CarNumber
at the same time.现在我知道如何通过 FP_CarNumber 进行搜索,但我想同时通过其他人进行搜索,例如SP_CarNumber
或SP_CarNumber
和FP_CarNumber
。
private void txtSearch(String str){
FirebaseRecyclerOptions<MainModel> options =
new FirebaseRecyclerOptions.Builder<MainModel>()
.setQuery(FirebaseDatabase.getInstance().getReference().child("Declaration_Data").child(currentuser).child("Declarations").orderByChild("FP_CarNumber").startAt(str).endAt(str + "\uf8ff"), MainModel.class)
.build();
mainAdapter = new MainAdapter(options);
mainAdapter.startListening();
recyclerView.setAdapter(mainAdapter);
}
The Realtime Database only supports queries on single field property.实时数据库仅支持对单个字段属性的查询。 I have explained in one o my answers:我在一个 o 我的答案中解释了:
How to solve such a situation by creating an extra field to keep the other values.如何通过创建一个额外的字段来保留其他值来解决这种情况。 Unfortunately, that workaround doesn't apply to all situations.不幸的是,该解决方法并不适用于所有情况。
Besides that, as far as I know, there is no library that does that automatically in Android.除此之外,据我所知,Android 中没有自动执行此操作的库。 However, there is one for the web, written by David East called Querybase .但是,有一个用于 Web 的,由 David East 编写,称为Querybase 。
So unlike in the Realtime Database, Cloud Firestore allows compound queries .因此,与实时数据库不同, Cloud Firestore允许复合查询。 So I recommend you try that.所以我建议你试试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.