2017-02-18 21 views
1

当我需要应用查询时,我遇到了firebase的问题。firebase indexin方法?错误在android

给我这样

错误信息使用未指定的指数。考虑加入“‘.indexOn’:‘用户名’”在书籍到您的安全和火力地堡数据库规则获得更好的性能

这是我的代码:

DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReferenceFromUrl("****/books"); 
    Query query = databaseReference.orderByChild("username").equalTo(true); 
    final FirebaseListAdapter<Books> firebaseListAdapter = new FirebaseListAdapter<Books>(this,Books.class,android.R.layout.two_line_list_item,query) { 
     @Override 
     protected void populateView(View v, Books model, int position) { 
      TextView textView1 = (TextView) v.findViewById(android.R.id.text1); 
      TextView textView2 = (TextView) v.findViewById(android.R.id.text2); 

      Typeface Myfont = Typeface.createFromAsset(getAssets(), "font/gernralfont.ttf"); 

      textView1.setTypeface(Myfont); 
      textView2.setTypeface(Myfont); 
      textView2.setTextSize(17); 
      textView2.setTextColor(Color.parseColor("#6eaafc")); 
      textView1.setTextColor(Color.parseColor("#4d70a0")); 
      textView1.setText("\n" + model.getUsername() +"\n"); 
      textView2.setText("-"+model.getBookhave()+ "\n"); 
     } 
    }; 


    hilist.setAdapter(firebaseListAdapter); 

我看了网上谈一些帖子'索引'与Firebase规则? 我不明白是什么意思?请帮我保存我的日子

回答

0

转到您项目的rules tab of the Firebase Database console

你会发现这样的:

{ 
    "rules": { 
    ".read": "auth != null", 
    ".write": "auth != null" 
    } 
} 

根据规则节点,添加一个孩子索引。因此,如果您从上面开始,它将变为:

{ 
    "rules": { 
    ".read": "auth != null", 
    ".write": "auth != null", 
    "Books": { 
     ".indexOn": "username" 
    } 
    } 
} 

然后发布您的规则。通过此指示,Firebase数据库服务器将为每本书的用户名创建一个索引。这允许它对服务器上的用户名执行查询。

+0

谢谢..现在工作100% –

相关问题