28

I am considering using Firebase for an application that should people to use full-text search over a collection of a few thousand objects. I like the idea of delivering a client-only application (not having to worry about hosting the data), but I am not sure how to handle search. The data will be static, so the indexing itself is not a big deal.

I assume I will need some additional service that runs queries and returns Firebase object handles. I can spin up such a service at some fixed location, but then I have to worry about its availability ad scalability. Although I don't expect too much traffic for this app, it can peak at a couple of thousand concurrent users.

Architectural thoughts?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Gene Golovchinsky
  • 6,101
  • 7
  • 53
  • 81

2 Answers2

30

Long-term, Firebase may have more advanced querying, so hopefully it'll support this sort of thing directly without you having to do anything special. Until then, you have a few options:

  1. Write server code to handle the searching. The easiest way would be to run some server code responsible for the indexing/searching, as you mentioned. Firebase has a Node.JS client, so that would be an easy way to interface the service into Firebase. All of the data transfer could still happen through Firebase, but you would write a Node.JS service that watches for client "search requests" at some designated location in Firebase and then "responds" by writing the result set back into Firebase, for the client to consume.
  2. Store the index in Firebase with clients automatically updating it. If you want to get really clever, you could try implementing a server-less scheme where clients automatically index their data as they write it... So the index for the full-text search would be stored in Firebase, and when a client writes a new item to the collection, it would be responsible for also updating the index appropriately. And to do a search, the client would directly consume the index to build the result set. This actually makes a lot of sense for simple cases where you want to index one field of a complex object stored in Firebase, but for full-text-search, this would probably be pretty gnarly. :-)
  3. Store the index in Firebase with server code updating it. You could try a hybrid approach where the index is stored in Firebase and is used directly by clients to do searches, but rather than have clients update the index, you'd have server code that updates the index whenever new items are added to the collection. This way, clients could still search for data when your server is down. They just might get stale results until your server catches up on the indexing.

Until Firebase has more advanced querying, #1 is probably your best bet if you're willing to run a little server code. :-)

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Michael Lehenbauer
  • 16,229
  • 1
  • 57
  • 59
  • 1
    Oops. Just re-read your comment that your data is static. In that case, option #2 isn't necessary and option #3 becomes easier. You still have to figure out how to build the full-text-search index, store it in Firebase, and have clients query it directly, but should be totally doable. – Michael Lehenbauer May 11 '12 at 23:28
  • Thanks for confirming that I wasn't missing something obvious. I think #1 is probably the right way to go -- re-implementing a full-text index in JavaScript doesn't seem like a good use of my time :-) – Gene Golovchinsky May 11 '12 at 23:37
  • Take a look at http://lunrjs.com/ for a complete JS based full-text indexing solution. – Nemo Oct 27 '13 at 15:21
  • is this still the state-of-the-art for firebase full text search? i.e. a serving interacting both with firebase and a search indexer (a la github.com/firebase/flashlight) – chris Nov 26 '14 at 18:10
  • 3
    For a nice implementation of #1, see https://github.com/firebase/flashlight It integrates with ElasticSearch to provide full-text search capabilities of Firebase data. – Michael Lehenbauer Nov 27 '14 at 05:46
  • @MichaelLehenbauer: how is the `Firebase will have more advanced querying, so hopefully it'll support this sort of thing directly without you having to do anything special.` going? Any advances on FTS in Firebase itself? – KarolDepka Jan 30 '17 at 22:25
  • Please @MichaelLehenbauer can u write an article on this .it is a much needed feature – suulisin Nov 20 '17 at 16:21
2

Google's current method to do full text search seems to be syncing with either Algolia or BigQuery with Cloud Functions for Firebase.

Here's Firebase's Algolia Full-text search integration example, and their BigQuery integration example that could be extended to support full search.

cgenco
  • 3,370
  • 2
  • 31
  • 36