This is the structure of my firebase
I want the user to write a name of the monument and check if the name exists, in the child "France" and "English", can you help?
Example: I write "tower" and the result is "tower bridge" and "tower eiffel"
locaisRef = ConfiguracaoFirebase.getFirebaseDatabase().child("English language");
searchViewPesquisaInicial.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
return view;
method
Query query = locaisRef.orderByChild("name")
.startAt(text)
.endAt(text + "\uf8ff");
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
list.clear()
for (DataSnapshot ds : dataSnapshot.getChildren()) {
list.add(ds.getValue(Locais.class));
}
seachAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
For this type of operations cloud firestore allows simpler queries than realtime database, since it allows collection groups:
Query query = db.collectionGroup("landmarks").orderBy("name").startAt(text).endAt(text + "~");
ATTENTION: Each collection group requires an index. If you haven't created one manually, the first time you run the query it will throw an exception containing a link. The link can be used to create an index. When the index is created the query will work properly
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.