Flutter- Is it impossible to implement search feature in Firestore with Algolia as of yet?

2,681

Solution 1

Your question is twofold:

Indexing Firebase content

In order to search the content you have in Firestore you have to send it to Algolia for indexing. Usually you would do that from a server or a Cloud Function like this.

There is no examples in dart because there is no server-side Algolia library for Dart, so if you want to use Dart you have to use the rest API

If you don't need to use Dart and are looking for a simple solution, you can use either NodeJS or Python cloud functions to index your content.

Querying Algolia

Yes you can query Algolia from Flutter using their Rest API as there is no client side library for Algolia in Dart.

It would look like this:

var uri = Uri.https(
  '$your_app_id-dsn.algolia.net',
  '/1/indexes/$your_index/query',
);

var headers = {
  'X-Algolia-API-Key': your_api_key,
  'X-Algolia-Application-Id': your_app_id,
};

var data = jsonEncode({
  'query': your_query,
});

var request = await HttpRequest.request(
  uri.toString(),
  requestHeaders: headers,
  method: 'POST',
  sendData: data,
);

var json = request.responseText;
var hits = jsonDecode(json)['hits'] as List;

Solution 2

I have built a pure Dart Algolia SDK, which is independent of iOS / Android, thus it can be easily implemented in your non-Flutter projects (such as Dart website, DartAngular).

You can find it on Dart’s website, or here is the link https://pub.dartlang.org/packages/algolia and there many more features to come in newer releases.

If you wish to contribute, you are most welcomed to join me.

Share:
2,681
Daibaku
Author by

Daibaku

Updated on December 07, 2022

Comments

  • Daibaku
    Daibaku over 1 year

    I would like to know whether there is any way to implement search feature in Firestore with Algolia?
    I searched and Dart is not supported yet.
    So, is it completely impossible or any other way to make it work?
    Since I'm pretty new in programming, someone please guide me to the right way?
    Any help is highly appreciated.

  • Daibaku
    Daibaku almost 6 years
    Thank you so much that's really helpful!