我在Firebase中保存以下数据:
我想在标题中找到所有有#Yahoo的记录.什么是确切的查询?
我对所创建的随机密钥感到困惑.我不知道如何处理这个,所以我发布在这里.
Firebase firebase = new Firebase(Constants.FIREBASE_URL_USER_TASKS).child(Utils.encodeEmail(unProcessedEmail)); Query queryRef = firebase.orderByKey().startAt("#" + mHashTag).endAt("#" + mHashTag + "\uf8ff"); queryRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { mTasksList.clear(); mAdapter.notifyDataSetChanged(); for (DataSnapshot task : dataSnapshot.getChildren()) { mTasksList.add(task.getValue(TaskModel.class)); } mAdapter.notifyItemRangeInserted(0,mTasksList.size()); mSwipeToRefresh.post(new Runnable() { @Override public void run() { mSwipeToRefresh.setRefreshing(false); } }); } @Override public void onCancelled(FirebaseError firebaseError) { mSwipeToRefresh.post(new Runnable() { @Override public void run() { mSwipeToRefresh.setRefreshing(false); } }); } });
解决方法
您无法搜索其标题包含#Yahoo的任何项目.看到:
How to perform sql “LIKE” operation on firebase?
How to perform sql “LIKE” operation on firebase?
Firebase firebase = new Firebase(Constants.FIREBASE_URL_USER_TASKS).child(Utils.encodeEmail(unProcessedEmail)); Query queryRef = firebase.orderByChild("title").startAt("#" + mHashTag)
为了使这项工作顺利进行,您必须添加一个index to your Firebase rules:
"rules": { "userTasks": { "$email": { ".indexOn": "title" // index tasks in their title property } } }