简体   繁体   English

如何按任何字段搜索 Firebase 数据库?

[英]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_CarNumberSP_CarNumberFP_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.

相关问题 如何通过分页进行任何字段搜索 - How to search by any field with pagination 如何实现对Android Firebase数据库的搜索按钮? - How to implement search button to android Firebase database? 如何在 Firebase 云文档的字段中搜索多个值? - How to search for multiple values within a field of Firebase Cloud documents? Firebase 数据库:如何在不指定密钥的情况下搜索任何地方 - Firebase Database : How I can search anywhere without specifying the key 如何在Android上仅更新Firebase数据库上的特定字段 - How to update only specific field on Firebase Database on android Firebase数据库无此类实例字段错误 - Firebase Database No such instance field error 如何使应用程序接受输入字段中的任何语言并按原样存储在数据库中 - how make application accept any language in input field and store as it is in database 通过数据数据库实现搜索字段 - Implementation of the search field by data database Hibernate Search 3.1.1-如何以任意顺序在一个字段的同一短语中搜索多个单词 - Hibernate Search 3.1.1 - How to search multiple words in same phrase on a field in any order 如何使用ElasticSearch rest高级客户端按任意字段中的任何单词进行搜索? - How to search by any word in any field with ElasticSearch rest high-level client?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM