9

What would be the best way to implement "Tag" feature with firebase database?

Assume that there are tens of millions of posts where each post can be tagged with a tag or multiple tags.

If I want to add a checkbox-like filter where viewers can select one or more tags to see posts that fall under all tags provided, can this be implemented in firebase datastore?

For instance, if a user selects the following 3 tags 'Drama', 'Love' and 'Horror', I want to return all posts which are tagged with at least these 3 tags.

It would be very easy to do this with relational datastore, but I wasn't sure if this can be done relatively easily in NoSQL (cloud datastore, firebase database) storage.

Community
  • 1
  • 1
user482594
  • 16,878
  • 21
  • 72
  • 108
  • @Jay How? Does Firebase real-time database support multi column query? Last time I checked, it only support running query against a single column. – user482594 Mar 16 '17 at 01:57
  • Firebase doesn't have columns, just parent nodes and child nodes. See this my answer to this question about [Complex Queries](http://stackoverflow.com/questions/42672790/firebase-for-complex-query-a-no-go/42701961#42701961) – Jay Mar 16 '17 at 19:46
  • @Jay Your solution will not work if there are many tags for instance, if there are 30 tags, there can be at 30! variations, which is just too many to cover. For instance, if 'tag#5' and 'tag#26' are selected out of 30 tags, how will search work with your solution? – user482594 Mar 17 '17 at 03:19
  • The solution still applies. A string of 30 fields such as *drama_love_horror...* is a tiny amount of data and works as well as a string of *drama*. If that string feels overwhelming, map it to something shorter; *drama = a, love = b, horror = c*. Now it's *a_b_c*. You could also nest functions to load all 'drama' and filter the rest in code. If you want to get crazy, add a third party search library like Elasticsearch. However, if the user is presented with an option to have 30 tags, you may want to reconsider how the data is being presented as that's a lot of tags for the user to select. – Jay Mar 17 '17 at 12:09
  • 1
    If we are storing index like 'drama_love_horror_comedy_60s_...', then when user wants to look up movies that are 'comedy' AND '60s', the index won't be able to support it. Basically, there has to be 2^n (where n is # of possible tag) index combinations. Luckily I found this article from google appengine website. It appears that google cloud datastore supports it. – user482594 Mar 18 '17 at 04:38

1 Answers1

0

It appears that firebase does not support this usecase yet, but google cloud datastore does.

https://cloud.google.com/appengine/articles/indexselection

The document goes in details about 'Exploding Search' and how google datastore's zigzag merge join algorithm solves this problem.

user482594
  • 16,878
  • 21
  • 72
  • 108