Skip to content

Commit

Permalink
## [0.1.4+2] - Added few advance query references and solved bugs.
Browse files Browse the repository at this point in the history
- [Bug] `.setFacetFilter(dynamic value)` can now accept String or List<String> value.
- [Added] AttributeForDistinct (Advance)
- [Added] Distinct (Advance)
- [Added] GetRankingInfo (Advance)
- [Added] ClickAnalytics (Advance)
  • Loading branch information
nhathiwala committed Mar 17, 2019
1 parent 44b5292 commit 9e89de3
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 70 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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<String> 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.

Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()`
Expand Down
6 changes: 3 additions & 3 deletions lib/src/index_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AlgoliaIndexSettings extends AlgoliaSettings {
Map<String, dynamic> body = json.decode(response.body);
return body;
} catch (err) {
throw err;
return err;
}
}
}
Expand Down Expand Up @@ -58,7 +58,7 @@ class AlgoliaSettings {
Future<AlgoliaTask> 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(
Expand All @@ -72,7 +72,7 @@ class AlgoliaSettings {
AlgoliaTask task = AlgoliaTask._(algolia, _index, body);
return task;
} catch (err) {
throw err;
return err;
}
}

Expand Down
10 changes: 5 additions & 5 deletions lib/src/object_reference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AlgoliaObjectReference {
Map<String, dynamic> body = json.decode(response.body);
return AlgoliaObjectSnapshot.fromMap(algolia, _index, body);
} catch (err) {
throw err;
return err;
}
}

Expand All @@ -51,7 +51,7 @@ class AlgoliaObjectReference {
Map<String, dynamic> body = json.decode(response.body);
return AlgoliaTask._(algolia, _index, body);
} catch (err) {
throw err;
return err;
}
}

Expand Down Expand Up @@ -81,7 +81,7 @@ class AlgoliaObjectReference {
Map<String, dynamic> body = json.decode(response.body);
return AlgoliaTask._(algolia, _index, body);
} catch (err) {
throw err;
return err;
}
}

Expand Down Expand Up @@ -123,7 +123,7 @@ class AlgoliaObjectReference {
Map<String, dynamic> body = json.decode(response.body);
return AlgoliaTask._(algolia, _index, body);
} catch (err) {
throw err;
return err;
}
}

Expand All @@ -145,7 +145,7 @@ class AlgoliaObjectReference {
Map<String, dynamic> body = json.decode(response.body);
return AlgoliaTask._(algolia, _index, body);
} catch (err) {
throw err;
return err;
}
}
}
81 changes: 73 additions & 8 deletions lib/src/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class AlgoliaQuery {
: _index = index,
_parameters = parameters ??
Map<String, dynamic>.unmodifiable(<String, dynamic>{
'facetFilters': List<List<String>>.unmodifiable(<List<String>>[]),
'facetFilters':
List<List<dynamic>>.unmodifiable(<List<dynamic>>[]),
'optionalFilters':
List<List<String>>.unmodifiable(<List<String>>[]),
'numericFilters':
Expand Down Expand Up @@ -76,7 +77,7 @@ class AlgoliaQuery {
Map<String, dynamic> body = json.decode(response.body);
return AlgoliaQuerySnapshot.fromMap(algolia, _index, body);
} catch (err) {
throw err;
return err;
}
}

Expand Down Expand Up @@ -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<String> facetFilters =
List<String>.from(_parameters['facetFilters']);
assert(facetFilters.where((String item) => value == item).isEmpty,
AlgoliaQuery setFacetFilter(dynamic value) {
assert(value is String || value is List<String>,
'value must be either String | List<String> but was found `${value.runtimeType}`');
final List<dynamic> facetFilters =
List<dynamic>.from(_parameters['facetFilters']);
assert(facetFilters.where((dynamic item) => value == item).isEmpty,
'FacetFilters $value already exists in this query');
facetFilters.add(value);
return _copyWithParameters(<String, dynamic>{'facetFilters': facetFilters});
Expand Down Expand Up @@ -891,7 +894,7 @@ class AlgoliaQuery {
/// Source: [Learn more](https://www.algolia.com/doc/api-reference/api-parameters/insideBoundingBox/)
///
AlgoliaQuery setInsideBoundingBox(List<BoundingBox> 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<num>> list =
value.map((v) => [v.p1Lat, v.p1Lng, v.p2Lat, v.p2Lng]).toList();
Expand Down Expand Up @@ -930,13 +933,75 @@ class AlgoliaQuery {
/// Source: [Learn more](https://www.algolia.com/doc/api-reference/api-parameters/insidePolygon/)
///
AlgoliaQuery setInsidePolygon(List<BoundingPolygonBox> 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<num>> list = value
.map((v) => [v.p1Lat, v.p1Lng, v.p2Lat, v.p2Lng, v.p3Lat, v.p3Lng])
.toList();
return _copyWithParameters(<String, dynamic>{'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(
<String, dynamic>{'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(<String, dynamic>{'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(<String, dynamic>{'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(<String, dynamic>{'clickAnalytics': enabled});
}
}

class BoundingBox {
Expand Down
Loading

0 comments on commit 9e89de3

Please sign in to comment.