2

I'll preface this by including existing (and useful) firebase data structure references:

https://www.firebase.com/blog/2013-04-12-denormalizing-is-normal.html

What's the best way of structuring data on firebase?

Firebase data structure and url

However, what I'm looking for is something more synonymous with MySQL's WHERE LIKE, i.e. the ability to return records that include a given substring.

Specifically, I want to provide users with a way to search all (public) users of an app (by username / name / email / phone / all of these).

I don't want to download all users and then use angular filters / alternative client side filtering, as this could become a large download as the user base scales (especially if the search is across multiple collections - e.g. username, name, email etc.)

I've considered using a tree structure, for example:

- users
   - username
      - a
         - an
            - and
              - andy
              - andr
                - andre
                  - andrea
                  - andrew
         - ann
            - anne

Then I could reference users/username/a when a user types in 'a', users/username/a/an for 'an' etc. and effectively only reference a subset of the users based on the search term.

Considering the NoSQL nature, along with the advice to denormalise data and keep the structure flat, does this structure make sense?

Or, is there an alternative / better way to do a LIKE esque query?

Gastón Saillén
  • 12,319
  • 5
  • 67
  • 77
andrewd
  • 33
  • 3
  • Update: according to this firebase post https://www.firebase.com/blog/2014-01-02-queries-part-two.html it seems the best current solution is by using elasticSearch http://www.elasticsearch.org/ on your server – andrewd Jul 30 '14 at 08:04
  • Firebase supports filtering data by *name* by *priority*. As soon as you need more than that, you'll need to create an "index" node somewhere else in your Firebase, where you store references to the data under a different *name* or *priority*. In the blog post you refer to, Elastic Search is used to automatically create and maintain such indices. – Frank van Puffelen Jul 30 '14 at 10:56
  • See also [this search algorithm post](http://stackoverflow.com/questions/25034860/firebase-how-to-match-opponents-in-a-game/25039133#25039133) – Kato Jul 30 '14 at 15:41
  • Thanks - ended up following firebase.com/blog/2014-01-02-queries-part-two.html which works well. – andrewd Sep 12 '14 at 06:13

0 Answers0