algolia 0.1.3+2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 78

Algolia Search (Dart Client)

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

pub package

Pub - API Docs - GitHub

Features

  • Query / Search
  • Get Object
  • Add Object
  • Update Object
  • Partial Update Object
  • Delete Object
  • Perform Batch Activities
  • Add Index
  • Delete Index
  • Clear Index
  • Index Settings

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: ^0.1.3

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').search('john');

    // Perform multiple facetFilters
    query = query.setFacetFilter('status:published');
    query = query.setFacetFilter('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);
  }

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)
  • .search(String value)
attributes (2/2)
  • .setAttributesToRetrieve(List<String> value)
  • .setRestrictSearchableAttributes(List<String> value)
filtering (6/6)
  • .setFilters(String value)
  • .setFacetFilter(String value) This can be used multiple times in a query.
  • .setOptionalFilter(String value) This can be used multiple times in a query.
  • .setNumericFilter(String value) This can be used multiple times in a query.
  • .setTagFilter(String value) This can be used multiple times in a query.
  • .setSumOrFiltersScore(bool value)
faceting (4/4)
  • .setFacets(List<String> value)
  • .setMaxValuesPerFacet(int value)
  • .setFacetingAfterDistinct({bool enable = true})
  • .setSortFacetValuesBy(AlgoliaSortFacetValuesBy value)
highlighting-snippeting (6/6)
  • .setAttributesToHighlight(List<String> value)
  • .setAttributesToSnippet(List<String> value)
  • .setHighlightPreTag(String value)
  • .setHighlightPostTag(String value)
  • .setSnippetEllipsisText(String value)
  • .setRestrictHighlightAndSnippetArrays({bool enable = true})
pagination (4/4)
  • .setPage(int value)
  • .setHitsPerPage(int value)
  • .setOffset(int value)
  • .setLength(int value)
typos (5/5)
  • .setMinWordSizefor1Typo(int value)
  • .setMinWordSizefor2Typos(int value)
  • .setTypoTolerance(dynamic value)
  • .setAllowTyposOnNumericTokens(bool value)
  • .setDisableTypoToleranceOnAttributes(List<String> value)
geo-search (7/7)
  • .setAroundLatLng(String value)
  • .setAroundLatLngViaIP(bool value)
  • .setAroundRadius(dynamic value)
  • .setAroundPrecision(int value)
  • .setMinimumAroundRadius(int value)
  • .setInsideBoundingBox(List<BoundingBox> value)
  • .setInsidePolygon(List<BoundingPolygonBox> value)
languages (0/3)
query-rules (0/2)
query-strategy (0/7)
advanced (0/11)
GET RESULT
  • .getObjects()

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)
  • .setSearchableAttributes(List<String> value)
  • .setAttributesForFaceting(List<String> value)
  • .setUnretrievableAttributes(List<String> value)
  • .setAttributesToRetrieve(List<String> value)
ranking (3/3)
  • .setRanking(List<String> value)
  • .setCustomRanking(List<String> value)
  • .setReplicas(List<String> value)
faceting (2/2)
  • .setMaxValuesPerFacet(int value)
  • .setSortFacetValuesBy(AlgoliaSortFacetValuesBy value)
highlighting-snippeting (6/6)
  • .setAttributesToHighlight(List<String> value)
  • .setAttributesToSnippet(List<String> value)
  • .setHighlightPreTag(String value)
  • .setHighlightPostTag(String value)
  • .setSnippetEllipsisText(String value)
  • .setRestrictHighlightAndSnippetArrays({bool enable = true})
pagination (2/2)
  • .setHitsPerPage(int value)
  • .setPaginationLimitedTo(int value)
typos (7/7)
  • .setMinWordSizefor1Typo(int value)
  • .setMinWordSizefor2Typos(int value)
  • .setTypoTolerance(dynamic value)
  • .setAllowTyposOnNumericTokens(bool value)
  • .setDisableTypoToleranceOnAttributes(List<String> value)
  • .setDisableTypoToleranceOnWords(List<String> value)
  • .setSeparatorsToIndex(List<String> value)
languages (0/3)
query-rules (0/2)
query-strategy (0/7)
performance (0/2)
advanced (0/11)
GET Settings
  • .getSettings()
SET Settings
  • .setSettings()

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

[0.1.3+2] - Added support to manage index settings.

  • Implementation & bug solved
    • highlightResult [Bug] (commit ref: 0d76d24fe8aa347a0933920afe5ded43bdcbd68b)
    • snippetResult [Implementation] (commit ref: 0d76d24fe8aa347a0933920afe5ded43bdcbd68b)

[0.1.3+1] - Added support to manage index settings.

  • Updated example.dart: Added index settings example.
  • Updated index .setSettings() response to AlgoliaTask.

[0.1.3] - Added support to manage index settings.

  • Added support to manage index settings (Get & Set), limited to 24 settings parameters, more to be added in newer releases.

[0.1.2] - Added new query params.

  • OptionalFilter (Filtering)
  • NumericFilter (Filtering)
  • TagFilter (Filtering)
  • SumOrFiltersScore (Filtering)
  • AroundLatLng (Geo Search)
  • AroundLatLngViaIP (Geo Search)
  • AroundRadius (Geo Search)
  • AroundPrecision (Geo Search)
  • MinimumAroundRadius (Geo Search)
  • InsideBoundingBox (Geo Search)
  • InsidePolygon (Geo Search)
  • MinWordSizefor1Typo (Typo)
  • MinWordSizefor2Typos (Typo)
  • TypoTolerance (Typo)
  • AllowTyposOnNumericTokens (Typo)
  • DisableTypoToleranceOnAttributes (Typo)
  • DisableTypoToleranceOnWords (Typo)
  • SeparatorsToIndex (Typo)

[0.1.1] - Added example.

  • Bug fixes.
  • Removed Flutter direct dependency to support universal dart projects.

[0.1.0] - Initial Release.

  • Initial release.

example/example.dart

import 'dart:async';
import 'package:algolia/algolia.dart';

void main() async {
  ///
  /// Initiate Algolia in your project
  ///
  Algolia algolia = Application.algolia;
  AlgoliaTask taskAdded,
      taskUpdated,
      taskDeleted,
      taskBatch,
      taskClearIndex,
      taskDeleteIndex;
  AlgoliaObjectSnapshot addedObject;

  ///
  /// 1. Perform Adding Object to existing Index.
  ///
  Map<String, dynamic> addData = {
    'name': 'John Smith',
    'contact': '+1 609 123456',
    'email': 'johan@example.com',
    'isDelete': false,
    'status': 'published',
    'createdAt': DateTime.now(),
    'modifiedAt': DateTime.now(),
  };
  taskAdded = await algolia.instance.index('contacts').addObject(addData);

  // Checking if has [AlgoliaTask]
  print(taskAdded.data);

  ///
  /// 2. Perform Get Object to existing Index.
  ///
  /// -- A Delay of 3 seconds is added for algolia to cdn the object for retrieval.
  addedObject = await Future.delayed(Duration(seconds: 3), () async {
    return await algolia.instance
        .index('contacts')
        .object(taskAdded.data['objectID'].toString())
        .getObject();
  });

  // Checking if has [AlgoliaObjectSnapshot]
  print('\n\n');
  print(addedObject.data);

  ///
  /// 3. Perform Updating Object to existing Index.
  ///
  Map<String, dynamic> updateData = Map<String, dynamic>.from(addedObject.data);
  updateData['contact'] = '+1 609 567890';
  updateData['modifiedAt'] = DateTime.now();
  taskUpdated = await algolia.instance
      .index('contacts')
      .object(addedObject.objectID)
      .updateData(updateData);

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

  ///
  /// 4. Perform Delete Object to existing Index.
  ///
  taskDeleted = await algolia.instance
      .index('contacts')
      .object(addedObject.objectID)
      .deleteObject();

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

  ///
  /// 5. Perform Batch
  ///
  AlgoliaBatch batch = algolia.instance.index('contacts').batch();
  batch.clearIndex();
  for (int i = 0; i < 10; i++) {
    Map<String, dynamic> addData = {
      'name': 'John ${DateTime.now().microsecond}',
      'contact': '+1 ${DateTime.now().microsecondsSinceEpoch}',
      'email': 'johan.${DateTime.now().microsecond}@example.com',
      'isDelete': false,
      'status': 'published',
      'createdAt': DateTime.now(),
      'modifiedAt': DateTime.now(),
    };
    batch.addObject(addData);
  }

  // Get Result/Objects
  taskBatch = await batch.commit();

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

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

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

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

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

  ///
  /// 7. Perform List all Indices
  ///
  AlgoliaIndexesSnapshot indices = await algolia.instance.getIndices();

  // Checking if has [AlgoliaIndexesSnapshot]
  print('\n\n');
  print('Indices count: ${indices.items.length}');

  ///
  /// 8. Perform Clear Index.
  ///
  taskClearIndex = await algolia.instance.index('contacts').clearIndex();

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

  ///
  /// 9. Perform Delete Index.
  ///
  taskDeleteIndex = await algolia.instance.index('contact').deleteIndex();

  ///
  /// 10. Get Index Setting Instance.
  ///
  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);
}

class Application {
  static Algolia algolia = Algolia.init(
    applicationId: 'YOUR_APPLICATION_ID',
    apiKey: 'YOUR_API_KEY',
  );
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  algolia: ^0.1.3+2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:algolia/algolia.dart';
  
Version Uploaded Documentation Archive
0.1.3+2 Jan 18, 2019 Go to the documentation of algolia 0.1.3+2 Download algolia 0.1.3+2 archive
0.1.3+1 Dec 25, 2018 Go to the documentation of algolia 0.1.3+1 Download algolia 0.1.3+1 archive
0.1.3 Dec 24, 2018 Go to the documentation of algolia 0.1.3 Download algolia 0.1.3 archive
0.1.2 Dec 21, 2018 Go to the documentation of algolia 0.1.2 Download algolia 0.1.2 archive
0.1.1 Dec 19, 2018 Go to the documentation of algolia 0.1.1 Download algolia 0.1.1 archive
0.1.0 Dec 19, 2018 Go to the documentation of algolia 0.1.0 Download algolia 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
56
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
78
Learn more about scoring.

We analyzed this package on Jan 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.10

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:algolia/algolia.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
http ^0.12.0 0.12.0+1
meta ^1.1.6 1.1.7
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
path 1.6.2
source_span 1.5.2
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
test ^1.0.0