Skip to content

Commit bd63492

Browse files
Merge #436
436: Implement `rankingScoreThreshold` as search query parameter r=curquiza a=memishood # Pull Request ## Related issue Fixes #386 ## What does this PR do? - implemented rankingScoreThreshold search parameter ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for filtering search results by a ranking score threshold parameter. * **Tests** * Added a test verifying results respect the configured ranking score threshold. * **Documentation** * Added code samples demonstrating how to use the ranking score threshold in search queries. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Emre Memis <[email protected]> Co-authored-by: Emre <[email protected]>
2 parents e9981d7 + f688fec commit bd63492

File tree

5 files changed

+43
-0
lines changed

5 files changed

+43
-0
lines changed

.code-samples.meilisearch.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,4 @@ reset_separator_tokens_1: await client.index('articles').resetSeparatorTokens();
297297
get_non_separator_tokens_1: await client.index('articles').getNonSeparatorTokens();
298298
update_non_separator_tokens_1: "await client.index('articles').updateNonSeparatorTokens([\"@\", \"#\"]);"
299299
reset_non_separator_tokens_1: await client.index('articles').resetNonSeparatorTokens();
300+
ranking_score_threshold: "await client\n .index('INDEX_NAME')\n .search('badman', SearchQuery(rankingScoreThreshold: 0.2));"

lib/src/query_parameters/index_search_query.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class IndexSearchQuery extends SearchQuery {
3434
super.showRankingScore,
3535
super.vector,
3636
super.showRankingScoreDetails,
37+
super.rankingScoreThreshold,
3738
});
3839

3940
@override
@@ -71,6 +72,7 @@ class IndexSearchQuery extends SearchQuery {
7172
bool? showRankingScore,
7273
List<dynamic /* double | List<double> */ >? vector,
7374
bool? showRankingScoreDetails,
75+
double? rankingScoreThreshold,
7476
}) =>
7577
IndexSearchQuery(
7678
query: query ?? this.query,
@@ -99,5 +101,7 @@ class IndexSearchQuery extends SearchQuery {
99101
vector: vector ?? this.vector,
100102
showRankingScoreDetails:
101103
showRankingScoreDetails ?? this.showRankingScoreDetails,
104+
rankingScoreThreshold:
105+
rankingScoreThreshold ?? this.rankingScoreThreshold,
102106
);
103107
}

lib/src/query_parameters/search_query.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class SearchQuery extends Queryable {
2727
final bool? showRankingScore;
2828
@RequiredMeiliServerVersion('1.3.0')
2929
final bool? showRankingScoreDetails;
30+
@RequiredMeiliServerVersion('1.9.0')
31+
final double? rankingScoreThreshold;
3032
@RequiredMeiliServerVersion('1.3.0')
3133
final List<dynamic /* double | List<double> */ >? vector;
3234

@@ -52,6 +54,7 @@ class SearchQuery extends Queryable {
5254
this.hybrid,
5355
this.showRankingScore,
5456
this.showRankingScoreDetails,
57+
this.rankingScoreThreshold,
5558
this.vector,
5659
});
5760

@@ -78,6 +81,7 @@ class SearchQuery extends Queryable {
7881
'hybrid': hybrid?.toMap(),
7982
'showRankingScore': showRankingScore,
8083
'showRankingScoreDetails': showRankingScoreDetails,
84+
'rankingScoreThreshold': rankingScoreThreshold,
8185
'vector': vector,
8286
};
8387
}
@@ -105,6 +109,7 @@ class SearchQuery extends Queryable {
105109
bool? showRankingScore,
106110
List<dynamic>? vector,
107111
bool? showRankingScoreDetails,
112+
double? rankingScoreThreshold,
108113
}) =>
109114
SearchQuery(
110115
offset: offset ?? this.offset,
@@ -131,5 +136,7 @@ class SearchQuery extends Queryable {
131136
vector: vector ?? this.vector,
132137
showRankingScoreDetails:
133138
showRankingScoreDetails ?? this.showRankingScoreDetails,
139+
rankingScoreThreshold:
140+
rankingScoreThreshold ?? this.rankingScoreThreshold,
134141
);
135142
}

test/code_samples.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,11 @@ void main() {
874874
// #docregion getting_started_search
875875
await client.index('movies').search('botman');
876876
// #enddocregion
877+
// #docregion ranking_score_threshold
878+
await client
879+
.index('INDEX_NAME')
880+
.search('badman', SearchQuery(rankingScoreThreshold: 0.2));
881+
// #enddocregion
877882
});
878883

879884
// skip this test, since it's only used for generating code samples

test/search_test.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,32 @@ void main() {
447447
});
448448
});
449449
});
450+
451+
test('use rankingScoreThreshold', () async {
452+
final res = await index
453+
.search(
454+
'The',
455+
SearchQuery(
456+
showRankingScore: true,
457+
rankingScoreThreshold: 0.9,
458+
),
459+
)
460+
.asSearchResult()
461+
.mapToContainer();
462+
463+
expect(res.hits.length, 3);
464+
465+
expect(
466+
res.hits,
467+
everyElement(
468+
isA<MeiliDocumentContainer<Map<String, dynamic>>>().having(
469+
(p0) => p0.rankingScore,
470+
'rankingScore',
471+
greaterThanOrEqualTo(0.9),
472+
),
473+
),
474+
);
475+
});
450476
});
451477

452478
group('Nested Books', () {

0 commit comments

Comments
 (0)