Skip to content

Commit b3113f7

Browse files
committed
implement rankingScoreThreshold search query parameter
1 parent c2a706c commit b3113f7

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('movies')\n .search('winter feast', SearchQuery(rankingScoreThreshold: 0.9));"

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('movies')
880+
.search('winter feast', SearchQuery(rankingScoreThreshold: 0.9));
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)