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 (v1.7.0) #375

Merged
merged 7 commits into from
Mar 11, 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
6 changes: 0 additions & 6 deletions lib/src/results/experimental_features.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ part 'experimental_features.g.dart';
class ExperimentalFeatures {
@JsonKey(name: 'vectorStore')
final bool vectorStore;
@JsonKey(name: 'scoreDetails')
final bool scoreDetails;

const ExperimentalFeatures({
required this.vectorStore,
required this.scoreDetails,
});

factory ExperimentalFeatures.fromJson(Map<String, dynamic> src) {
Expand All @@ -34,12 +31,9 @@ class ExperimentalFeatures {
class UpdateExperimentalFeatures {
@JsonKey(name: 'vectorStore')
final bool? vectorStore;
@JsonKey(name: 'scoreDetails')
final bool? scoreDetails;

const UpdateExperimentalFeatures({
this.vectorStore,
this.scoreDetails,
});

Map<String, dynamic> toJson() => _$UpdateExperimentalFeaturesToJson(this);
Expand Down
2 changes: 0 additions & 2 deletions lib/src/results/experimental_features.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

199 changes: 92 additions & 107 deletions test/search_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,98 @@ void main() {
expect(result.hits, hasLength(1));
});

test('Show ranking score details', () 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, 4);

expect(
res.hits,
everyElement(
isA<MeiliDocumentContainer<Map<String, dynamic>>>()
.having(
(p0) => p0.parsed,
'parsed',
isNotEmpty,
)
.having(
(p0) => p0.src,
'src',
isNotEmpty,
)
.having(
(p0) => p0.rankingScore,
'rankingScore',
isNotNull,
)
.having(
(p0) => p0.rankingScoreDetails,
'rankingScoreDetails',
rankingScoreDetailsMatcher,
),
),
);
});

group('with', () {
test('offset parameter', () async {
final result =
Expand Down Expand Up @@ -457,11 +549,9 @@ void main() {
// setUp(() async {
// features = await client.http.updateExperimentalFeatures(
// UpdateExperimentalFeatures(
// scoreDetails: true,
// vectorStore: true,
// ),
// );
// expect(features.scoreDetails, true);
// expect(features.vectorStore, true);

// uid = randomUid();
Expand Down Expand Up @@ -498,111 +588,6 @@ void main() {
// ),
// );
// });

// 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 {
Expand Down
Loading