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

Update tests related to the next Meilisearch release (v1.6.0) #368

Merged
merged 5 commits into from
Jan 16, 2024
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ await index.search('wonder', filter: ['id > 1 AND genres = Action']);

This package guarantees compatibility with [version v1.x of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/latest), but some features may not be present. Please check the [issues](https://github.com/meilisearch/meilisearch-dart/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+label%3Aenhancement) for more info.

⚠️ This package is not compatible with the [`vectoreStore` experimental feature](https://www.meilisearch.com/docs/learn/experimental/vector_search) of Meilisearch v1.6.0 and later. More information on this [issue](https://github.com/meilisearch/meilisearch-dart/issues/369).

## 💡 Learn more

The following sections in our main documentation website may interest you:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:

dev_dependencies:
test: ^1.0.0
dart_jsonwebtoken: ^2.3.2
dart_jsonwebtoken: ^2.12.2
lints: ">=2.1.0 <4.0.0"
json_serializable: ^6.7.1
build_runner: ^2.4.6
Expand Down
312 changes: 156 additions & 156 deletions test/search_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:meilisearch/meilisearch.dart';
import 'package:meilisearch/src/results/experimental_features.dart';
import 'package:test/test.dart';

import 'utils/books.dart';
Expand Down Expand Up @@ -449,161 +448,162 @@ void main() {
});
});

group('Experimental', () {
setUpClient();
late String uid;
late MeiliSearchIndex index;
late ExperimentalFeatures features;
setUp(() async {
features = await client.http.updateExperimentalFeatures(
UpdateExperimentalFeatures(
scoreDetails: true,
vectorStore: true,
),
);
expect(features.scoreDetails, true);
expect(features.vectorStore, true);

uid = randomUid();
index = await createIndexWithData(uid: uid, data: vectorBooks);
});

test('vector search', () async {
final vector = [0, 1, 2];
final res = await index
.search(
null,
SearchQuery(
vector: vector,
),
)
.asSearchResult()
.mapToContainer();

expect(res.vector, vector);
expect(
res.hits,
everyElement(
isA<MeiliDocumentContainer<Map<String, dynamic>>>()
.having(
(p0) => p0.vectors,
'vectors',
isNotNull,
)
.having(
(p0) => p0.semanticScore,
'semanticScore',
isNotNull,
),
),
);
});

test('normal search', () async {
final res = await index
.search(
'The',
SearchQuery(
showRankingScore: true,
showRankingScoreDetails: true,
attributesToHighlight: ['*'],
showMatchesPosition: true,
),
)
.asSearchResult()
.mapToContainer();

final attributeMatcher = isA<MeiliRankingScoreDetailsAttributeRule>()
.having((p0) => p0.src, 'src', allOf(isNotNull, isNotEmpty))
.having((p0) => p0.score, 'score', isNotNull)
.having((p0) => p0.order, 'order', isNotNull)
.having((p0) => p0.queryWordDistanceScore, 'queryWordDistanceScore',
isNotNull)
.having((p0) => p0.attributeRankingOrderScore,
'attributeRankingOrderScore', isNotNull);

final wordsMatcher = isA<MeiliRankingScoreDetailsWordsRule>()
.having((p0) => p0.src, 'src', allOf(isNotNull, isNotEmpty))
.having((p0) => p0.score, 'score', isNotNull)
.having((p0) => p0.order, 'order', isNotNull)
.having((p0) => p0.matchingWords, 'matchingWords', isNotNull)
.having((p0) => p0.maxMatchingWords, 'maxMatchingWords', isNotNull);

final exactnessMatcher = isA<MeiliRankingScoreDetailsExactnessRule>()
.having((p0) => p0.src, 'src', allOf(isNotNull, isNotEmpty))
.having((p0) => p0.score, 'score', isNotNull)
.having((p0) => p0.order, 'order', isNotNull)
.having(
(p0) => p0.matchType,
'matchType',
allOf(isNotNull, isNotEmpty),
);

final typoMatcher = isA<MeiliRankingScoreDetailsTypoRule>()
.having((p0) => p0.src, 'src', allOf(isNotNull, isNotEmpty))
.having((p0) => p0.score, 'score', isNotNull)
.having((p0) => p0.order, 'order', isNotNull)
.having((p0) => p0.typoCount, 'typoCount', isNotNull)
.having((p0) => p0.maxTypoCount, 'maxTypoCount', isNotNull);

final proximityMatcher = isA<MeiliRankingScoreDetailsProximityRule>()
.having((p0) => p0.src, 'src', allOf(isNotNull, isNotEmpty))
.having((p0) => p0.score, 'score', isNotNull)
.having((p0) => p0.order, 'order', isNotNull);

final rankingScoreDetailsMatcher = isA<MeiliRankingScoreDetails>()
.having((p0) => p0.src, 'src', allOf(isNotNull, isNotEmpty))
.having((p0) => p0.attribute, 'attribute', attributeMatcher)
.having((p0) => p0.words, 'words', wordsMatcher)
.having((p0) => p0.exactness, 'exactness', exactnessMatcher)
.having((p0) => p0.typo, 'typo', typoMatcher)
.having((p0) => p0.proximity, 'proximity', proximityMatcher)
.having(
(p0) => p0.customRules, 'customRules', allOf(isNotNull, isEmpty));

expect(res.hits.length, 2);

expect(
res.hits,
everyElement(
isA<MeiliDocumentContainer<Map<String, dynamic>>>()
.having(
(p0) => p0.formatted,
'formatted',
allOf(isNotNull, isNotEmpty, contains('id')),
)
.having(
(p0) => p0.matchesPosition,
'matchesPosition',
allOf(isNotNull, isNotEmpty, containsPair('title', isNotEmpty)),
)
.having(
(p0) => p0.parsed,
'parsed',
isNotEmpty,
)
.having(
(p0) => p0.src,
'src',
isNotEmpty,
)
.having(
(p0) => p0.rankingScore,
'rankingScore',
isNotNull,
)
.having(
(p0) => p0.rankingScoreDetails,
'rankingScoreDetails',
rankingScoreDetailsMatcher,
)
.having(
(p0) => p0.vectors, 'vectors', allOf(isNotNull, isNotEmpty))
.having((p0) => p0.semanticScore, 'semanticScore', isNull),
),
);
});
});
// Commented because of https://github.com/meilisearch/meilisearch-dart/issues/369
// group('Experimental', () {
// setUpClient();
// late String uid;
// late MeiliSearchIndex index;
// late ExperimentalFeatures features;
// setUp(() async {
// features = await client.http.updateExperimentalFeatures(
// UpdateExperimentalFeatures(
// scoreDetails: true,
// vectorStore: true,
// ),
// );
// expect(features.scoreDetails, true);
// expect(features.vectorStore, true);

// uid = randomUid();
// index = await createIndexWithData(uid: uid, data: vectorBooks);
// });

// test('vector search', () async {
// final vector = [0, 1, 2];
// final res = await index
// .search(
// null,
// SearchQuery(
// vector: vector,
// ),
// )
// .asSearchResult()
// .mapToContainer();

// expect(res.vector, vector);
// expect(
// res.hits,
// everyElement(
// isA<MeiliDocumentContainer<Map<String, dynamic>>>()
// .having(
// (p0) => p0.vectors,
// 'vectors',
// isNotNull,
// )
// .having(
// (p0) => p0.semanticScore,
// 'semanticScore',
// isNotNull,
// ),
// ),
// );
// });

// test('normal search', () async {
// final res = await index
// .search(
// 'The',
// SearchQuery(
// showRankingScore: true,
// showRankingScoreDetails: true,
// attributesToHighlight: ['*'],
// showMatchesPosition: true,
// ),
// )
// .asSearchResult()
// .mapToContainer();

// final attributeMatcher = isA<MeiliRankingScoreDetailsAttributeRule>()
// .having((p0) => p0.src, 'src', allOf(isNotNull, isNotEmpty))
// .having((p0) => p0.score, 'score', isNotNull)
// .having((p0) => p0.order, 'order', isNotNull)
// .having((p0) => p0.queryWordDistanceScore, 'queryWordDistanceScore',
// isNotNull)
// .having((p0) => p0.attributeRankingOrderScore,
// 'attributeRankingOrderScore', isNotNull);

// final wordsMatcher = isA<MeiliRankingScoreDetailsWordsRule>()
// .having((p0) => p0.src, 'src', allOf(isNotNull, isNotEmpty))
// .having((p0) => p0.score, 'score', isNotNull)
// .having((p0) => p0.order, 'order', isNotNull)
// .having((p0) => p0.matchingWords, 'matchingWords', isNotNull)
// .having((p0) => p0.maxMatchingWords, 'maxMatchingWords', isNotNull);

// final exactnessMatcher = isA<MeiliRankingScoreDetailsExactnessRule>()
// .having((p0) => p0.src, 'src', allOf(isNotNull, isNotEmpty))
// .having((p0) => p0.score, 'score', isNotNull)
// .having((p0) => p0.order, 'order', isNotNull)
// .having(
// (p0) => p0.matchType,
// 'matchType',
// allOf(isNotNull, isNotEmpty),
// );

// final typoMatcher = isA<MeiliRankingScoreDetailsTypoRule>()
// .having((p0) => p0.src, 'src', allOf(isNotNull, isNotEmpty))
// .having((p0) => p0.score, 'score', isNotNull)
// .having((p0) => p0.order, 'order', isNotNull)
// .having((p0) => p0.typoCount, 'typoCount', isNotNull)
// .having((p0) => p0.maxTypoCount, 'maxTypoCount', isNotNull);

// final proximityMatcher = isA<MeiliRankingScoreDetailsProximityRule>()
// .having((p0) => p0.src, 'src', allOf(isNotNull, isNotEmpty))
// .having((p0) => p0.score, 'score', isNotNull)
// .having((p0) => p0.order, 'order', isNotNull);

// final rankingScoreDetailsMatcher = isA<MeiliRankingScoreDetails>()
// .having((p0) => p0.src, 'src', allOf(isNotNull, isNotEmpty))
// .having((p0) => p0.attribute, 'attribute', attributeMatcher)
// .having((p0) => p0.words, 'words', wordsMatcher)
// .having((p0) => p0.exactness, 'exactness', exactnessMatcher)
// .having((p0) => p0.typo, 'typo', typoMatcher)
// .having((p0) => p0.proximity, 'proximity', proximityMatcher)
// .having(
// (p0) => p0.customRules, 'customRules', allOf(isNotNull, isEmpty));

// expect(res.hits.length, 2);

// expect(
// res.hits,
// everyElement(
// isA<MeiliDocumentContainer<Map<String, dynamic>>>()
// .having(
// (p0) => p0.formatted,
// 'formatted',
// allOf(isNotNull, isNotEmpty, contains('id')),
// )
// .having(
// (p0) => p0.matchesPosition,
// 'matchesPosition',
// allOf(isNotNull, isNotEmpty, containsPair('title', isNotEmpty)),
// )
// .having(
// (p0) => p0.parsed,
// 'parsed',
// isNotEmpty,
// )
// .having(
// (p0) => p0.src,
// 'src',
// isNotEmpty,
// )
// .having(
// (p0) => p0.rankingScore,
// 'rankingScore',
// isNotNull,
// )
// .having(
// (p0) => p0.rankingScoreDetails,
// 'rankingScoreDetails',
// rankingScoreDetailsMatcher,
// )
// .having(
// (p0) => p0.vectors, 'vectors', allOf(isNotNull, isNotEmpty))
// .having((p0) => p0.semanticScore, 'semanticScore', isNull),
// ),
// );
// });
// });

test('search code samples', () async {
// #docregion search_get_1
Expand Down