I want to check if my users input contains a substring that is a document in my firestore database, is this possible in Java? (Android-studio)

Luciano Deben :

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!

Alex Mamo :

If a question is exactly equal to the document ID, it works

It works because you are pointing to the document that has that exact id.

Now I want to check if there is a word/word combination in the question that's equal to one of my documents ID.

Unfortunately, there is no way you can create a query to search for a substring in the document id. The only option that you have is to create a property of type String that can hold the question and perform a query using one of my solutions that can be found in my answer from the following post:

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=389318&siteId=1