问题描述
我正在开发一个应用程序,它将帮助用户搜索并下载已由其他用户作为帖子形式上传的图书.
I'm developing an app that will help the user to search the books and download them which have been uploaded by other users as a form of the post.
为了首先下载书籍,用户应根据标题"之类的属性进行搜索.
In order to download the books first, the user should search them owing to attribute such as Title.
满足用户要求的帖子应显示在 firebase-UI recyclerview中.
The posts which meet the requirement of the user should be displayed in the firebase-UI recyclerview.
这是我的Firebase数据结构:
This is my Firebase data structure:
我想要创建一个查询的示例代码,该查询将返回方便发布的ID,例如 ImgBRr2YFYfAu1WwENS1Ucj6jz13_1514813350760 .
I want the sample code that will create a Query which returns Id of convenient Posts such as ImgBRr2YFYfAu1WwENS1Ucj6jz13_1514813350760.
请帮助我解决问题,欢迎任何建议和想法
Please help me to solve the problem, any suggestions and ideas will be welcomed
推荐答案
这是您可以做的,
按语言搜索,然后按标题&过滤作者
For search by language and then filter by title & author
public void search(String languangeSearchString, String title, String author){
FirebaseDatabase.getInstance().getReference().child("Posts").equalTo("language").startAt(languangeSearchString).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String id = dataSnapshot.getKey();
if(dataSnapshot.child("title").exists() && dataSnapshot.child("author").exists()){
if(dataSnapshot.child("title").getValue(String.class).equals(title) && dataSnapshot.child("author").getValue(String.class).equals(author)){
//Here are the results
}
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
这篇关于Android-使用过滤进行Firebase搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!