0

I am retrieving data from the Firebase Database using this:

[[[[_ref queryOrderedByChild:@"name"] queryStartingAtValue:@"Smith"] queryEndingAtValue:@"Smith\uf8ff"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {

and the result is all records starting with "Smith" the name field.

But I want to get all records where the name field has in any position "Smith". So I have tried this:

queryStartingAtValue:@"%Smith%"

with only the queryStartingAtValue i get back the records that has in any position in the name field "Smith" and after that all other records, as I haven't put in the queryEndingAtValue.

When adding this:

queryEndingAtValue:@"%Smith\uf8ff%"

it is strange, because I don't get any record.

Does anyone has found a solution for this?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 1
    I'm not sure what the `%` signs are meant to do, but Firebase's query language is not the same as SQL's `WHERE` clause. Can you remove the `%` signs and try again? – Frank van Puffelen Jul 01 '16 at 14:51
  • @Frank van Puffelen: removing the % works perfect, but only retrieves records where the field name begins with "Smith", it is not retrieving records where the name has for example "John Smith". – Dietmar Schwarz Webers Jul 01 '16 at 17:10
  • 1
    Firebase doesn't offer that kind of query - you can't directly query for a sub-string within a string. However, there are alternatives posted here on stackoverfllow. Here's one with a different question but the answer is relevant [real time searching](http://stackoverflow.com/questions/36870425/swift-how-can-i-use-shouldchangetextinrange-with-firebase-for-real-time-sear/36872475#36872475) and [searching](http://stackoverflow.com/questions/10559191/firebase-and-indexing-search) and [searching](http://stackoverflow.com/questions/28589092/firebase-query-find-item-with-child-that-contains-string) – Jay Jul 01 '16 at 17:19

0 Answers0