Search code examples
firebasegoogle-cloud-firestorealgoliafirebase-extensions

Search feature based on Algolia with localised data using Firestore


I have a mobile app, which uses Firestore as a remote database.

I'd like to add search feature into the app. I want to use https://extensions.dev/extensions/algolia/firestore-algolia-search as it seems to be easiest way.

Think of "categories" for example, array of strings. Texts are gonna be different for different languages.

How would you approach that on the database side so it works fine with search feature?

My assumption is that every record with "categories" should have localised fields so it's gonna be searchable regardless of the language. So something like "en-category", "de-category", "nl-category" on the Firestore side.

Is there a better way than mentioned above?


Solution

  • I use that Algolia extension to sync over the documents of a few key collections in my Firestore database, then use Algolia to search and filter lists of results. Recognize that Algolia results are the contents of the Documents that you synch'ed over from Firestore. You can display the Algolia results to your user rather than fetching the same data values from Firestore.

    So I use Algolia results to fill in my "list" screen. As we filter and search, we narrow the lists. When the user clicks an item to see the full details, it is in that Details screen that I fetch the actual document from Firestore, make edits to it, and submit back to Firestore.

    There are a few ways to deal with localization. One way is as you suggest: to put localized versions of the categories into the Documents themselves. Another way is to standardize the categories in one language, but have the UI (the search interface) take in queries of a user's language, convert them to the standardized language, and issue that for the search. This second approach has several benefits over the first approach -- mainly that changes to the categories do not have to be replicated across all existing documents.