Query Document Based on Regex in Firestore [duplicate]

被刻印的时光 ゝ 提交于 2020-11-29 09:45:05

问题


I want to query a document in Firestore using a regex. This is because in order to add a search functionality into my Flutter app, I need to be able to create a query based on the search. For example if the user types: 'alice' -- I would have a regex that would look like (?i)alice and I would query firestore for any documents that the name field meets this regex, whether it be Alice, Alice Doe, or Doe Alice. I'm looking for a query that would look something like this:

Firestore.instance.collection('people')
  .where('name', matchesRegex: '(?i)alice')

Thanks for any help. I feel like this is a pretty basic feature but I can't find it any where in the docs. And I really can't get all of the documents and search based off of that because the collection is very large, and I don't want to read that many documents.


回答1:


Firestore does not offer any regular expression in queries. Those types of queries do not scale in the way that Firestore requires. It only supports exact string matches, and range queries with string prefixes.

If you need more flexible text-based queries, consider mirroring your data to a text search engine, such as Algola, as describe in the documentation.



来源:https://stackoverflow.com/questions/61602779/query-document-based-on-regex-in-firestore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!