diff --git a/README.md b/README.md index 873b842a..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', ); ``` @@ -151,7 +150,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 diff --git a/lib/src/index.dart b/lib/src/index.dart index 966cc014..7a9139e3 100644 --- a/lib/src/index.dart +++ b/lib/src/index.dart @@ -26,8 +26,7 @@ abstract class MeiliSearchIndex { String? query, { int? offset, int? limit, - String? filters, - dynamic facetFilters, + dynamic filter, List? facetsDistribution, List? attributesToRetrieve, List? attributesToCrop, @@ -72,15 +71,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 43a65106..c6e4a83f 100644 --- a/lib/src/index_impl.dart +++ b/lib/src/index_impl.dart @@ -110,8 +110,7 @@ class MeiliSearchIndexImpl implements MeiliSearchIndex { String? query, { int? offset, int? limit, - String? filters, - dynamic facetFilters, + dynamic filter, List? facetsDistribution, List? attributesToRetrieve, List? attributesToCrop, @@ -123,8 +122,7 @@ class MeiliSearchIndexImpl implements MeiliSearchIndex { 'q': query, 'offset': offset, 'limit': limit, - 'filters': filters, - 'facetFilters': facetFilters, + 'filter': filter, 'facetsDistribution': facetsDistribution, 'attributesToRetrieve': attributesToRetrieve, 'attributesToCrop': attributesToCrop, @@ -246,25 +244,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/lib/src/index_settings.dart b/lib/src/index_settings.dart index 9bdf916e..20fb10bf 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, @@ -20,8 +20,8 @@ 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) - List? attributesForFaceting; + /// 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 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(), 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/search_test.dart b/test/search_test.dart index f5ca768b..4e7bdc30 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 phrase search', () 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,70 @@ 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('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 + .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/settings_test.dart b/test/settings_test.dart index 1b3a17ea..844b81c7 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']; 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 { diff --git a/test/utils/books.dart b/test/utils/books.dart index 7d6bc5ae..91ff0341 100644 --- a/test/utils/books.dart +++ b/test/utils/books.dart @@ -3,12 +3,20 @@ 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 { diff --git a/test/utils/client.dart b/test/utils/client.dart index 1a20dcc7..c2deb385 100644 --- a/test/utils/client.dart +++ b/test/utils/client.dart @@ -71,7 +71,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);