Firebase 如何通过Flatter搜索firestore数据库中的多个字段

Firebase 如何通过Flatter搜索firestore数据库中的多个字段,firebase,flutter,search,google-cloud-firestore,Firebase,Flutter,Search,Google Cloud Firestore,我正在尝试构建一个搜索功能,其中在我的搜索字段中输入的文本是通过Firestore中的两个字段(profileName和username)进行搜索。例如,如果用户的档案名为“Sylvester Appiah”,用户名为“keeett”。然后,当搜索用户名或profileName时,它应该返回相同的用户。我不确定是否可以在.where()方法中使用profileName或username。感谢您的帮助 controlSearch(字符串搜索词){ FuturepUsers=用户参考 。其中(“pr

我正在尝试构建一个搜索功能,其中在我的搜索字段中输入的文本是通过Firestore中的两个字段(profileName和username)进行搜索。例如,如果用户的档案名为“Sylvester Appiah”,用户名为“keeett”。然后,当搜索用户名或profileName时,它应该返回相同的用户。我不确定是否可以在.where()方法中使用profileName或username。感谢您的帮助

controlSearch(字符串搜索词){
FuturepUsers=用户参考
。其中(“profileName”,大于或等于:searchWord)
.getDocuments();
设置状态(){
未来搜索结果=pUsers;
});
}

您不能将多个条件传递给
where()
。相反,您可以多次调用
where()
,将它们链接到所需的查询中:

usersReference
  .where("profileName",isGreaterThanOrEqualTo: searchWord)
  .where("username",isEqualTo: "QeustionableCoder")
  .getDocuments();
请注意,您可能需要为此类多字段查询定义索引。如果缺少索引,SDK将记录一条关于该索引的错误消息。在错误消息中查找URL,因为这是在正确字段上定义索引的最快方法