3

I am trying to query data on firebase to find a child with a value containing a portion of a string. So say the value is 'apple' if I search 'app' I would have that record returned. I realize this has been asked but the answers I have read all point to the fact that firebase will be integrating this feature....its almost 3 years later and I can't seem to find anything.

Sean Cook
  • 435
  • 7
  • 21
  • Also I am aware of searching by the starting value which would slove the above use case, but say the search term was 'ppl' and I wanted to return the 'apple' record – Sean Cook Jul 23 '16 at 06:27
  • 1
    Yes, this question has been asked before - here's some references. [searching](http://stackoverflow.com/questions/33867185/searching-in-firebase-without-server-side-code) and the classic [multiple where](http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase/26701282#26701282). And, as of yet, nothing has changed. However, there is an answer to your specific question. – Jay Jul 23 '16 at 12:46
  • Also, if you have more info it's probably better to refine the question than to add comments as that will help others who are searching for a similar topic. – Jay Jul 23 '16 at 12:54

1 Answers1

5

In your example...

If you are strictly querying for data that starts with a string, 'app' in this case, then that's easily done with:

queryStartingAtValue("app").queryEndingAtValue("app\u{f8ff}")

For more info, see the very well written but now legacy Firebase Guide To Retrieving Data

and scroll down to the Range Queries section

For completeness:

The f8ff character used in the query above is a very high code point in the Unicode range. Because it is after most regular characters in Unicode, the query matches all values that start with a b. (app in this case)

Jay
  • 34,438
  • 18
  • 52
  • 81