0

I try to filter the list for items that contain a certain text.

database:

{"123":{"cities":"sss"},"445":{"cities":"hello hi dd"}}

And I want to get the items that contains "hi" within the cities value:

{"445":{"cities":"hello hi dd"}}

I tryd this:

https://xxxxx.firebaseio.com/allitems.json?orderBy="cities"&startAt="hi"

But it's not working... It only shows the items that starts with "hi"...

thanks.

Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
red alert
  • 25
  • 4
  • I think there is no such a function. If that is the case you should get all the data from DB and filter with js. https://firebase.google.com/docs/reference/js/firebase.database.Query#methods firebase realtime database is very restrictive and it is designed to work fast. So they are not really flexible in terms of querying – canbax Nov 12 '19 at 10:28

1 Answers1

0

At the time of writing, there is no built-in full-text search capability in the Firebase Realtime Database.

The official Cloud Functions samples include an example of full-text search with the Algolia hosted search service.


Note that there is a workaround if you search for a string that starts with some specific characters (which is different than a string which contains some specific characters).

Have a look at the "Range Queries" section of the REST API documentation:

We can combine startAt and endAt to limit both ends of our query. The following example finds all dinosaurs whose name starts with the letter "b":

curl 'https://dinosaur-facts.firebaseio.com/dinosaurs.json?orderBy="$key"&startAt="b"&endAt="b\uf8ff"&print=pretty'

The \uf8ff 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.

So in your case you would do as follows:

https://xxxxx.firebaseio.com/allitems.json?orderBy="cities"&startAt="hi"&endAt="hi\uf8ff"
Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121