knoxpo / dart_algolia

[Unofficial] Algolia is a pure dart SDK, wrapped around Algolia REST API for easy implementation for your Flutter or Dart projects.
Other
116 stars 110 forks source link
algolia algolia-search algoliasearch dart flutter knoxpo sdk

Algolia Search (Dart Client)

Algolia

[UNOFFICIAL] Algolia is a pure dart SDK, wrapped around Algolia REST API for easy implementation for your Flutter or Dart projects.

pub package .github/workflows/dart.yml Build Status

Pub - API Docs - GitHub

Features

Version compatibility

See CHANGELOG for all breaking (and non-breaking) changes.

Become Contributor

If you wish to contribute in our development process, refer to our Contributing Guidelines

Getting started

You should ensure that you add the router as a dependency in your flutter project.

dependencies:
 algolia: ^1.1.2

You should then run flutter packages upgrade or update your packages in IntelliJ.

Example Project

There is a pretty sweet example project in the example folder. Check it out. Otherwise, keep reading to get up and running.

Setting up

  ///
  /// Initiate static Algolia once in your project.
  ///
  class Application {
    static final Algolia algolia = Algolia.init(
      applicationId: 'YOUR_APPLICATION_ID',
      apiKey: 'YOUR_API_KEY',
    );
  }

  void main() async {
    ///
    /// Initiate Algolia in your project
    ///
    Algolia algolia = Application.algolia;

    ///
    /// Perform Query
    ///
    AlgoliaQuery query = algolia.instance.index('contacts').query('john');

    // Perform multiple facetFilters
    query = query.facetFilter('status:published');
    query = query.facetFilter('isDelete:false');

    // Get Result/Objects
    AlgoliaQuerySnapshot snap = await query.getObjects();

    // Checking if has [AlgoliaQuerySnapshot]
    print('Hits count: ${snap.nbHits}');

    ///
    /// Perform Index Settings
    ///
    AlgoliaIndexSettings settingsRef = algolia.instance.index('contact').settings;

    // Get Settings
    Map<String, dynamic> currentSettings = await settingsRef.getSettings();

    // Checking if has [Map]
    print('\n\n');
    print(currentSettings);

    // Set Settings
    AlgoliaSettings settingsData = settingsRef;
    settingsData = settingsData.setReplicas(const ['index_copy_1', 'index_copy_2']);
    AlgoliaTask setSettings = await settingsData.setSettings();

    // Checking if has [AlgoliaTask]
    print('\n\n');
    print(setSettings.data);

    // Pushing Event
    AlgoliaEvent event = AlgoliaEvent(
      eventType: AlgoliaEventType.view,
      eventName: 'View contact',
      index: 'contacts',
      userToken: 'user123',
    );
    await algolia.instance.pushEvents([event]);
  }

Insights

The Insights API lets you push a collection of events related to how your product is being used. Sending those events is a required step for using several Algolia features like Click analytics, A/B Testing, Personalization and Dynamic Re-Ranking.

Search Parameters

Here is the list of parameters you can use with the search method (search scope). We have managed to include most commonly used parameters for search functionality and there many more to be added in future releases.

We have indicated counts of queryable parameters with their availability status on official Algolia website and what we have managed to support it in this version of the release.

search (1/1)
attributes (2/2)
filtering (6/6)
faceting (4/4)
highlighting-snippeting (6/6)
pagination (4/4)
typos (5/5)
geo-search (7/7)
languages (8/11)
query-rules (3/3)
personalization (3/3)
query-strategy (7/7)
performance (2/2)
advanced (11/15)
custom-query (11/15)
GET RESULT

Settings Parameters

Here is the list of parameters you can use with the settings method (settings scope). We have managed to include most commonly used parameters for settings functionality and there many more to be added in future releases.

We have indicated counts of settings parameters with their availability status on official Algolia website and what we have managed to support it in this version of the release.

attributes (4/4)
ranking (3/3)
faceting (2/2)
highlighting-snippeting (6/6)
pagination (2/2)
typos (7/7)
languages (8/11)
query-rules (3/3)
personalization (3/3)
query-strategy (7/7)
performance (2/2)
advanced (11/15)
GET Settings
SET Settings

Algolia [Unofficial SDK for Dart] is a Knoxpo original.