【问题标题】:SELECT where document field contains the string in Firestore?选择其中文档字段包含 Firestore 中的字符串?
【发布时间】:2018-05-20 09:37:17
【问题描述】:

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

【问题讨论】:

  • 你可以看看here。

标签: android firebase google-cloud-firestore


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    相关资源
    最近更新 更多