0
votes

Can I query multiple keywords in firestore? How I can match an array of keywords in firestore?

I have a collection of documents with a title, I want to query articles contains specific keywords.

Following is my document structure.

{
    "users": {
        "user_id_1": {
            "username": "user one",
            "profile_pic": "some_url",
                "articles": {
                    "article_id_1": {
                        "title": "Firebase is so cool",
                        "comments": {
                        "comment_id_1": "First comment",
                        "comment_id_2": "I like trains"
                        }
                    },
                    "article_id_2": {
                        "title": "Firestore rocks!",
                        "comments": {
                        "comment_id_1": "SQL it's better",
                        "comment_id_2": "Do you know the wae?"
                        }
                    },
                    "article_id_3": {
                        "title": "Firestore awesome",
                        "comments": {
                        "comment_id_1": "SQL it's better",
                        "comment_id_2": "Do you know the wae?"
                        }
                    },
                    "article_id_4": {
                        "title": "Firestore is easy",
                        "comments": {
                        "comment_id_1": "SQL it's better",
                        "comment_id_2": "Do you know the wae?"
                        }
                    }
            }
        }
    }
}

Here I want to search articles based on the following keywords.

["cool", "rocks", "Firestore is easy"]

I should get article_id_1, article_id_2 and article_id_4

Thanks.

1
You might want to edit your question to better illustrate the contents of your documents, as well as the kinds of queries you're expecting to perform against that data, with expected results. - Doug Stevenson
@DougStevenson - I have added the document structure. Thanks! - Unnikrishnan

1 Answers

3
votes

This is not possible with Firestore alone. It's not a text search engine. You will want to export your data to a text search engine such as Algolia in order to perform text searches that are not based on simple text equality. The documentation suggests this solution.