1

I am trying to search the user on the basis of name . It search perfectly if the name is given from first name but didn't search on the string the second name. Where first and second both are saved in one value separated by space for example "John Smith". If search on "john" or "jo" etc it retrieve the record but if its smith it retrieve nothing. Code

 var ref = firebase.database().ref().child('User').orderByChild("name").startAt(searchString).endAt(searchString + "\uf8ff");
    $scope.usercollection = $firebaseArray(ref);
Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
usman ali
  • 11
  • 1
  • 4
  • That is expected behavior: Firebase Database queries can only search from the start of the string. They cannot perform a `contains()` operator. See http://stackoverflow.com/questions/22506531/how-to-perform-sql-like-operation-on-firebase. Firebase also just released an integration with Cloud Functions, which allows you to perform such search indexing through Google infrastructure. See the search use-case here: https://firebase.google.com/docs/functions/use-cases#other_ways_to_integrate_with_third-party_services_and_apis – Frank van Puffelen Mar 22 '17 at 14:14

1 Answers1

4

With your query it is normal that you only get results starting with j, jo, joh, john, etc... The startAt method "creates a Query with the specified starting point". So it looks at how your searchString variable starts.

There is no full text search mechanism in Firebse for the moment. You will find on the web several possibilities to implement such a mechanism, e.g.:

https://firebase.googleblog.com/2014/01/queries-part-2-advanced-searches-with.html

https://github.com/FirebaseExtended/flashlight

ggDeGreat
  • 1,098
  • 1
  • 17
  • 33
Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121