Is there a way to search sub string at Firestore?

前端 未结 1 1895
遥遥无期
遥遥无期 2020-11-28 16:13

If there is a String named \'California\' at firestore database and i want to search from android app as \'Cali\' then the firebase should

相关标签:
1条回答
  • 2020-11-28 16:52

    Unfortunately, there is no query in Firestore that looks like this:

    db.collection("cities").whereContains("name", "Cali")
    

    But for small datasets, there is a workaround that can help you solve this, which is by querying the database to get all city names and use contains() method like this:

    String str1 = document.getString("yourProperty");
    String str2 = "Cali";
    boolean b = str1.toLowerCase().contains(str2.toLowerCase());
    

    If you'll try to print the value of b, you'll see that is true. But the above examples works well enough only for small datasets, it doesn't work for large datasets and this is because downloading an entire collection to search for fields client-side isn't practical. In this case, as the official documentation recommends:

    To enable full text search of your Cloud Firestore data, use a third-party search service like Algolia.

    For a concrete example, please also see my answer from this post.

    0 讨论(0)
提交回复
热议问题