2

I am trying to query the firestore database to find documents with attribute string that "contains" the given keyword.

For instance, if I have the keyword an, I want documents with attribute value such as "and", "ande", "any" to show up.

However, the Firestore doc only states that there's only equalTo and greater and less than operations.

How can I accomplish this feat?

Seongmin Choo
  • 1,653
  • 3
  • 10
  • 14
  • Maybe this post could help: https://stackoverflow.com/questions/46568142/google-firestore-query-on-substring-of-a-property-value-text-search – Paulo Jul 06 '18 at 09:04
  • While this is a duplicate question which has been asked many times, the *answer* linked to the duplicate isn't really a good answer the question (IMO). I believe you are asking how to perform a substring search e.g. your database includes three words *past, stay and dude* and you want to find all nodes that contain the substring *st*, which in this example would be past and stay. That accepted answer would not work as is. It would only work with pre-defined combinations of each word; p, pa, pas, a, as, ast, s, st etc. @frankvanpuffelen may have more insight. However... – Jay Jul 07 '18 at 13:29
  • Thanks for the additions Jay. I was indeed looking for a different/better answer on *contains* queries. Do you have better one? – Frank van Puffelen Jul 07 '18 at 13:39
  • ... Using an external source to search your substrings is spot on. [Algolia](https://firebase.google.com/docs/firestore/solutions/search) or something like ElasticSearch is the way to go. If you have limited data, the other option is to load your data and search in code, or limit the amount of data and search in code. I think this question/answer is more relevant [Firestore Query Across Multiple Fields for Same Value](https://stackoverflow.com/questions/49141813/firestore-query-across-multiple-fields-for-same-value/49142172#49142172). so the answer is no but there are alternatives – Jay Jul 07 '18 at 13:40
  • @FrankvanPuffelen I don't really have any other solutions other than brute force methods which are generally not practical for large amounts of data. I provided a couple of Firebase *Database* solutions such as [Firebase Swift querying for symbols](https://stackoverflow.com/questions/46851926/firebase-swift-querying-for-symbols/46863764#46863764) and [text search](https://stackoverflow.com/questions/36870425/swift-how-can-i-use-shouldchangetextinrange-with-firebase-for-real-time-sear/36872475#36872475). It's Database but the concept is similar. – Jay Jul 07 '18 at 13:46
  • Yeah, I remember that last one. Build an entire tree like that in Firebase is impressive. I'd definitely consider it an exercise that's more fun than pragmatic. :-) – Frank van Puffelen Jul 07 '18 at 16:07

0 Answers0