Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tagFilters implementation, adding tagFilters with OR relations #117

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/index_reference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class AlgoliaIndexReference extends AlgoliaQuery {
}) async {
var response = await algolia._apiCall(
ApiRequestType.post,
'indexes/$encodedIndex/facets/${Uri.encodeFull(facetName)}/query',
'indexes/$encodedIndex/facets/${Uri.encodeComponent(facetName)}/query',
data: {
'params': params,
'facetQuery': facetQuery,
Expand Down
11 changes: 7 additions & 4 deletions lib/src/index_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AlgoliaSettings {
final Algolia algolia;
final String _index;
final Map<String, dynamic> _parameters;
String get encodedIndex => Uri.encodeFull(_index);
String get encodedIndex => Uri.encodeComponent(_index);

AlgoliaSettings _copyWithParameters(Map<String, dynamic> parameters) {
return AlgoliaSettings._(
Expand All @@ -60,18 +60,21 @@ class AlgoliaSettings {
String toString() {
return {
'url': '${algolia._host}indexes' +
(_index.isNotEmpty ? '/' + Uri.encodeFull(_index) : ''),
(_index.isNotEmpty ? '/' + Uri.encodeComponent(_index) : ''),
'headers': algolia._headers,
'parameters': _parameters,
}.toString();
}

Future<AlgoliaTask> setSettings() async {
Future<AlgoliaTask> setSettings({
required bool forwardToReplicas,
}) async {
assert(
_parameters.keys.isNotEmpty, 'No setting parameter to update found.');
var response = await algolia._apiCall(
ApiRequestType.put,
'indexes/$encodedIndex/settings',
'indexes/$encodedIndex/settings' +
(forwardToReplicas ? '?forwardToReplicas=true' : ''),
data: _parameters,
);
Map<String, dynamic> body = json.decode(response.body);
Expand Down
6 changes: 3 additions & 3 deletions lib/src/object_reference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class AlgoliaObjectReference {
String? get objectID => _objectId;

String? get encodedObjectID =>
_objectId != null ? Uri.encodeFull(_objectId!) : null;
String? get encodedIndex => _index != null ? Uri.encodeFull(_index!) : null;
_objectId != null ? Uri.encodeComponent(_objectId!) : null;
String? get encodedIndex => _index != null ? Uri.encodeComponent(_index!) : null;

/// Get the object referred to by this [AlgoliaObjectReference].
///
Expand Down Expand Up @@ -47,7 +47,7 @@ class AlgoliaObjectReference {
url += '/$encodedObjectID';
}
if (data['objectID'] != null && _objectId == null) {
url += "/${Uri.encodeFull(data['objectID'])}";
url += "/${Uri.encodeComponent(data['objectID'])}";
} else if (data['objectID'] != null) {
data.remove('objectID');
}
Expand Down
18 changes: 13 additions & 5 deletions lib/src/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class AlgoliaQuery {
List<List<String>>.unmodifiable(<List<String>>[]),
'numericFilters':
List<List<String>>.unmodifiable(<List<String>>[]),
'tagFilters': List<List<String>>.unmodifiable(<List<String>>[]),
'tagFilters': List<dynamic>.unmodifiable(<dynamic>[]),
});
final Algolia algolia;
final String _index;
final Map<String, dynamic> _parameters;

Map<String, dynamic> get parameters => _parameters;
String get encodedIndex => Uri.encodeFull(_index);
String get encodedIndex => Uri.encodeComponent(_index);

AlgoliaQuery _copyWithParameters(Map<String, dynamic> parameters) {
return AlgoliaQuery._(
Expand Down Expand Up @@ -671,13 +671,21 @@ class AlgoliaQuery {
/// Source: [Learn more](https://www.algolia.com/doc/api-reference/api-parameters/tagFilters/)
///
AlgoliaQuery setTagFilter(String value) {
final tagFilters = List<String>.from(_parameters['tagFilters']);
assert(tagFilters.where((String item) => value == item).isEmpty,
final tagFilters = List<dynamic>.from(_parameters['tagFilters']);
assert(tagFilters.where((dynamic item) => value == item).isEmpty,
'TagFilters $value already exists in this query');
tagFilters.add(value);
tagFilters.add([value]);
return _copyWithParameters(<String, dynamic>{'tagFilters': tagFilters});
}

AlgoliaQuery setTagFilterOneOf(List<String> oneOfValues) {
assert(oneOfValues.isNotEmpty);
final tagFilters = List<dynamic>.from(_parameters['tagFilters']);
tagFilters.add(List.unmodifiable([...oneOfValues]));
return _copyWithParameters(<String, dynamic>{'tagFilters': tagFilters});
}


///
/// **sumOrFiltersScores**
///
Expand Down
2 changes: 1 addition & 1 deletion lib/src/synonyms_reference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AlgoliaSynonymsReference {
///
/// ID of the referenced index.
///
String get encodedIndex => Uri.encodeFull(index);
String get encodedIndex => Uri.encodeComponent(index);

///
/// **Search synonyms**
Expand Down
Loading