如何在我的 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/