From 6837cd0cbdb9b2be92c7c6ddc47d4897ca724469 Mon Sep 17 00:00:00 2001 From: curquiza Date: Fri, 16 Feb 2024 16:14:32 +0100 Subject: [PATCH] Add test for showRankingScoreDetails --- test/search_test.dart | 210 +++++++++++++++++++++--------------------- 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/test/search_test.dart b/test/search_test.dart index 2d736b9..716aa20 100644 --- a/test/search_test.dart +++ b/test/search_test.dart @@ -448,6 +448,111 @@ void main() { }); }); + 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() + .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() + .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() + .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() + .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() + .having((p0) => p0.src, 'src', allOf(isNotNull, isNotEmpty)) + .having((p0) => p0.score, 'score', isNotNull) + .having((p0) => p0.order, 'order', isNotNull); + + final rankingScoreDetailsMatcher = isA() + .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>>() + .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(); @@ -496,111 +601,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() - // .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() - // .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() - // .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() - // .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() - // .having((p0) => p0.src, 'src', allOf(isNotNull, isNotEmpty)) - // .having((p0) => p0.score, 'score', isNotNull) - // .having((p0) => p0.order, 'order', isNotNull); - - // final rankingScoreDetailsMatcher = isA() - // .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>>() - // .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 {