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

Changes related to the next Meilisearch release (v0.27.0) #150

Merged
merged 6 commits into from
May 9, 2022
Merged
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
16 changes: 14 additions & 2 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ search_parameter_guide_retrieve_1: |-
search_parameter_guide_crop_1: |-
await client
.index('movies')
.search('shifu', attributesToCrop: ['overview'], cropLength: 10);
.search('shifu', attributesToCrop: ['overview'], cropLength: 5);
search_parameter_guide_highlight_1: |-
await client
.index('movies')
Expand Down Expand Up @@ -468,4 +468,16 @@ landing_getting_started_1: |-
{ 'id': 4, 'title': 'Mad Max: Fury Road' },
{ 'id': 5, 'title': 'Moana' },
{ 'id': 6, 'title': 'Philadelphia'}
])
]);
search_parameter_guide_crop_marker_1: |-
await client
.index('movies')
.search('shifu', attributesToCrop: ['overview'], cropMarker: "[…]");
search_parameter_guide_highlight_tag_1: |-
await client
.index('movies')
.search('winter feast',
attributesToHighlight: ['overview'],
highlightPreTag: '<span class="highlight">',
highlightPostTag: '</span>',
);
2 changes: 1 addition & 1 deletion .github/workflows/pre-release-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Get the latest Meilisearch RC
run: echo "MEILISEARCH_VERSION=$(curl https://raw.githubusercontent.com/meilisearch/integration-guides/main/scripts/get-latest-meilisearch-rc.sh | bash)" >> $GITHUB_ENV
- name: Meilisearch (${{ env.MEILISEARCH_VERSION }}) setup with Docker
run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} ./meilisearch --master-key=masterKey --no-analytics
run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} meilisearch --master-key=masterKey --no-analytics
- name: Run integration tests
run: docker run --net="host" -v $PWD:/package -w /package google/dart:${{ matrix.version }} /bin/sh -c 'pub get && pub run test'

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ JSON output:

## 🤖 Compatibility with Meilisearch

This package only guarantees the compatibility with the [version v0.26.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.26.0).
This package only guarantees the compatibility with the [version v0.27.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.27.0).

## 💡 Learn More

Expand Down
3 changes: 3 additions & 0 deletions lib/src/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ abstract class MeiliSearchIndex {
int? cropLength,
List<String>? attributesToHighlight,
bool? matches,
String? cropMarker,
String? highlightPreTag,
String? highlightPostTag,
});

/// Return the document in the index by given [id].
Expand Down
6 changes: 6 additions & 0 deletions lib/src/index_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ class MeiliSearchIndexImpl implements MeiliSearchIndex {
int? cropLength,
List<String>? attributesToHighlight,
bool? matches,
String? cropMarker,
String? highlightPreTag,
String? highlightPostTag,
}) async {
final data = <String, dynamic>{
'q': query,
Expand All @@ -128,6 +131,9 @@ class MeiliSearchIndexImpl implements MeiliSearchIndex {
'cropLength': cropLength,
'attributesToHighlight': attributesToHighlight,
'matches': matches,
'cropMarker': cropMarker,
'highlightPreTag': highlightPreTag,
'highlightPostTag': highlightPostTag,
};
data.removeWhere((k, v) => v == null);
final response = await http.postMethod('/indexes/$uid/search', data: data);
Expand Down
83 changes: 82 additions & 1 deletion test/search_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,34 @@ void main() {
var index = await createBooksIndex();
var result = await index.search('Alice In Wonderland',
attributesToCrop: ["title"], cropLength: 2);
expect(result.hits![0]['_formatted']['title'], equals('Alice In'));
expect(result.hits![0]['_formatted']['title'], equals('Alice In…'));
});

test('searches with default cropping parameters', () async {
var index = await createBooksIndex();
var result = await index.search('prince',
attributesToCrop: ['*'], cropLength: 2);

expect(result.hits![0]['_formatted']['title'], equals('…Petit Prince'));
});

test('searches with custom cropMarker', () async {
var index = await createBooksIndex();
var result = await index.search('prince',
attributesToCrop: ['*'], cropLength: 1, cropMarker: '[…] ');

expect(result.hits![0]['_formatted']['title'], equals('[…] Prince'));
});

test('searches with custom highlight tags', () async {
var index = await createBooksIndex();
var result = await index.search('blood',
attributesToHighlight: ['*'],
highlightPreTag: '<mark>',
highlightPostTag: '</mark>');

expect(result.hits![0]['_formatted']['title'],
equals('Harry Potter and the Half-<mark>Blood</mark> Prince'));
});

test('filter parameter', () async {
Expand Down Expand Up @@ -136,5 +163,59 @@ void main() {
expect(result.hits![0]['book_id'], 4);
});
});

test('searches within nested content with no parameters', () async {
var index = await createNestedBooksIndex();
var response = await index.search('An awesome');

expect(response.hits![0], {
"id": 5,
"title": 'The Hobbit',
"info": {
"comment": 'An awesome book',
"reviewNb": 900,
},
});
});

test('searches on nested content with searchable on specific nested field',
() async {
var index = await createNestedBooksIndex();
await index
.updateSettings(
IndexSettings(searchableAttributes: ['title', 'info.comment']))
.waitFor();

var response = await index.search('An awesome');

expect(response.hits![0], {
"id": 5,
"title": 'The Hobbit',
"info": {
"comment": 'An awesome book',
"reviewNb": 900,
},
});
});

test('searches on nested content with content with sort', () async {
var index = await createNestedBooksIndex();
await index
.updateSettings(IndexSettings(
searchableAttributes: ['title', 'info.comment'],
sortableAttributes: ['info.reviewNb']))
.waitFor();

var response = await index.search('', sort: ['info.reviewNb:desc']);

expect(response.hits![0], {
"id": 6,
"title": 'Harry Potter and the Half-Blood Prince',
"info": {
"comment": 'The best book',
"reviewNb": 1000,
},
});
});
});
}
66 changes: 65 additions & 1 deletion test/utils/books.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,73 @@ var booksDoc = [
}
];

var nestedBooksDoc = [
{
"id": 1,
"title": 'Pride and Prejudice',
"info": {
"comment": 'A great book',
"reviewNb": 500,
},
},
{
"id": 2,
"title": 'Le Petit Prince',
"info": {
"comment": 'A french book',
"reviewNb": 600,
},
},
{
"id": 3,
"title": 'Le Rouge et le Noir',
"info": {
"comment": 'Another french book',
"reviewNb": 700,
},
},
{
"id": 4,
"title": 'Alice In Wonderland',
"comment": 'A weird book',
"info": {
"comment": 'A weird book',
"reviewNb": 800,
},
},
{
"id": 5,
"title": 'The Hobbit',
"info": {
"comment": 'An awesome book',
"reviewNb": 900,
},
},
{
"id": 6,
"title": 'Harry Potter and the Half-Blood Prince',
"info": {
"comment": 'The best book',
"reviewNb": 1000,
},
},
{"id": 7, "title": "The Hitchhiker's Guide to the Galaxy"},
];

Future<MeiliSearchIndex> createBooksIndex({String? uid}) async {
return _createIndex(uid: uid);
}

Future<MeiliSearchIndex> createNestedBooksIndex({String? uid}) async {
return _createIndex(uid: uid, isNested: true);
}

Future<MeiliSearchIndex> _createIndex(
{String? uid, bool isNested = false}) async {
final index = client.index(uid ?? randomUid());
final response = await index.addDocuments(booksDoc).waitFor();
final books = isNested ? nestedBooksDoc : booksDoc;
final response = await index.addDocuments(books).waitFor();

if (response.status != 'succeeded') {
throw Exception(
'Impossible to process test suite, the documents were not added into the index.');
Expand Down