Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从“获取文档”;Firestore“;在android中使用复合查询_Android_Firebase_Indexing_Google Cloud Firestore - Fatal编程技术网

如何从“获取文档”;Firestore“;在android中使用复合查询

如何从“获取文档”;Firestore“;在android中使用复合查询,android,firebase,indexing,google-cloud-firestore,Android,Firebase,Indexing,Google Cloud Firestore,我已经为我的应用程序中的所有下拉微调器构建了这样一个firebase查询 实际上,我的android应用程序中有20多个微调器,可以根据选择的任何下拉列表搜索firebase firestore集合中的用户。目前,我使用if-else条件处理了所有可能的场景,并基于任何选定的微调器进行复合查询。但这不是我目前正在使用的一种好方法。我需要在任何查询旁边追加查询,而不处理任何微调器检查..她是我的代码 Query query; CollectionReference collection = fi

我已经为我的应用程序中的所有下拉微调器构建了这样一个firebase查询

实际上,我的android应用程序中有20多个微调器,可以根据选择的任何下拉列表搜索firebase firestore集合中的用户。目前,我使用if-else条件处理了所有可能的场景,并基于任何选定的微调器进行复合查询。但这不是我目前正在使用的一种好方法。我需要在任何查询旁边追加查询,而不处理任何微调器检查..她是我的代码

Query query;
CollectionReference collection = 
firestore.collection(Constants.MEMBERS);
query  = collection;

if (rangeBarRating.getRightIndex() != 0 && spinnerReligion.getSelectedItemPosition() != 0){
        query =  collection.whereEqualTo(Constants.RELIGION,spinnerReligion.getSelectedItem()).whereEqualTo(Constants.REGISTERATION_STATUS,rangeBarRating.getRightIndex());
    } else if (spinnerCountry.getSelectedItemPosition() != 0){
        query =  collection.whereEqualTo(Constants.COUNTRY_LIVING_IN,spinnerCountry.getSelectedItem());
    }else if (rangeBarRating.getRightIndex() != 0){
        query =  collection.whereEqualTo(Constants.REGISTERATION_STATUS,rangeBarRating.getRightIndex());
    }else if ((rangeBarAge.getLeftIndex()+18) > 18){
        query =  collection.whereGreaterThanOrEqualTo(Constants.AGE,(rangeBarAge.getLeftIndex()+18));
    }

我需要动态的方法,就像我只使用if语句而不是if-else一样。如果选择了某个微调器,则在“我的查询”中附加该微调器值并获得所需结果。

您在分配条件查询时犯了一个小错误。您希望将每个条件添加到现有查询中,但事实上,您一直在从集合重建新查询。要解决此问题,请在每次添加条件时从
query
生成:

firestore.collection(Constants.MEMBERS);
query = collection;

if (rangeBarRating.getRightIndex() != 0 && spinnerReligion.getSelectedItemPosition() != 0){
    query =  query.whereEqualTo(Constants.RELIGION,spinnerReligion.getSelectedItem()).whereEqualTo(Constants.REGISTERATION_STATUS,rangeBarRating.getRightIndex());
} else if (spinnerCountry.getSelectedItemPosition() != 0){
    query =  query.whereEqualTo(Constants.COUNTRY_LIVING_IN,spinnerCountry.getSelectedItem());
}else if (rangeBarRating.getRightIndex() != 0){
    query =  query.whereEqualTo(Constants.REGISTERATION_STATUS,rangeBarRating.getRightIndex());
}else if ((rangeBarAge.getLeftIndex()+18) > 18){
    query =  query.whereGreaterThanOrEqualTo(Constants.AGE,(rangeBarAge.getLeftIndex()+18));
}

所以你想要通配符之类的东西?我不知道你说的“在任何查询旁边追加查询”是什么意思。你想对你的查询应用多个过滤器吗?@AlexMamo我不知道Firebase中的通配符是什么。。兄弟,实际上,如果(选择了微调器一)query=collection.whereEqualTo(Constants.religure,spinnerReligure.getSelectedItem()),我想要这样的东西
;如果选择了(微调器2),则{类似于此查询的内容=collection.append next where子句到collection}
@DougStevenson yes。我需要在我的收藏中应用多个筛选器进行搜索。。我的应用程序中有25个以上的微调器。用户可以选择任何他想要搜索的微调器,也可以根据他的搜索选择多个微调器criteria@YasirAli因此,您有一个基于的查询,并且根据微调器中选择的数据,您希望添加更多的
whereEqualTo
调用到您的查询,我理解对了吗?谢谢Puff,这正是我想要的。你为我节省了很多时间,还有额外的检查。。