In the following code, 'question' is a string variable created by a users voice input. this question is compared with document IDs in my firebase cloud firestore.
public void setAnswer(String question){
FirebaseFirestore JLdatabase = FirebaseFirestore.getInstance();
DocumentReference docRef = JLdatabase.collection("Products").document(question);
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
textViewAnswer.setText(document.getString("location"));
} else {
textViewAnswer.setText("I can't help you with this yet");
}
} else {
textViewAnswer.setText("Oeps. Something went wrong");
}
}
});
If question is exactly equal to the document ID, it works, but most of the time something slightly different will be said. Now I want to check if there is a word/word combination in the question that's equal to one of my documents ID. Is this possible in Java? I couldn't find something like this on the web.
If there is a better way to solve a problem like this. I would like to here!