使用字符串选择对象包含Firebase DB中的一些子字符串 [英] Select object with string contains some substrings from Firebase DB

查看:21
本文介绍了使用字符串选择对象包含Firebase DB中的一些子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Firebase数据库的结构为

I have firebase database with structure

现在,我只想选择具有给定性别和品质的名字.我写了这样的代码

Now I want to select only names with given gender and qualities. I wrote code like this

private NameImpl.Gender mGender;
private String[] mQualities;

...

public void GetNames()
{
    mRef.orderByChild("Gender").equalTo(mGender.name()).addValueEventListener(new ValueEventListener()
     {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            getData(dataSnapshot);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
     });
}

但是我不明白如何在此处添加要求数据库中的Qualities字符串必须包含来自mQualities的所有单词的要求.

But I can't understand how to add here requirement that Qualities string in database must contain all words from mQualities.

推荐答案

如果不对架构进行一些重大更改,则无法使用Firebase Realtime Database执行此操作.实时数据库不具备在多种条件下执行过滤的功能(有人用SQL术语说"multiple where子句").如果要检查多个项目的匹配项,则必须创建一个复合字段,其中包含要查找的内容的组合.例如,您将需要一个具有性别和所有性质以可预测方式串联在一起的字符串值,然后让客户搜索该字符串.

You can't do this with Firebase Realtime Database without some significant changes to your schema. Realtime Database doesn't have the capability to perform filtering on multiple conditions (some people say "multiple where clauses" in SQL terms). If you want to check for matches on multiple things, you'll have to create a composite field that contains a combination of the things you're looking for. For example, you'll need a string value that has gender and all the qualities concatenated together in predictable fashion, then have clients search for that string.

Firestore允许您在多种条件下进行过滤,但是仍然无法搜索对象集.您仍然需要一个特殊的字段,将所有质量连接在一起.

Firestore allows you to filter on multiple conditions, but you still can't search for sets of objects. You'll still need a special field that concatenates all the qualities together.

这篇关于使用字符串选择对象包含Firebase DB中的一些子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆