diff --git a/CHANGELOG.md b/CHANGELOG.md index ce89736..b59ea62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [0.1.4+2] - Added few advance query references and solved bugs. +- [Bug] `.setFacetFilter(dynamic value)` can now accept String or List value. +- [Added] AttributeForDistinct (Advance) +- [Added] Distinct (Advance) +- [Added] GetRankingInfo (Advance) +- [Added] ClickAnalytics (Advance) + ## [0.1.4+1] - Added support facets. - Added `facets` to ``AlgoliaQuerySnapshot`` to list facets name with hits count. diff --git a/README.md b/README.md index 8c77e6b..8f76018 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ version of the release. ##### filtering (6/6) - `.setFilters(String value)` -- `.setFacetFilter(String value)` This can be used multiple times in a query. +- `.setFacetFilter(dynamic 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. @@ -218,7 +218,11 @@ version of the release. ##### performance (0/2) -##### advanced (0/11) +##### advanced (4/11) +- `.setAttributeForDistinct(String value)` +- `.setDistinct({dynamic value = 0})` +- `.setGetRankingInfo({bool enabled = true})` +- `.setClickAnalytics({bool enabled = false})` ##### GET Settings - `.getSettings()` diff --git a/lib/src/index_settings.dart b/lib/src/index_settings.dart index 8406fa8..dac0bf3 100644 --- a/lib/src/index_settings.dart +++ b/lib/src/index_settings.dart @@ -26,7 +26,7 @@ class AlgoliaIndexSettings extends AlgoliaSettings { Map body = json.decode(response.body); return body; } catch (err) { - throw err; + return err; } } } @@ -58,7 +58,7 @@ class AlgoliaSettings { Future setSettings() async { try { assert( - _parameters.keys.length > 0, 'No setting parameter to update found.'); + _parameters.keys.isNotEmpty, 'No setting parameter to update found.'); String url = '${algolia._host}indexes/$_index/settings'; Response response = await put( @@ -72,7 +72,7 @@ class AlgoliaSettings { AlgoliaTask task = AlgoliaTask._(algolia, _index, body); return task; } catch (err) { - throw err; + return err; } } diff --git a/lib/src/object_reference.dart b/lib/src/object_reference.dart index 0d889f6..1a6889a 100644 --- a/lib/src/object_reference.dart +++ b/lib/src/object_reference.dart @@ -27,7 +27,7 @@ class AlgoliaObjectReference { Map body = json.decode(response.body); return AlgoliaObjectSnapshot.fromMap(algolia, _index, body); } catch (err) { - throw err; + return err; } } @@ -51,7 +51,7 @@ class AlgoliaObjectReference { Map body = json.decode(response.body); return AlgoliaTask._(algolia, _index, body); } catch (err) { - throw err; + return err; } } @@ -81,7 +81,7 @@ class AlgoliaObjectReference { Map body = json.decode(response.body); return AlgoliaTask._(algolia, _index, body); } catch (err) { - throw err; + return err; } } @@ -123,7 +123,7 @@ class AlgoliaObjectReference { Map body = json.decode(response.body); return AlgoliaTask._(algolia, _index, body); } catch (err) { - throw err; + return err; } } @@ -145,7 +145,7 @@ class AlgoliaObjectReference { Map body = json.decode(response.body); return AlgoliaTask._(algolia, _index, body); } catch (err) { - throw err; + return err; } } } diff --git a/lib/src/query.dart b/lib/src/query.dart index ed5a8f8..1fab323 100644 --- a/lib/src/query.dart +++ b/lib/src/query.dart @@ -18,7 +18,8 @@ class AlgoliaQuery { : _index = index, _parameters = parameters ?? Map.unmodifiable({ - 'facetFilters': List>.unmodifiable(>[]), + 'facetFilters': + List>.unmodifiable(>[]), 'optionalFilters': List>.unmodifiable(>[]), 'numericFilters': @@ -76,7 +77,7 @@ class AlgoliaQuery { Map body = json.decode(response.body); return AlgoliaQuerySnapshot.fromMap(algolia, _index, body); } catch (err) { - throw err; + return err; } } @@ -260,10 +261,12 @@ class AlgoliaQuery { /// /// Source: [Learn more](https://www.algolia.com/doc/api-reference/api-parameters/facetFilters/) /// - AlgoliaQuery setFacetFilter(String value) { - final List facetFilters = - List.from(_parameters['facetFilters']); - assert(facetFilters.where((String item) => value == item).isEmpty, + AlgoliaQuery setFacetFilter(dynamic value) { + assert(value is String || value is List, + 'value must be either String | List but was found `${value.runtimeType}`'); + final List facetFilters = + List.from(_parameters['facetFilters']); + assert(facetFilters.where((dynamic item) => value == item).isEmpty, 'FacetFilters $value already exists in this query'); facetFilters.add(value); return _copyWithParameters({'facetFilters': facetFilters}); @@ -891,7 +894,7 @@ class AlgoliaQuery { /// Source: [Learn more](https://www.algolia.com/doc/api-reference/api-parameters/insideBoundingBox/) /// AlgoliaQuery setInsideBoundingBox(List value) { - assert(value != null && value.length > 0, 'value can not be empty'); + assert(value != null && value.isNotEmpty, 'value can not be empty'); assert(!_parameters.containsKey('insideBoundingBox')); List> list = value.map((v) => [v.p1Lat, v.p1Lng, v.p2Lat, v.p2Lng]).toList(); @@ -930,13 +933,75 @@ class AlgoliaQuery { /// Source: [Learn more](https://www.algolia.com/doc/api-reference/api-parameters/insidePolygon/) /// AlgoliaQuery setInsidePolygon(List value) { - assert(value != null && value.length > 0, 'value can not be empty'); + assert(value != null && value.isNotEmpty, 'value can not be empty'); assert(!_parameters.containsKey('insidePolygon')); List> list = value .map((v) => [v.p1Lat, v.p1Lng, v.p2Lat, v.p2Lng, v.p3Lat, v.p3Lng]) .toList(); return _copyWithParameters({'insidePolygon': list}); } + + /// + /// **attributeForDistinct** + /// + /// Name of the de-duplication attribute to be used with the distinct feature. + /// + /// TODO: Add documention. + /// Source: [Learn more](https://www.algolia.com/doc/api-reference/api-parameters/attributeForDistinct/) + /// + AlgoliaQuery setAttributeForDistinct(String value) { + assert(value != null, 'value can not be empty'); + assert(!_parameters.containsKey('attributeForDistinct')); + return _copyWithParameters( + {'attributeForDistinct': value}); + } + + /// + /// **distinct** + /// + /// Name of the de-duplication attribute to be used with the distinct feature. + /// + /// TODO: Add documention. + /// Source: [Learn more](https://www.algolia.com/doc/api-reference/api-parameters/distinct/) + /// + AlgoliaQuery setDistinct({dynamic value = 0}) { + assert(value is int || value is bool, 'value should be a int or boolean'); + assert(!_parameters.containsKey('distinct')); + return _copyWithParameters({'distinct': value}); + } + + /// + /// **getRankingInfo** + /// + /// Retrieve detailed ranking information. + /// + /// This setting lets you see exactly which ranking criteria played a role in selecting each record. + /// + /// TODO: Add documention. + /// Source: [Learn more](https://www.algolia.com/doc/api-reference/api-parameters/getRankingInfo/) + /// + AlgoliaQuery setGetRankingInfo({bool enabled = true}) { + assert(enabled != null, 'value can not be empty'); + assert(!_parameters.containsKey('getRankingInfo')); + return _copyWithParameters({'getRankingInfo': enabled}); + } + + /// + /// **clickAnalytics** + /// + /// Enable the Click Analytics feature. + /// + /// The effect of setting clickAnalytics to true is to add a queryID to the search response. + /// As explained here, this queryID can subsequently be used in click and conversion analytics. + /// + /// TODO: Add documention. + /// Source: [Learn more](https://www.algolia.com/doc/api-reference/api-parameters/clickAnalytics/) + /// + AlgoliaQuery setClickAnalytics({bool enabled = false}) { + assert(enabled != null, 'value can not be empty'); + assert(!_parameters.containsKey('clickAnalytics')); + return _copyWithParameters({'clickAnalytics': enabled}); + } } class BoundingBox { diff --git a/pubspec.lock b/pubspec.lock index 902d383..3b0d596 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,7 +7,7 @@ packages: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.33.3+1" + version: "0.35.4" args: dependency: transitive description: @@ -49,7 +49,7 @@ packages: name: convert url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" crypto: dependency: transitive description: @@ -57,20 +57,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.6" - csslib: - dependency: transitive - description: - name: csslib - url: "https://pub.dartlang.org" - source: hosted - version: "0.14.6" front_end: dependency: transitive description: name: front_end url: "https://pub.dartlang.org" source: hosted - version: "0.1.6+4" + version: "0.1.14" glob: dependency: transitive description: @@ -78,20 +71,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.7" - html: - dependency: transitive - description: - name: html - url: "https://pub.dartlang.org" - source: hosted - version: "0.13.3+3" http: dependency: "direct main" description: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.12.0" + version: "0.12.0+1" http_multi_server: dependency: transitive description: @@ -133,14 +119,7 @@ packages: name: kernel url: "https://pub.dartlang.org" source: hosted - version: "0.3.6+4" - logging: - dependency: transitive - description: - name: logging - url: "https://pub.dartlang.org" - source: hosted - version: "0.11.3+2" + version: "0.3.14" matcher: dependency: transitive description: @@ -154,7 +133,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.1.7" mime: dependency: transitive description: @@ -189,7 +168,7 @@ packages: name: package_resolver url: "https://pub.dartlang.org" source: hosted - version: "1.0.6" + version: "1.0.10" path: dependency: transitive description: @@ -197,20 +176,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.6.2" - plugin: + pedantic: dependency: transitive description: - name: plugin + name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "0.2.0+3" + version: "1.5.0" pool: dependency: transitive description: name: pool url: "https://pub.dartlang.org" source: hosted - version: "1.3.6" + version: "1.4.0" pub_semver: dependency: transitive description: @@ -266,7 +245,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.4.1" + version: "1.5.5" stack_trace: dependency: transitive description: @@ -294,28 +273,28 @@ packages: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.1.0" test: dependency: "direct dev" description: name: test url: "https://pub.dartlang.org" source: hosted - version: "1.5.1+1" + version: "1.5.3" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.1" + version: "0.2.2" test_core: dependency: transitive description: name: test_core url: "https://pub.dartlang.org" source: hosted - version: "0.2.0+1" + version: "0.2.1+1" typed_data: dependency: transitive description: @@ -323,13 +302,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.6" - utf: - dependency: transitive - description: - name: utf - url: "https://pub.dartlang.org" - source: hosted - version: "0.9.0+5" vm_service_client: dependency: transitive description: @@ -359,4 +331,4 @@ packages: source: hosted version: "2.1.15" sdks: - dart: ">=2.0.0 <3.0.0" + dart: ">=2.1.1-dev.0.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 1ee5d67..d841c12 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: algolia -version: 0.1.4+1 +version: 0.1.4+2 authors: - Nayan Hathiwala (Knoxpo) description: > @@ -7,7 +7,7 @@ description: > homepage: https://github.com/knoxpo/dart_algolia environment: - sdk: ">=2.0.0-dev.68.0 <3.0.0" + sdk: ">=2.0.0 <3.0.0" dependencies: meta: ^1.1.6 diff --git a/test/algolia_test.dart b/test/algolia_test.dart index 8fd5761..0ad519e7 100644 --- a/test/algolia_test.dart +++ b/test/algolia_test.dart @@ -204,11 +204,17 @@ void main() async { }); } +// class Application { +// static final Algolia algolia = Algolia.init( +// applicationId: 'YOUR_APPLICATION_ID', +// apiKey: 'YOUR_API_KEY', +// ); +// } + + class Application { static final Algolia algolia = Algolia.init( - applicationId: 'YOUR_APPLICATION_ID', - apiKey: 'YOUR_API_KEY', + applicationId: '86BGVLXUEM', + apiKey: '07e1fdc2794cc6dabefd9219e83acd1d', ); -} - - +} \ No newline at end of file