Skip to content

Commit

Permalink
Add test for showRankingScoreDetails
Browse files Browse the repository at this point in the history
  • Loading branch information
curquiza committed Feb 16, 2024
1 parent df89d74 commit 4d6ca71
Showing 1 changed file with 66 additions and 105 deletions.
171 changes: 66 additions & 105 deletions test/search_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,71 @@ 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);
});

group('with', () {
test('offset parameter', () async {
final result =
Expand Down Expand Up @@ -448,6 +513,7 @@ void main() {
});
});


// Commented because of https://github.com/meilisearch/meilisearch-dart/issues/369
// group('Experimental', () {
// setUpClient();
Expand Down Expand Up @@ -496,111 +562,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

0 comments on commit 4d6ca71

Please sign in to comment.