问题
i was planning to have a full text search feature for the String
name field of my document, but from the research i have done , it seems like searching text with firestore is not possible, then i come up with solution which is creating a new array field to store keyword in document, like this
and then i called it using arracVontains, with searchedKeyword as the inputted text from user
_firestore
.collection(itemOrderPath)
.where("keyword", arrayContains:searchedKeyword)
Now, i'm quite hesitant on wether it is okay to do it like this(will there be huge impact on my app)? or is there any better way to do this? Thank you!
回答1:
I was in the same position, before, I decided to go with the Full-text search using Algolia + Firestore
Few Risks with current flow:
- More manual work needed. Create / Update
- String data is case sensitive
- Here you are adding more weight to your document. It may affect the performance
- For single keyword search
array-contains
would be enough; However for multi keyword search you have to go witharray-contains-any
, but it has few limitations. - etc, etc
I tried the same solution that you are following now. However, due to few limitation, I picked up this Algolia
solution. For me, this solutions seems bit costly; however at initial stage we could manage this. But at the end, you have to decide based on your application's requirement.
Solution: https://firebase.google.com/docs/firestore/solutions/search
来源:https://stackoverflow.com/questions/65769237/firestore-text-search-containing-keyword-flutter