android - 选择文档字段包含 Firestore 中的字符串的位置?

标签 android firebase google-cloud-firestore

如何在我的 Firestore 中选择一个字段值包含“pp”的文档; 如何在 firestore 中添加 whereContains("title","pp") 之类的选项? firestore 添加了多个 where cause 但我们还需要“包含” 以改进搜索。是否有任何替代方法可用或 firestore 开发人员忽略它?

FirebaseFirestore db2 = FirebaseFirestore.getInstance();
            db2.collection("products")
                    .whereEqualTo("cat","fruits")
                    .whereEqualTo("subcat","apple")
                    .whereEqualTo("blocked",false)
                    .whereContains("title","pp")
                    .get()


                    .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                        @Override
                        public void onComplete(@NonNull Task<QuerySnapshot> task) {
                            if (task.isSuccessful()) {
                                for(int i=0;i<task.getResult().size();i++){
                                    Product product=task.getResult().getDocuments().get(i).toObject(Product.class);
                                    Log.d(TAG+"2", product.getTitle()+"");
                                }
                                for (QueryDocumentSnapshot document : task.getResult()) {
                                  //  Log.d(TAG+"2", document.getId() + " => " + document.getData());

                                }
                            } else {
                                Log.w(TAG+"2", "Error getting documents.", task.getException());
                            }
                        }
                    });

最佳答案

Firestore 没有按子字符串搜索的方法。您的选择是 mirror your data to a full text search engine例如 Algolia,要巧妙地构建数据以支持类似于子字符串搜索的特定类型的查询,或 file a feature request .

关于android - 选择文档字段包含 Firestore 中的字符串的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50433447/

相关文章:

java - 按返回键返回第一个 fragment

android - Google登录对话框关闭android studio后屏幕闪烁

java - 为什么回收站 View 不显示任何错误为 : E/RecyclerView: No adapter attached; skipping layout 的帖子

firebase - 如何按 '_createTime' 对 Firestore 文档进行排序?

android - Firebase Cloud Firestore 在插入时卡住应用程序

android - 使用嵌套选择 Android SQLite 的复杂更新查询

android - 如何在Android中获取 map 上的经纬度?

android - flutter 正在更新而不使用 setState

android - 无法解析 : com. google.firebase :firebase-core:11. 0.0

java - Firebase Auth有点dubbio