如何在Firebase数据库中搜索

时间:2018-10-09 23:07:13

标签: c# firebase search firebase-realtime-database

如何在不使用弹性搜索的情况下使用Firebase数据库统一搜索用户?

因此,我找到了这个Tutorial,这对我在Android Studio上有所帮助,我想知道如何为Unity复制此内容?

(我的可怕尝试)

public void SearchUser()
{
    FirebaseDatabase.DefaultInstance.RootReference.Child("user_id").OrderByChild("username").StartAt(searchField.text).EndAt(searchField.text + "\uf8ff")
          .GetValueAsync().ContinueWith(task => {
    if (task.IsFaulted) {
      // Handle the error...
    }
    else if (task.IsCompleted) {
      DataSnapshot snapshot = task.Result;
                  // Do something with snapshot...
                  Debug.Log("Found " +snapshot.Value.ToString());
    }
  });

}

1 个答案:

答案 0 :(得分:1)

我不是专家,但我一直在关注本文档(https://firebase.google.com/docs/database/unity/retrieve-data

FirebaseDatabase.DefaultInstance
    .GetReference("users").OrderByChild("username").EqualTo(searchusername)
    .ValueChanged += HandleValueChanged;
}

void HandleValueChanged(object sender, ValueChangedEventArgs args) {
  if (args.DatabaseError != null) {
    Debug.LogError(args.DatabaseError.Message);
    return;
  }
  // Do something with the data in args.Snapshot
}

我认为您需要在某个地方EqualTo(searchusername)