From e976081d756c613dad73699da4fcf92294026212 Mon Sep 17 00:00:00 2001 From: meili-bot <74670311+meili-bot@users.noreply.github.com> Date: Tue, 27 Apr 2021 15:27:09 +0200 Subject: [PATCH 01/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e2a245d..e029fd13 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ JSON output: ## 🤖 Compatibility with MeiliSearch -This package only guarantees the compatibility with the [version v0.20.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.20.0). +This package only guarantees the compatibility with the [version v0.21.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.21.0). ## 💡 Learn More From 22db1b1f9a4d0d237a062eae82e4122e78f18d9d Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 5 Jul 2021 16:05:20 +0200 Subject: [PATCH 02/12] Update README --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index ac4e9de9..d3789609 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ void main() async { } ``` -With the `updateId`, you can check the status (`enqueued`, `processed` or `failed`) of your documents addition using the [update endpoint](https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status). +With the `updateId`, you can check the status (`enqueued`, `processing`, `processed` or `failed`) of your documents addition using the [update endpoint](https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status). #### Basic Search @@ -124,7 +124,6 @@ All the supported options are described in the [search parameters](https://docs. var result = await index.search( 'prince', attributesToHighlight: ['title'], - filters: 'book_id > 10', ); ``` From 4625c6fee574af811090553394ddd2179b4c89aa Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 5 Jul 2021 16:11:11 +0200 Subject: [PATCH 03/12] Rename attributes_for_faceting into filterable_attributes --- lib/src/index_settings.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/index_settings.dart b/lib/src/index_settings.dart index 9bdf916e..17f76e5c 100644 --- a/lib/src/index_settings.dart +++ b/lib/src/index_settings.dart @@ -3,7 +3,7 @@ class IndexSettings { this.synonyms, this.stopWords, this.rankingRules, - this.attributesForFaceting, + this.filterableAttributes, this.distinctAttribute, this.searchableAttributes = allAttributes, this.displayedAttributes = allAttributes, @@ -21,7 +21,7 @@ class IndexSettings { List? rankingRules; /// Attributes to use as [facets](https://docs.meilisearch.com/reference/features/faceted_search.html) - List? attributesForFaceting; + List? filterableAttributes; /// Search returns documents with distinct (different) values of the given field List? distinctAttribute; @@ -36,7 +36,7 @@ class IndexSettings { 'synonyms': synonyms, 'stopWords': stopWords, 'rankingRules': rankingRules, - 'attributesForFaceting': attributesForFaceting, + 'filterableAttributes': filterableAttributes, 'distinctAttribute': distinctAttribute, 'searchableAttributes': searchableAttributes, 'displayedAttributes': displayedAttributes, @@ -48,8 +48,8 @@ class IndexSettings { .map((key, value) => MapEntry(key, value.cast())), stopWords: (map['stopWords'] as List?)?.cast(), rankingRules: (map['rankingRules'] as List?)?.cast(), - attributesForFaceting: - (map['attributesForFaceting'] as List?)?.cast(), + filterableAttributes: + (map['filterableAttributes'] as List?)?.cast(), distinctAttribute: (map['distinctAttribute'] as List?)?.cast(), searchableAttributes: (map['searchableAttributes'] as List?)?.cast(), From 4e68078328e39d4bbc3916b5c9dae5a7224642c8 Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 5 Jul 2021 16:14:45 +0200 Subject: [PATCH 04/12] Adding processing in the condition to check --- test/utils/client.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/utils/client.dart b/test/utils/client.dart index 6d8dd917..b24f54bc 100644 --- a/test/utils/client.dart +++ b/test/utils/client.dart @@ -69,7 +69,7 @@ extension PendingUpdateX on PendingUpdate { while (DateTime.now().isBefore(endingTime)) { var response = await getStatus(); - if (response.status != 'enqueued') { + if (response.status != 'enqueued' && response.status != 'processing') { return response; } await Future.delayed(interval); From fdc1cea265fc7dca68ee4781a13594a4e4de7d32 Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 5 Jul 2021 16:21:48 +0200 Subject: [PATCH 05/12] Rename Filters in Filter and remove FacetFilters --- lib/src/index.dart | 4 ++-- lib/src/index_impl.dart | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/src/index.dart b/lib/src/index.dart index 056a00f1..cef777da 100644 --- a/lib/src/index.dart +++ b/lib/src/index.dart @@ -22,8 +22,8 @@ abstract class MeiliSearchIndex { String? query, { int? offset, int? limit, - String? filters, - dynamic facetFilters, + String? filter, + // dynamic facetFilters, List? facetsDistribution, List? attributesToRetrieve, List? attributesToCrop, diff --git a/lib/src/index_impl.dart b/lib/src/index_impl.dart index 52311ff1..a0206655 100644 --- a/lib/src/index_impl.dart +++ b/lib/src/index_impl.dart @@ -108,8 +108,8 @@ class MeiliSearchIndexImpl implements MeiliSearchIndex { String? query, { int? offset, int? limit, - String? filters, - dynamic facetFilters, + String? filter, + // dynamic facetFilters, List? facetsDistribution, List? attributesToRetrieve, List? attributesToCrop, @@ -121,8 +121,8 @@ class MeiliSearchIndexImpl implements MeiliSearchIndex { 'q': query, 'offset': offset, 'limit': limit, - 'filters': filters, - 'facetFilters': facetFilters, + 'filter': filter, + // 'facetFilters': facetFilters, 'facetsDistribution': facetsDistribution, 'attributesToRetrieve': attributesToRetrieve, 'attributesToCrop': attributesToCrop, From 5bd9cc10f25533869cdda513f05351adcecc8826 Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 5 Jul 2021 17:30:53 +0200 Subject: [PATCH 06/12] Adding test for new features --- test/search_test.dart | 43 +++++++++++++++++++++++++++++++++++++++++++ test/utils/books.dart | 12 ++++++------ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/test/search_test.dart b/test/search_test.dart index f5ca768b..2e65675e 100644 --- a/test/search_test.dart +++ b/test/search_test.dart @@ -1,3 +1,4 @@ +import 'package:meilisearch/meilisearch.dart'; import 'package:test/test.dart'; import 'utils/books.dart'; @@ -25,6 +26,12 @@ void main() { expect(result.hits, hasLength(booksDoc.length)); }); + test('with basic query with quote', () async { + var index = await createBooksIndex(); + var result = await index.search('coco \"harry\"'); + expect(result.hits, hasLength(1)); + }); + group('with', () { test('offset parameter', () async { var index = await createBooksIndex(); @@ -37,6 +44,42 @@ void main() { var result = await index.search('', limit: 3); expect(result.hits, hasLength(3)); }); + + test('filter parameter', () async { + var index = await createBooksIndex(); + var response = await index + .updateSettings(IndexSettings( + filterableAttributes: ['tag'], + )) + .waitFor(); + expect(response.status, 'processed'); + var result = await index.search('prince', filter: 'tag = Tale'); + expect(result.hits, hasLength(1)); + }); + + test('filter parameter with number', () async { + var index = await createBooksIndex(); + var response = await index + .updateSettings(IndexSettings( + filterableAttributes: ['tag', 'book_id'], + )) + .waitFor(); + expect(response.status, 'processed'); + var result = await index.search('', filter: 'book_id < 100 AND tag = Tale'); + expect(result.hits, hasLength(1)); + }); + + test('facetDistributions parameter', () async { + var index = await createBooksIndex(); + var response = await index + .updateSettings(IndexSettings( + filterableAttributes: ['tag'], + )) + .waitFor(); + expect(response.status, 'processed'); + var result = await index.search('prince', facetsDistribution: ['*']); + expect(result.hits, hasLength(2)); + }); }); }); } diff --git a/test/utils/books.dart b/test/utils/books.dart index 7d6bc5ae..c26e1f90 100644 --- a/test/utils/books.dart +++ b/test/utils/books.dart @@ -3,12 +3,12 @@ import 'package:meilisearch/meilisearch.dart'; import 'client.dart'; var booksDoc = [ - {'book_id': 123, 'title': 'Pride and Prejudice'}, - {'book_id': 456, 'title': 'Le Petit Prince'}, - {'book_id': 1, 'title': 'Alice In Wonderland'}, - {'book_id': 1344, 'title': 'The Hobbit'}, - {'book_id': 4, 'title': 'Harry Potter and the Half-Blood Prince'}, - {'book_id': 42, 'title': 'The Hitchhiker\'s Guide to the Galaxy'} + {'book_id': 123, 'title': 'Pride and Prejudice', 'tag': 'Romance'}, + {'book_id': 456, 'title': 'Le Petit Prince', 'tag': 'Tale'}, + {'book_id': 1, 'title': 'Alice In Wonderland', 'tag': 'Tale'}, + {'book_id': 1344, 'title': 'The Hobbit', 'tag': 'Epic fantasy'}, + {'book_id': 4, 'title': 'Harry Potter and the Half-Blood Prince', 'tag': 'Epic fantasy'}, + {'book_id': 42, 'title': 'The Hitchhiker\'s Guide to the Galaxy', 'tag': 'Epic fantasy'} ]; Future createBooksIndex() async { From 6cd496c2a8b3badf9a2d66e44386be6211e1b068 Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 5 Jul 2021 17:55:30 +0200 Subject: [PATCH 07/12] Fixing Linter --- test/search_test.dart | 27 ++++++++++++++------------- test/utils/books.dart | 12 ++++++++++-- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/test/search_test.dart b/test/search_test.dart index 2e65675e..b4b10676 100644 --- a/test/search_test.dart +++ b/test/search_test.dart @@ -48,10 +48,10 @@ void main() { test('filter parameter', () async { var index = await createBooksIndex(); var response = await index - .updateSettings(IndexSettings( - filterableAttributes: ['tag'], - )) - .waitFor(); + .updateSettings(IndexSettings( + filterableAttributes: ['tag'], + )) + .waitFor(); expect(response.status, 'processed'); var result = await index.search('prince', filter: 'tag = Tale'); expect(result.hits, hasLength(1)); @@ -60,22 +60,23 @@ void main() { test('filter parameter with number', () async { var index = await createBooksIndex(); var response = await index - .updateSettings(IndexSettings( - filterableAttributes: ['tag', 'book_id'], - )) - .waitFor(); + .updateSettings(IndexSettings( + filterableAttributes: ['tag', 'book_id'], + )) + .waitFor(); expect(response.status, 'processed'); - var result = await index.search('', filter: 'book_id < 100 AND tag = Tale'); + var result = + await index.search('', filter: 'book_id < 100 AND tag = Tale'); expect(result.hits, hasLength(1)); }); test('facetDistributions parameter', () async { var index = await createBooksIndex(); var response = await index - .updateSettings(IndexSettings( - filterableAttributes: ['tag'], - )) - .waitFor(); + .updateSettings(IndexSettings( + filterableAttributes: ['tag'], + )) + .waitFor(); expect(response.status, 'processed'); var result = await index.search('prince', facetsDistribution: ['*']); expect(result.hits, hasLength(2)); diff --git a/test/utils/books.dart b/test/utils/books.dart index c26e1f90..91ff0341 100644 --- a/test/utils/books.dart +++ b/test/utils/books.dart @@ -7,8 +7,16 @@ var booksDoc = [ {'book_id': 456, 'title': 'Le Petit Prince', 'tag': 'Tale'}, {'book_id': 1, 'title': 'Alice In Wonderland', 'tag': 'Tale'}, {'book_id': 1344, 'title': 'The Hobbit', 'tag': 'Epic fantasy'}, - {'book_id': 4, 'title': 'Harry Potter and the Half-Blood Prince', 'tag': 'Epic fantasy'}, - {'book_id': 42, 'title': 'The Hitchhiker\'s Guide to the Galaxy', 'tag': 'Epic fantasy'} + { + 'book_id': 4, + 'title': 'Harry Potter and the Half-Blood Prince', + 'tag': 'Epic fantasy' + }, + { + 'book_id': 42, + 'title': 'The Hitchhiker\'s Guide to the Galaxy', + 'tag': 'Epic fantasy' + } ]; Future createBooksIndex() async { From cdd4c7f2c9dffc93202340443103e15c2fd98f07 Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 21 Jul 2021 10:20:31 +0200 Subject: [PATCH 08/12] Add tests and fix filter --- lib/src/index.dart | 3 +-- lib/src/index_impl.dart | 4 +--- test/search_test.dart | 28 ++++++++++++++++++++++++++-- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/src/index.dart b/lib/src/index.dart index cef777da..e932696c 100644 --- a/lib/src/index.dart +++ b/lib/src/index.dart @@ -22,8 +22,7 @@ abstract class MeiliSearchIndex { String? query, { int? offset, int? limit, - String? filter, - // dynamic facetFilters, + dynamic filter, List? facetsDistribution, List? attributesToRetrieve, List? attributesToCrop, diff --git a/lib/src/index_impl.dart b/lib/src/index_impl.dart index a0206655..9a0ded22 100644 --- a/lib/src/index_impl.dart +++ b/lib/src/index_impl.dart @@ -108,8 +108,7 @@ class MeiliSearchIndexImpl implements MeiliSearchIndex { String? query, { int? offset, int? limit, - String? filter, - // dynamic facetFilters, + dynamic filter, List? facetsDistribution, List? attributesToRetrieve, List? attributesToCrop, @@ -122,7 +121,6 @@ class MeiliSearchIndexImpl implements MeiliSearchIndex { 'offset': offset, 'limit': limit, 'filter': filter, - // 'facetFilters': facetFilters, 'facetsDistribution': facetsDistribution, 'attributesToRetrieve': attributesToRetrieve, 'attributesToCrop': attributesToCrop, diff --git a/test/search_test.dart b/test/search_test.dart index b4b10676..66d76b16 100644 --- a/test/search_test.dart +++ b/test/search_test.dart @@ -26,9 +26,9 @@ void main() { expect(result.hits, hasLength(booksDoc.length)); }); - test('with basic query with quote', () async { + test('with basic query with phrase search', () async { var index = await createBooksIndex(); - var result = await index.search('coco \"harry\"'); + var result = await index.search('coco "harry"'); expect(result.hits, hasLength(1)); }); @@ -70,6 +70,30 @@ void main() { expect(result.hits, hasLength(1)); }); + test('filter parameter with array', () async { + var index = await createBooksIndex(); + var response = await index + .updateSettings(IndexSettings( + filterableAttributes: ['tag'], + )) + .waitFor(); + expect(response.status, 'processed'); + var result = await index.search('prince', filter: ['tag = Tale']); + expect(result.hits, hasLength(1)); + }); + + test('filter parameter with multiple array', () async { + var index = await createBooksIndex(); + var response = await index + .updateSettings(IndexSettings( + filterableAttributes: ['tag'], + )) + .waitFor(); + expect(response.status, 'processed'); + var result = await index.search('prince', filter: [['tag = Tale', 'tag = Tale'], 'tag = Tale']); + expect(result.hits, hasLength(1)); + }); + test('facetDistributions parameter', () async { var index = await createBooksIndex(); var response = await index From 7b0a665cd8ca62d55bd0b92416f2f2d074e81966 Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 21 Jul 2021 10:25:11 +0200 Subject: [PATCH 09/12] Fix linter --- test/search_test.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/search_test.dart b/test/search_test.dart index 66d76b16..4e7bdc30 100644 --- a/test/search_test.dart +++ b/test/search_test.dart @@ -90,7 +90,10 @@ void main() { )) .waitFor(); expect(response.status, 'processed'); - var result = await index.search('prince', filter: [['tag = Tale', 'tag = Tale'], 'tag = Tale']); + var result = await index.search('prince', filter: [ + ['tag = Tale', 'tag = Tale'], + 'tag = Tale' + ]); expect(result.hits, hasLength(1)); }); From 8bce5e5dd03dec2bd9cfd46b2a2308b0cc017682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mentine=20Urquizar?= Date: Mon, 2 Aug 2021 12:47:35 +0200 Subject: [PATCH 10/12] Rename attributes for faceting into filterable attributes (#71) --- lib/src/index.dart | 14 +++++++------- lib/src/index_impl.dart | 16 ++++++++-------- test/settings_test.dart | 16 ++++++++-------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/src/index.dart b/lib/src/index.dart index 39595a8d..041217ca 100644 --- a/lib/src/index.dart +++ b/lib/src/index.dart @@ -67,15 +67,15 @@ abstract class MeiliSearchIndex { /// Get the settings of the index. Future getSettings(); - /// Get attributes for faceting of the index. - Future> getAttributesForFaceting(); + /// Get filterable attributes of the index. + Future> getFilterableAttributes(); - /// Reset attributes for faceting of the index. - Future resetAttributesForFaceting(); + /// Reset filterable attributes of the index. + Future resetFilterableAttributes(); - /// Update attriutes for faceting of the index. - Future updateAttributesForFaceting( - List attributesForFaceting); + /// Update filterable attributes of the index. + Future updateFilterableAttributes( + List filterableAttributes); /// Get the displayed attributes of the index. Future> getDisplayedAttributes(); diff --git a/lib/src/index_impl.dart b/lib/src/index_impl.dart index 810551f9..463a3b9e 100644 --- a/lib/src/index_impl.dart +++ b/lib/src/index_impl.dart @@ -242,25 +242,25 @@ class MeiliSearchIndexImpl implements MeiliSearchIndex { } @override - Future> getAttributesForFaceting() async { + Future> getFilterableAttributes() async { final response = - await http.getMethod('/indexes/$uid/settings/attributes-for-faceting'); + await http.getMethod('/indexes/$uid/settings/filterable-attributes'); return (response.data as List).cast(); } @override - Future resetAttributesForFaceting() async { + Future resetFilterableAttributes() async { return await _update( - http.deleteMethod('/indexes/$uid/settings/attributes-for-faceting')); + http.deleteMethod('/indexes/$uid/settings/filterable-attributes')); } @override - Future updateAttributesForFaceting( - List attributesForFaceting) async { + Future updateFilterableAttributes( + List filterableAttributes) async { return await _update(http.postMethod( - '/indexes/$uid/settings/attributes-for-faceting', - data: attributesForFaceting)); + '/indexes/$uid/settings/filterable-attributes', + data: filterableAttributes)); } @override diff --git a/test/settings_test.dart b/test/settings_test.dart index 1b3a17ea..b2b5f95b 100644 --- a/test/settings_test.dart +++ b/test/settings_test.dart @@ -51,19 +51,19 @@ void main() { expect(settings.displayedAttributes, equals(['*'])); }); - test('Getting, setting, and deleting attributes for faceting', () async { + test('Getting, setting, and deleting filterable attributes', () async { final index = await client.createIndex(randomUid()); - final updatedAttributesForFaceting = ['genres', 'director']; + final updatedFilterableAttributes = ['director', 'genres']; var response = await index - .updateAttributesForFaceting(updatedAttributesForFaceting) + .updateFilterableAttributes(updatedFilterableAttributes) .waitFor(); expect(response.status, 'processed'); - var attributesForFaceting = await index.getAttributesForFaceting(); - expect(attributesForFaceting, updatedAttributesForFaceting); - response = await index.resetAttributesForFaceting().waitFor(); + var filterableAttributes = await index.getFilterableAttributes(); + expect(filterableAttributes, updatedFilterableAttributes); + response = await index.resetFilterableAttributes().waitFor(); expect(response.status, 'processed'); - attributesForFaceting = await index.getAttributesForFaceting(); - expect(attributesForFaceting, []); + filterableAttributes = await index.getFilterableAttributes(); + expect(filterableAttributes, []); }); test('Getting, setting, and deleting displayed attributes', () async { From 2575a70ccb90887468ea82fe19bd98216fe61595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mentine=20Urquizar?= Date: Mon, 2 Aug 2021 12:53:16 +0200 Subject: [PATCH 11/12] Fix tests (#72) --- test/get_version_test.dart | 4 ++-- test/settings_test.dart | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/get_version_test.dart b/test/get_version_test.dart index 2a8296c1..812c3283 100644 --- a/test/get_version_test.dart +++ b/test/get_version_test.dart @@ -9,10 +9,10 @@ void main() { test('version is returned from the server', () async { var keys = await client.getVersion(); expect(keys.keys, contains('commitSha')); - expect(keys.keys, contains('buildDate')); + expect(keys.keys, contains('commitDate')); expect(keys.keys, contains('pkgVersion')); expect(keys['commitSha'], isNotEmpty); - expect(keys['buildDate'], isNotEmpty); + expect(keys['commitDate'], isNotEmpty); expect(keys['pkgVersion'], isNotEmpty); }); }); diff --git a/test/settings_test.dart b/test/settings_test.dart index b2b5f95b..844b81c7 100644 --- a/test/settings_test.dart +++ b/test/settings_test.dart @@ -53,7 +53,7 @@ void main() { test('Getting, setting, and deleting filterable attributes', () async { final index = await client.createIndex(randomUid()); - final updatedFilterableAttributes = ['director', 'genres']; + final updatedFilterableAttributes = ['director']; var response = await index .updateFilterableAttributes(updatedFilterableAttributes) .waitFor(); From d35847f7e8ce211b20da3791d8a02b878b8d0c07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mentine=20Urquizar?= Date: Tue, 24 Aug 2021 19:52:59 +0200 Subject: [PATCH 12/12] Update lib/src/index_settings.dart Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- lib/src/index_settings.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/index_settings.dart b/lib/src/index_settings.dart index 17f76e5c..20fb10bf 100644 --- a/lib/src/index_settings.dart +++ b/lib/src/index_settings.dart @@ -20,7 +20,7 @@ class IndexSettings { /// List of ranking rules sorted by order of importance List? rankingRules; - /// Attributes to use as [facets](https://docs.meilisearch.com/reference/features/faceted_search.html) + /// Attributes to use in [filters](https://docs.meilisearch.com/reference/features/filtering_and_faceted_search.html) List? filterableAttributes; /// Search returns documents with distinct (different) values of the given field