SELECT 哪个文档字段包含 Firestore 中的字符串?

Mid*_*laj 1 android firebase google-cloud-firestore

如何在 Firestore 中选择字段值包含 'pp' 的文档;如何像whereContains("title","pp")firestore 中一样添加选项?firestore 添加了多个 where 原因,但我们还需要“包含”来改进搜索。是否有任何替代方法可用或 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());
                            }
                        }
                    });
Run Code Online (Sandbox Code Playgroud)

Dou*_*son 5

Firestore 没有按子字符串搜索的方法。您的选择是将数据镜像到 Algolia 等全文搜索引擎,巧妙地构建数据以支持类似于子字符串搜索的特定类型的查询,或者提交功能请求