Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e976081
Update README.md
meili-bot Apr 27, 2021
8bbbacf
Merge branch 'main' into bump-meilisearch-v0.21.0
curquiza May 6, 2021
b47a922
Merge branch 'main' into bump-meilisearch-v0.21.0
curquiza Jun 21, 2021
089a6a8
Merge branch 'main' into bump-meilisearch-v0.21.0
curquiza Jun 24, 2021
22db1b1
Update README
alallema Jul 5, 2021
5db4c40
Merge pull request #60 from meilisearch/update-readme
alallema Jul 5, 2021
4625c6f
Rename attributes_for_faceting into filterable_attributes
alallema Jul 5, 2021
23af865
Merge pull request #61 from meilisearch/filterable_attributes
alallema Jul 5, 2021
4e68078
Adding processing in the condition to check
alallema Jul 5, 2021
033a6f9
Merge pull request #62 from meilisearch/improve-wfpu
alallema Jul 5, 2021
fdc1cea
Rename Filters in Filter and remove FacetFilters
alallema Jul 5, 2021
b72d2db
Merge pull request #63 from meilisearch/filter
alallema Jul 5, 2021
5bd9cc1
Adding test for new features
alallema Jul 5, 2021
6cd496c
Fixing Linter
alallema Jul 5, 2021
0a6c0d5
Merge pull request #64 from meilisearch/add-tests
alallema Jul 5, 2021
cdd4c7f
Add tests and fix filter
alallema Jul 21, 2021
7b0a665
Fix linter
alallema Jul 21, 2021
dccc03f
Merge pull request #65 from meilisearch/add-tests
alallema Jul 21, 2021
ff74a77
Merge branch 'main' into bump-meilisearch-v0.21.0
curquiza Aug 2, 2021
b717cad
Merge branch 'main' into bump-meilisearch-v0.21.0
curquiza Aug 2, 2021
8bce5e5
Rename attributes for faceting into filterable attributes (#71)
curquiza Aug 2, 2021
2575a70
Fix tests (#72)
curquiza Aug 2, 2021
d35847f
Update lib/src/index_settings.dart
curquiza Aug 24, 2021
67a81ad
Merge branch 'main' into bump-meilisearch-v0.21.0
curquiza Aug 24, 2021
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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <!-- omit in toc -->

Expand Down Expand Up @@ -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',
);
```

Expand All @@ -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

Expand Down
17 changes: 8 additions & 9 deletions lib/src/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ abstract class MeiliSearchIndex {
String? query, {
int? offset,
int? limit,
String? filters,
dynamic facetFilters,
dynamic filter,
List<String>? facetsDistribution,
List<String>? attributesToRetrieve,
List<String>? attributesToCrop,
Expand Down Expand Up @@ -72,15 +71,15 @@ abstract class MeiliSearchIndex {
/// Get the settings of the index.
Future<IndexSettings> getSettings();

/// Get attributes for faceting of the index.
Future<List<String>> getAttributesForFaceting();
/// Get filterable attributes of the index.
Future<List<String>> getFilterableAttributes();

/// Reset attributes for faceting of the index.
Future<PendingUpdate> resetAttributesForFaceting();
/// Reset filterable attributes of the index.
Future<PendingUpdate> resetFilterableAttributes();

/// Update attriutes for faceting of the index.
Future<PendingUpdate> updateAttributesForFaceting(
List<String> attributesForFaceting);
/// Update filterable attributes of the index.
Future<PendingUpdate> updateFilterableAttributes(
List<String> filterableAttributes);

/// Get the displayed attributes of the index.
Future<List<String>> getDisplayedAttributes();
Expand Down
22 changes: 10 additions & 12 deletions lib/src/index_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ class MeiliSearchIndexImpl implements MeiliSearchIndex {
String? query, {
int? offset,
int? limit,
String? filters,
dynamic facetFilters,
dynamic filter,
List<String>? facetsDistribution,
List<String>? attributesToRetrieve,
List<String>? attributesToCrop,
Expand All @@ -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,
Expand Down Expand Up @@ -246,25 +244,25 @@ class MeiliSearchIndexImpl implements MeiliSearchIndex {
}

@override
Future<List<String>> getAttributesForFaceting() async {
Future<List<String>> 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<String>();
}

@override
Future<PendingUpdate> resetAttributesForFaceting() async {
Future<PendingUpdate> resetFilterableAttributes() async {
return await _update(
http.deleteMethod('/indexes/$uid/settings/attributes-for-faceting'));
http.deleteMethod('/indexes/$uid/settings/filterable-attributes'));
}

@override
Future<PendingUpdate> updateAttributesForFaceting(
List<String> attributesForFaceting) async {
Future<PendingUpdate> updateFilterableAttributes(
List<String> filterableAttributes) async {
return await _update(http.postMethod(
'/indexes/$uid/settings/attributes-for-faceting',
data: attributesForFaceting));
'/indexes/$uid/settings/filterable-attributes',
data: filterableAttributes));
}

@override
Expand Down
12 changes: 6 additions & 6 deletions lib/src/index_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class IndexSettings {
this.synonyms,
this.stopWords,
this.rankingRules,
this.attributesForFaceting,
this.filterableAttributes,
this.distinctAttribute,
this.searchableAttributes = allAttributes,
this.displayedAttributes = allAttributes,
Expand All @@ -20,8 +20,8 @@ class IndexSettings {
/// List of ranking rules sorted by order of importance
List<String>? rankingRules;

/// Attributes to use as [facets](https://docs.meilisearch.com/reference/features/faceted_search.html)
List<String>? attributesForFaceting;
/// Attributes to use in [filters](https://docs.meilisearch.com/reference/features/filtering_and_faceted_search.html)
List<String>? filterableAttributes;

/// Search returns documents with distinct (different) values of the given field
List<String>? distinctAttribute;
Expand All @@ -36,7 +36,7 @@ class IndexSettings {
'synonyms': synonyms,
'stopWords': stopWords,
'rankingRules': rankingRules,
'attributesForFaceting': attributesForFaceting,
'filterableAttributes': filterableAttributes,
'distinctAttribute': distinctAttribute,
'searchableAttributes': searchableAttributes,
'displayedAttributes': displayedAttributes,
Expand All @@ -48,8 +48,8 @@ class IndexSettings {
.map((key, value) => MapEntry(key, value.cast<String>())),
stopWords: (map['stopWords'] as List?)?.cast<String>(),
rankingRules: (map['rankingRules'] as List?)?.cast<String>(),
attributesForFaceting:
(map['attributesForFaceting'] as List?)?.cast<String>(),
filterableAttributes:
(map['filterableAttributes'] as List?)?.cast<String>(),
distinctAttribute: (map['distinctAttribute'] as List?)?.cast<String>(),
searchableAttributes:
(map['searchableAttributes'] as List?)?.cast<String>(),
Expand Down
4 changes: 2 additions & 2 deletions test/get_version_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down
71 changes: 71 additions & 0 deletions test/search_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:meilisearch/meilisearch.dart';
import 'package:test/test.dart';

import 'utils/books.dart';
Expand Down Expand Up @@ -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();
Expand All @@ -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));
});
Comment on lines +100 to +110
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a test on the returned facetDistribution? To test if no 0 values are present. I'm not sure it is needed but out of curiosity

Copy link
Member

@curquiza curquiza Aug 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a test for the search engine from my POV, plus this test is already present in many SDKs :)

});
});
}
16 changes: 8 additions & 8 deletions test/settings_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 14 additions & 6 deletions test/utils/books.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<MeiliSearchIndex> createBooksIndex() async {
Expand Down
2 changes: 1 addition & 1 deletion test/utils/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down