-
Notifications
You must be signed in to change notification settings - Fork 55
/
.code-samples.meilisearch.yaml
784 lines (765 loc) · 30.7 KB
/
.code-samples.meilisearch.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
# This code-samples file is used by the Meilisearch documentation
# Every example written here will be automatically fetched by
# the documentation on build
# You can read more on https://github.com/meilisearch/documentation/tree/master/.vuepress/code-samples
---
getting_started_faceting: |-
var faceting = new Faceting {
MaxValuesPerFacet = 2
};
await client.Index("movies").UpdateFacetingAsync(faceting);
getting_started_pagination: |-
var pagination = new Pagination {
MaxTotalHits = 500
};
await client.Index("movies").UpdatePaginationAsync(pagination);
synonyms_guide_1: |-
var synonyms = new Dictionary<string, IEnumerable<string>>
{
{ "great", new string[] { "fantastic" } },
{ "fantastic", new string[] { "great" } }
};
await client.Index("movies").UpdateSynonymsAsync(synonyms);
date_guide_index_1: |-
string jsonString = await File.ReadAllTextAsync("games.json");
var games = JsonSerializer.Deserialize<IEnumerable<Movie>>(jsonString, options);
var index = client.Index("games");
await index.AddDocumentsAsync<Movie>(games);
date_guide_filterable_attributes_1: |-
await client.Index("games").UpdateFilterableAttributesAsync(new string[] { "release_timestamp" });
date_guide_filter_1: |-
var filters = new SearchQuery() { Filter = "release_timestamp >= 1514761200 AND release_timestamp < 1672527600" };
SearchResult<Game> games = await client.Index("games").SearchAsync<Game>("", filters);
date_guide_sortable_attributes_1: |-
await client.Index("games").UpdateSortableAttributesAsync(new string[] { "release_timestamp" });
date_guide_sort_1: |-
SearchQuery sort = new SearchQuery() { Sort = new string[] { "release_timestamp:desc" }};
await client.Index("games").SearchAsync<Game>("", sort);
filtering_guide_nested_1: |-
var filters = new SearchQuery() { Filter = "rating.users >= 90" };
SearchResult<MovieRating> movies = await client.Index("movie_ratings").SearchAsync<MovieRating>("thriller", filters);
sorting_guide_sort_nested_1: |-
SearchQuery sort = new SearchQuery() { Sort = new string[] { "rating.users:asc" }};
await client.Index("books").SearchAsync<Book>("science fiction", sort);
async_guide_filter_by_date_1: |-
await client.GetTasksAsync(new TasksQuery { AfterEnqueuedAt = DateTime.Parse("2020-10-11T11:49:53.000Z") });
async_guide_multiple_filters_1: |-
var query = new TasksQuery { IndexUids = new List<string> { "movies" }, Types = new List<TaskInfo> { TaskInfo.DocumentAdditionOrUpdate, TaskInfo.DocumentDeletion }, Statuses = new List<TaskInfoStatus> { TaskInfoStatus.Processing } };
await client.GetTasksAsync(query);
async_guide_filter_by_ids_1: |-
await client.GetTasksAsync(new TasksQuery { Uids = new List<int> { 5, 10, 13 } });
async_guide_filter_by_statuses_1: |-
await client.GetTasksAsync(new TasksQuery { Statuses = new List<TaskInfoStatus> { TaskInfoStatus.Failed, TaskInfoStatus.Canceled } });
async_guide_filter_by_types_1: |-
await client.GetTasksAsync(new TasksQuery { Types = new List<TaskInfoType> { TaskInfoType.DumpCreation, TaskInfoType.IndexSwap } });
async_guide_filter_by_index_uids_1: |-
await client.GetTasksAsync(new TasksQuery { IndexUids = new List<string> { "movies" } });
delete_tasks_1: |-
await client.DeleteTasksAsync(new DeleteTasksQuery { Uids = new List<int> { 1, 2 } });
cancel_tasks_1: |-
await client.CancelTasksAsync(new CancelTasksQuery { Uids = new List<int> { 1, 2 } });
async_guide_canceled_by_1: |-
await client.GetTasksAsync(new TasksQuery { CanceledBy = new List<int> { 9, 15 } });
swap_indexes_1: |-
await client.SwapIndexesAsync(new List<IndexSwap> { new IndexSwap("indexA", "indexB"), new IndexSwap("indexX", "indexY") } });
search_parameter_guide_hitsperpage_1: |-
await client.Index("movies").SearchAsync<Movie>("", new SearchQuery { HitsPerPage = 15 });
search_parameter_guide_page_1: |-
await client.Index("movies").SearchAsync<Movie>("", new SearchQuery { Page = 2 });
get_one_index_1: |-
await client.GetIndexAsync("movies");
list_all_indexes_1: |-
await client.GetAllIndexesAsync(new IndexesQuery { Limit = 3 });
create_an_index_1: |-
TaskInfo task = await client.CreateIndexAsync("movies", "id");
update_an_index_1: |-
TaskInfo task = await client.UpdateIndexAsync("movies", "id");
delete_an_index_1: |-
await client.DeleteIndexAsync("movies");
get_one_document_1: |-
await client.Index("movies").GetDocumentAsync<Movie>(25684, new List<string> { "id", "title", "poster", "release_date" });
get_documents_1: |-
await client.Index("movies").GetDocumentsAsync<Movie>(new DocumentsQuery() { Limit = 2, Filter = "genres = action" });
get_documents_post_1: |-
await client.Index("movies").GetDocumentsAsync<Movie>(new DocumentsQuery() {
Limit = 3,
Fields = new List<string> { "title", "genres", "rating", "language"},
Filter = "(rating > 3 AND (genres=Adventure OR genres=Fiction)) AND language=English"
});
add_or_replace_documents_1: |-
var movie = new[]
{
new Movie
{
Id = "287947",
Title = "Shazam",
Poster = "https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg",
Overview = "A boy is given the ability to become an adult superhero in times of need with a single magic word.",
ReleaseDate = "2019-03-23"
}
};
await index.AddDocumentsAsync(movie);
add_or_update_documents_1: |-
var movie = new[]
{
new Movie { Id = "287947", Title = "Shazam ⚡️", Genres = "comedy" }
};
await index.UpdateDocumentsAsync(movie);
delete_all_documents_1: |-
await client.Index("movies").DeleteAllDocumentsAsync();
delete_one_document_1: |-
await client.Index("movies").DeleteOneDocumentAsync("25684");
delete_documents_by_batch_1: |-
await client.Index("movies").DeleteDocumentsAsync(new[] { "23488", "153738", "437035", "363869" });
delete_documents_by_filter_1: |-
await client.Index("movies").DeleteDocumentsAsync(new DeleteDocumentsQuery() { Filter = "genres = action OR genres = adventure" });
search_post_1: |-
await client.Index("movies").SearchAsync<Movie>("American ninja");
get_task_1: |
TaskInfo task = await client.GetTaskAsync(1);
get_all_tasks_1: |
ResourceResults<Task> taskResult = await client.GetTasksAsync();
get_settings_1: |-
await client.Index("movies").GetSettingsAsync();
update_settings_1: |-
Settings newSettings = new Settings
{
RankingRules = new string[]
{
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
"release_date:desc",
"rank:desc"
},
DistinctAttribute = "movie_id",
SearchableAttributes = new string[] { "title", "overview", "genres" },
DisplayedAttributes = new string[] { "title", "overview", "genres", "release_date" },
SortableAttributes = new string[] { "title", "release_date" },
StopWords = new string[] { "the", "a", "an" },
Synonyms = new Dictionary<string, IEnumerable<string>>
{
{ "wolverine", new string[] { "xmen", "logan" } },
{ "logan", new string[] { "wolverine" } },
},
FilterableAttributes = new string[] { },
TypoTolerance = new TypoTolerance
{
DisableOnAttributes = new string[] { "title" },
MinWordSizeForTypos = new TypoTolerance.TypoSize
{
OneTypo = 8,
TwoTypos = 10
}
}
};
TaskInfo task = await client.Index("movies").UpdateSettingsAsync(newFilters);
reset_settings_1: |-
await client.Index("movies").ResetSettingsAsync();
get_synonyms_1: |-
await client.Index("movies").GetSynonymsAsync();
update_synonyms_1: |-
var synonyms = new Dictionary<string, IEnumerable<string>>
{
{ "wolverine", new string[] { "xmen", "logan" } },
{ "logan", new string[] { "wolverine", "xmen" } },
{ "wow", new string[] { "world of warcraft" } }
};
await client.Index("movies").UpdateSynonymsAsync(synonyms);
reset_synonyms_1: |-
await client.Index("movies").ResetSynonymsAsync();
get_stop_words_1: |-
await client.Index("movies").GetStopWordsAsync();
update_stop_words_1: |-
await client.Index("movies").UpdateStopWordsAsync(new[] {"of", "the", "to"});
reset_stop_words_1: |-
await client.Index("movies").ResetStopWordsAsync();
get_separator_tokens_1: |-
await client.Index("movies").GetSeparatorTokensAsync();
update_separator_tokens_1: |-
await client.Index("movies").UpdateSeparatorTokensAsync(new[] { "|", "…" });
reset_separator_tokens_1: |-
await client.Index("movies").ResetSeparatorTokensAsync();
get_non_separator_tokens_1: |-
await client.Index("movies").GetNonSeparatorTokensAsync();
update_non_separator_tokens_1: |-
await client.Index("movies").UpdateNonSeparatorTokensAsync(new[] { "@", "#" });
reset_non_separator_tokens_1: |-
await client.Index("movies").ResetNonSeparatorTokensAsync();
get_ranking_rules_1: |-
await client.Index("movies").GetRankingRulesAsync();
update_ranking_rules_1: |-
await client.Index("movies").UpdateRankingRulesAsync(new[]
{
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
"release_date:asc",
"rank:desc"
});
reset_ranking_rules_1: |-
await client.Index("movies").ResetRankingRulesAsync();
get_distinct_attribute_1: |-
string result = await client.Index("shoes").GetDistinctAttributeAsync();
update_distinct_attribute_1: |-
TaskInfo result = await client.Index("shoes").UpdateDistinctAttributeAsync("skuid");
reset_distinct_attribute_1: |-
TaskInfo result = await client.Index("shoes").ResetDistinctAttributeAsync();
get_searchable_attributes_1: |-
await client.Index("movies").GetSearchableAttributesAsync();
update_searchable_attributes_1: |-
await client.Index("movies").UpdateSearchableAttributesAsync(new[] {"title", "overview", "genres"});
reset_searchable_attributes_1: |-
await client.Index("movies").ResetSearchableAttributesAsync();
get_filterable_attributes_1: |-
IEnumerable<string> attributes = await client.Index("movies").GetFilterableAttributesAsync();
update_filterable_attributes_1: |-
List<string> attributes = new() { "genres", "director" };
TaskInfo result = await client.Index("movies").UpdateFilterableAttributesAsync(attributes);
reset_filterable_attributes_1: |-
TaskInfo result = await client.Index("movies").ResetFilterableAttributesAsync();
get_displayed_attributes_1: |-
await client.Index("movies").GetDisplayedAttributesAsync();
update_displayed_attributes_1: |-
await client.Index("movies").UpdateDisplayedAttributesAsync(new[]
{
"title",
"overview",
"genres",
"release_date"
});
reset_displayed_attributes_1: |-
await client.Index("movies").ResetDisplayedAttributesAsync();
get_index_stats_1: |-
await client.Index("movies").GetStatsAsync();
get_indexes_stats_1: |-
await client.GetStatsAsync();
get_health_1: |-
await client.HealthAsync();
get_version_1: |-
await client.GetVersionAsync();
distinct_attribute_guide_1: |-
await client.Index("jackets").UpdateDistinctAttributeAsync("product_id");
field_properties_guide_searchable_1: |-
await client.Index("movies").UpdateSearchableAttributesAsync(new[]
{
"title",
"overview",
"genres"
});
field_properties_guide_displayed_1: |-
await client.Index("movies").UpdateDisplayedAttributesAsync(new[]
{
"title",
"overview",
"genres",
"release_date"
});
filtering_guide_1: |-
SearchQuery filters = new SearchQuery() { Filter = "release_date > \"795484800\"" };
SearchResult<Movie> movies = await client.Index("movie_ratings").SearchAsync<Movie>("Avengers", filters);
filtering_guide_2: |-
SearchQuery filters = new SearchQuery() { Filter = "release_date > 795484800 AND (director =
\"Tim Burton\" OR director = \"Christopher Nolan\")" };
SearchResult<Movie> movies = await client.Index("movie_ratings").SearchAsync<Movie>("Batman", filters);
filtering_guide_3: |-
SearchQuery filters = new SearchQuery() { Filter = "release_date > 1577884550 AND (NOT director = \"Tim Burton\")" };
SearchResult<Movie> movies = await client.Index("movie_ratings").SearchAsync<Movie>("Planet of the Apes", filters);
search_parameter_guide_query_1: |-
await client.Index("movies").SearchAsync<Movie>("shifu");
search_parameter_guide_offset_1: |-
var sq = new SearchQuery
{
Offset = 1
};
await client.Index("movies").SearchAsync<Movie>("shifu", sq);
search_parameter_guide_limit_1: |-
var sq = new SearchQuery
{
Limit = 2
};
await client.Index("movies").SearchAsync<Movie>("shifu", sq);
search_parameter_guide_retrieve_1: |-
var sq = new SearchQuery
{
AttributesToRetrieve = new[] {"overview", "title"}
};
await client.Index("movies").SearchAsync<Movie>("shifu", sq);
search_parameter_guide_crop_1: |-
var sq = new SearchQuery
{
AttributesToCrop = new[] {"overview"},
CropLength = 5
};
await client.Index("movies").SearchAsync<Movie>("shifu", sq);
search_parameter_guide_crop_marker_1: |-
var sq = new SearchQuery
{
AttributesToCrop = new[] {"overview"},
CropMarker = "[...]"
};
await client.Index("movies").SearchAsync<Movie>("shifu", sq);
search_parameter_guide_highlight_1: |-
var sq = new SearchQuery
{
AttributesToHighlight = new[] {"overview"}
};
await client.Index("movies").SearchAsync<Movie>("winter feast", sq);
search_parameter_guide_highlight_tag_1: |-
var sq = new SearchQuery
{
AttributesToHighlight = new[] {"overview"},
HighlightPreTag = "<span class=\"highlight\">",
HighlightPostTag = "</span>"
};
await client.Index("movies").SearchAsync<Movie>("winter feast", sq);
search_parameter_guide_show_matches_position_1: |-
await client.Index("movies").SearchAsync<T>(
"winter feast",
new SearchQuery
{
ShowMatchesPosition = True,
});
search_parameter_guide_attributes_to_search_on_1: |-
var searchQuery = new SearchQuery
{
AttributesToSearchOn = new[] { "overview" }
};
await client.Index("movies").SearchAsync<Movie>("adventure", searchQuery);
search_parameter_guide_facet_stats_1: |-
var sq = new SearchQuery
{
Facets = new string[] { "genres", "rating" }
};
await client.Index("movie_ratings").SearchAsync<Movie>("Batman", sq);
getting_started_add_documents_md: |-
```bash
dotnet add package Meilisearch
```
```csharp
using System.IO;
using System.Text.Json;
using Meilisearch;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace Meilisearch_demo
{
public class Movie
{
public string Id { get; set; }
public string Title { get; set; }
public string Poster { get; set; }
public string Overview { get; set; }
public IEnumerable<string> Genres { get; set; }
}
internal class Program
{
static async Task Main(string[] args)
{
MeilisearchClient client = new MeilisearchClient("http://localhost:7700", "aSampleMasterKey");
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};
string jsonString = await File.ReadAllTextAsync("movies.json");
var movies = JsonSerializer.Deserialize<IEnumerable<Movie>>(jsonString, options);
var index = client.Index("movies");
await index.AddDocumentsAsync<Movie>(movies);
}
}
}
```
[About this SDK](https://www.github.com/meilisearch/meilisearch-dotnet)
getting_started_check_task_status: |-
TaskInfo task = await client.GetTaskAsync(0);
getting_started_search_md: |-
```csharp
MeilisearchClient client = new MeilisearchClient("http://localhost:7700", "masterKey");
var index = client.Index("movies");
SearchResult<Movie> movies = await index.SearchAsync<Movie>("botman");
foreach (var movie in movies.Hits)
{
Console.WriteLine(movie.Title);
}
```
[About this SDK](https://www.github.com/meilisearch/meilisearch-dotnet)
getting_started_add_meteorites: |-
MeilisearchClient client = new MeilisearchClient("http://localhost:7700", "masterKey");
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};
string jsonString = await File.ReadAllTextAsync("meteorites.json");
var meteorites = JsonSerializer.Deserialize<IEnumerable<Meteorite>>(jsonString, options);
var index = client.Index("meteorites");
await index.AddDocumentsAsync<Meteorite>(meteorites);
getting_started_update_ranking_rules: |-
await client.Index("movies").UpdateRankingRulesAsync(new string[] {
"exactness",
"words",
"typo",
"proximity",
"attribute",
"sort",
"release_date:asc",
"rank:desc"
});
getting_started_update_displayed_attributes: |-
await client.Index("movies").UpdateDisplayedAttributesAsync(new string[] {
"title",
"overview",
"poster"
});
getting_started_update_searchable_attributes: |-
await client.Index("movies").UpdateSearchableAttributesAsync(new string[] {
"title"
});
getting_started_update_stop_words: |-
await client.Index("movies").UpdateStopWordsAsync(new string[] {
"the"
});
getting_started_synonyms: |-
var newSynonyms = new Dictionary<string, IEnumerable<string>>
{
{ "winnie", new string[] { "piglet" } },
{ "piglet", new string[] { "winnie" } },
};
await client.Index("movies").UpdateSynonymsAsync(newSynonyms);
getting_started_filtering: |-
SearchQuery filter = new SearchQuery() { Filter = "mass < 200" };
await client.Index("meteorites").SearchAsync<Meteorite>("", filter);
getting_started_geo_radius: |-
SearchQuery filter = new SearchQuery() { Filter = "_geoRadius(46.9480, 7.4474, 210000)" };
await client.Index("meteorites").SearchAsync<Meteorite>("", filter);
getting_started_geo_point: |-
SearchQuery sort = new SearchQuery() { Sort = new string[] { "_geoPoint(48.8583701,2.2922926):asc" }};
await client.Index("meteorites").SearchAsync<Meteorite>("", sort);
getting_started_sorting: |-
SearchQuery searchQuery = new SearchQuery() {
Sort = new string[] { "mass:asc" },
Filter = "mass < 200",
};
await client.Index("meteorites").SearchAsync<Meteorite>("", searchQuery);
getting_started_configure_settings: |-
var newSettings = new Settings
{
FilterableAttributes = new string[] { "mass", "_geo" },
SortableAttributes = new string[] { "mass", "_geo" },
};
await client.Index("meteorites").UpdateSettingsAsync(newSettings);
filtering_update_settings_1: |-
await client.Index("movies").UpdateFilterableAttributesAsync(new [] { "director", "genres" });
faceted_search_walkthrough_filter_1: |-
var sq = new SearchQuery
{
Filter = "(genre = 'Horror' AND genre = 'Mystery') OR director = 'Jordan Peele'"
};
await client.Index("movies").SearchAsync<Movie>("thriller", sq);
faceted_search_update_settings_1: |-
List<string> attributes = new() { "genres", "rating", "language" };
TaskInfo result = await client.Index("movie_ratings").UpdateFilterableAttributesAsync(attributes);
faceted_search_1: |-
var sq = new SearchQuery
{
Facets = new string[] { "genres", "rating", "language" }
};
await client.Index("books").SearchAsync<Book>("classic", sq);
add_movies_json_1: |-
// Make sure to add this using to your code
using System.IO;
var jsonDocuments = await File.ReadAllTextAsync("movies.json");
await client.Index("movies").AddDocumentsJsonAsync(jsonDocuments);
landing_getting_started_1: |-
MeilisearchClient client = new MeilisearchClient("http://localhost:7700", "masterKey");
var documents = new Movie[] {
new Movie { Id = "1", Title = "Carol" },
new Movie { Id = "2", Title = "Wonder Woman" },
new Movie { Id = "3", Title = "Life of Pi" },
new Movie { Id = "4", Title = "Mad Max: Fury Road" },
new Movie { Id = "5", Title = "Moana", ", "Action" },
new Movie { Id = "6", Title = "Philadelphia" }
};
var task = await client.Index("movies").AddDocumentsAsync<Movie>(documents);
post_dump_1: |-
await client.CreateDumpAsync();
phrase_search_1: |-
await client.Index("movies").SearchAsync<Movie>("\"african american\" horror");
sorting_guide_update_sortable_attributes_1: |-
await client.Index("books").UpdateSortableAttributesAsync(new [] { "price", "author" });
sorting_guide_update_ranking_rules_1: |-
await client.Index("books").UpdateRankingRulesAsync(new[]
{
"words",
"sort",
"typo",
"proximity",
"attribute",
"exactness"
});
sorting_guide_sort_parameter_1: |-
var sq = new SearchQuery
{
Sort = new[] { "price:asc" },
};
await client.Index("books").SearchAsync<Book>("science fiction", sq);
sorting_guide_sort_parameter_2: |-
var sq = new SearchQuery
{
Sort = new[] { "author:desc" },
};
await client.Index("books").SearchAsync<Book>("butler", sq);
get_sortable_attributes_1: |-
await client.Index("books").GetSortableAttributesAsync();
update_sortable_attributes_1: |-
await client.Index("books").UpdateSortableAttributesAsync(new [] { "price", "author" });
reset_sortable_attributes_1: |-
await client.Index("books").ResetSortableAttributesAsync();
search_parameter_guide_sort_1: |-
var sq = new SearchQuery
{
Sort = new[] { "price:asc" },
};
await client.Index("books").SearchAsync<Book>("science fiction", sq);
geosearch_guide_filter_settings_1: |-
List<string> attributes = new() { "_geo" };
TaskInfo result = await client.Index("movies").UpdateFilterableAttributesAsync(attributes);
geosearch_guide_filter_usage_1: |-
SearchQuery filters = new SearchQuery() { Filter = "_geoRadius(45.472735, 9.184019, 2000)" };
SearchResult<Restaurant> restaurants = await client.Index("restaurants").SearchAsync<Restaurant>("", filters);
geosearch_guide_filter_usage_2: |-
SearchQuery filters = new SearchQuery()
{
Filter = new string[] { "_geoRadius(45.472735, 9.184019, 2000) AND type = pizza" }
};
SearchResult<Restaurant> restaurants = await client.Index("restaurants").SearchAsync<Restaurant>("restaurants", filters);
geosearch_guide_sort_settings_1: |-
List<string> attributes = new() { "_geo" };
TaskInfo result = await client.Index("restaurants").UpdateSortableAttributesAsync(attributes);
geosearch_guide_sort_usage_1: |-
SearchQuery filters = new SearchQuery()
{
Sort = new string[] { "_geoPoint(48.8561446,2.2978204):asc" }
};
SearchResult<Restaurant> restaurants = await client.Index("restaurants").SearchAsync<Restaurant>("", filters);
geosearch_guide_sort_usage_2: |-
SearchQuery filters = new SearchQuery()
{
Sort = new string[] {
"_geoPoint(48.8561446,2.2978204):asc",
"rating:desc"
}
};
SearchResult<Restaurant> restaurants = await client.Index("restaurants").SearchAsync<Restaurant>("restaurants", filters);
geosearch_guide_filter_usage_3: |-
SearchQuery filters = new SearchQuery()
{
Filter = "_geoBoundingBox([45.494181, 9.214024], [45.449484, 9.179175])"
};
SearchResult<Restaurant> restaurants = await client.Index("restaurants").SearchAsync<Restaurant>("restaurants", filters);
primary_field_guide_create_index_primary_key: |-
TaskInfo task = await client.CreateIndexAsync("books", "reference_number");
primary_field_guide_update_document_primary_key: |-
TaskInfo task = await client.UpdateIndexAsync("books", "title");
primary_field_guide_add_document_primary_key: |-
await index.AddDocumentsAsync(
new[] {
new Book {
ReferenceNumber = 287947,
Title = "Diary of a Wimpy Kid",
Author = "Jeff Kinney",
Genres = new string[] { "comedy", "humor" },
Price = 5.00
}
},
"reference_number");
authorization_header_1: |-
MeilisearchClient client = new MeilisearchClient("http://localhost:7700", "masterKey");
var keys = await client.GetKeysAsync();
get_one_key_1: |-
Key key = await client.GetKeyAsync("d0552b41536279a0ad88bd595327b96f01176a60c2243e906c52ac02375f9bc4");
get_all_keys_1: |-
ResourceResults<Key> keyResult = await client.GetKeysAsync(new KeysQuery { Limit = 3 });
create_a_key_1: |-
Key keyOptions = new Key
{
Description = "Add documents: Products API key",
Actions = new KeyAction[] { KeyAction.DocumentsAdd },
Indexes = new string[] { "products" },
ExpiresAt = DateTime.Parse("2042-04-02T00:42:42Z")
};
Key createdKey = await this.client.CreateKeyAsync(keyOptions);
update_a_key_1: |-
await client.UpdateKeyAsync(
"6062abda-a5aa-4414-ac91-ecd7944c0f8d",
description: "Manage documents: Products/Reviews API key",
name: "Products/Reviews API key"
)
delete_a_key_1: |-
client.DeleteKeyAsync("6062abda-a5aa-4414-ac91-ecd7944c0f8d")
security_guide_search_key_1: |-
MeilisearchClient client = new MeilisearchClient("http://localhost:7700", "apiKey");
SearchResult<Patient> searchResult = await client.Index("patient_medical_records").SearchAsync<Patient>();
security_guide_update_key_1: |-
MeilisearchClient client = new MeilisearchClient("http://localhost:7700", "masterKey");
await client.UpdateKeyAsync("74c9c733-3368-4738-bbe5-1d18a5fecb37", description: "Default Search API Key");
security_guide_create_key_1: |-
MeilisearchClient client = new MeilisearchClient("http://localhost:7700", "masterKey");
Key keyOptions = new Key
{
Description = "Search patient records key",
Actions = new string[] { "search" },
Indexes = new string[] { "patient_medical_records" },
ExpiresAt = DateTime.Parse("2023-01-01T00:00:00Z")
};
Key createdKey = await this.client.CreateKeyAsync(keyOptions);
security_guide_list_keys_1: |-
MeilisearchClient client = new MeilisearchClient("http://localhost:7700", "masterKey");
ResourceResults<Key> keyResult = await client.GetKeysAsync();
var keys = keyResult.Result;
security_guide_delete_key_1: |-
MeilisearchClient client = new MeilisearchClient("http://localhost:7700", "masterKey");
client.DeleteKeyAsync("ac5cd97d-5a4b-4226-a868-2d0eb6d197ab")
tenant_token_guide_generate_sdk_1: |-
var apiKey = "B5KdX2MY2jV6EXfUs6scSfmC...";
var expiresAt = new DateTime(2025, 12, 20);
var searchRules = new TenantTokenRules(new Dictionary<string, object> {
{ "patient_medical_records", new Dictionary<string, object> { { "filter", "user_id = 1" } } }
});
token = client.GenerateTenantToken(
searchRules,
apiKey: apiKey // optional,
expiresAt: expiresAt // optional
);
tenant_token_guide_search_sdk_1: |-
frontEndClient = new MeilisearchClient("http://localhost:7700", token);
SearchResult<Patient> searchResult = await frontEndClient.Index("patient_medical_records").SearchAsync<Patient>("blood test");
getting_started_typo_tolerance: |-
var typoTolerance = new TypoTolerance {
MinWordSizeTypos = new TypoTolerance.TypoSize {
OneTypo = 4
}
};
await client.Index("movies").UpdateTypoToleranceAsync(typoTolerance);
get_typo_tolerance_1: await client.Index("books").GetTypoToleranceAsync();
update_typo_tolerance_1: |-
var typoTolerance = new TypoTolerance {
DisableOnAttributes = new string[] { "title" },
MinWordSizeTypos = new TypoTolerance.TypoSize {
OneTypo = 4,
TwoTypos = 10
}
};
await client.Index("books").UpdateTypoToleranceAsync(typoTolerance);
reset_typo_tolerance_1: |-
await client.Index("books").ResetTypoToleranceAsync();
typo_tolerance_guide_1: |-
var typoTolerance = new TypoTolerance {
Enabled = false
};
await client.Index("movies").UpdateTypoToleranceAsync(typoTolerance);
typo_tolerance_guide_2: |-
var typoTolerance = new TypoTolerance {
DisableOnAttributes = new string[] { "title" }
};
await client.Index("movies").UpdateTypoToleranceAsync(typoTolerance);
typo_tolerance_guide_3: |-
var typoTolerance = new TypoTolerance {
DisableOnWords = new string[] { "shrek" }
};
await client.Index("movies").UpdateTypoToleranceAsync(typoTolerance);
typo_tolerance_guide_4: |-
var typoTolerance = new TypoTolerance {
MinWordSizeTypos = new TypoTolerance.TypoSize {
OneTypo = 4,
TwoTypos = 10
}
};
await client.Index("movies").UpdateTypoToleranceAsync(typoTolerance);
get_all_tasks_paginating_1: |-
ResourceResults<TaskInfo> taskResult = await client.GetTasksAsync(new TasksQuery { Limit = 2, From = 10 });
get_all_tasks_paginating_2: |-
ResourceResults<TaskInfo> taskResult = await client.GetTasksAsync(new TasksQuery { Limit = 2, From = 8 });
get_pagination_settings_1: |-
await client.Index("movies").GetPaginationAsync();
update_pagination_settings_1: |-
var pagination = new Pagination {
MaxTotalHits = 20
};
await client.Index("movies").UpdatePaginationAsync(pagination);
reset_pagination_settings_1: |-
await client.Index("movies").ResetPaginationAsync();
get_faceting_settings_1: |-
await client.Index("movies").GetFacetingAsync();
update_faceting_settings_1: |-
var faceting = new Faceting {
MaxValuesPerFacet = 2
};
await client.Index("movies").UpdateFacetingAsync(faceting);
reset_faceting_settings_1: |-
await client.Index("movies").ResetFacetingAsync();
multi_search_1: |-
await client.MultiSearchAsync(new MultiSearchQuery()
{
Queries = new System.Collections.Generic.List<SearchQuery>()
{
new SearchQuery() {
IndexUid = "movies",
Q = "booh",
Limit = 5
},
new SearchQuery() {
IndexUid = "movies",
Q = "nemo",
Limit = 5
},
new SearchQuery() {
IndexUid = "movie_ratings",
Q = "us",
},
}
});
search_parameter_guide_matching_strategy_1: |-
SearchQuery params = new SearchQuery() { MatchingStrategy = "last" };
await client.Index("movies").SearchAsync<Game>("big fat liar", params);
search_parameter_guide_matching_strategy_2: |-
SearchQuery params = new SearchQuery() { MatchingStrategy = "all" };
await client.Index("movies").SearchAsync<Game>("big fat liar", params);
search_parameter_guide_show_ranking_score_1: |-
var params = new SearchQuery()
{
ShowRankingScore = true
};
await client.Index("movies").SearchAsync<MovieWithRankingScore>("dragon", params);
search_parameter_guide_show_ranking_score_details_1: |-
var params = new SearchQuery()
{
ShowRankingScoreDetails = true
};
await client.Index("movies").SearchAsync<MovieWithRankingScoreDetails>("dragon", params);
get_proximity_precision_settings_1: |-
await client.Index("books").GetProximityPrecisionAsync();
update_proximity_precision_settings_1: |-
await client.Index("books").UpdateProximityPrecisionAsync("byAttribute");
reset_proximity_precision_settings_1: |-
await client.Index("books").ResetProximityPrecisionAsync();
search_parameter_reference_distinct_1: |-
var params = new SearchQuery()
{
Distinct = "ATTRIBUTE_A"
};
await client.Index("INDEX_NAME").SearchAsync<T>("QUERY TERMS", params);
distinct_attribute_guide_filterable_1: |-
List<string> attributes = new() { "product_id", "sku", "url" };
TaskInfo result = await client.Index("products").UpdateFilterableAttributesAsync(attributes);
distinct_attribute_guide_distinct_parameter_1: |-
var params = new SearchQuery()
{
Distinct = "sku"
};
await client.Index("products").SearchAsync<Product>("white shirt", params);