选择文档字段包含Firestore中的字符串的位置吗? [英] SELECT where document field contains the string in Firestore?
问题描述
如何在我的Firestore中选择一个文档,其中字段的值包含'pp';如何在firestore中添加 whereContains("title","pp")
这样的选项?firestore在原因中添加了多个,但我们也需要包含"改善搜索.有没有其他可用的方法,或者Firestore开发人员忽略了它?
How can I select a document in my Firestore where the value of a field contains 'pp' ;
How to add option like whereContains("title","pp")
in firestore ?
firestore added multiple where cause but we need "contains" also
to improve search. Is there any alternate method available or firestore developers ignore it?
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无法通过子字符串进行搜索.您可以选择将您的数据镜像到全文搜索引擎,例如Algolia,请聪明地了解如何构造数据以支持类似于子字符串搜索的特定类型的查询,或者提交功能请求.
Firestore has no method to search by substring. Your options are to mirror your data to a full text search engine such as Algolia, be clever about how you structure your data to support the specific kinds of queries that are similar to a substring search, or file a feature request.
这篇关于选择文档字段包含Firestore中的字符串的位置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!