Skip to content

Commit 14f1895

Browse files
bors[bot]tjakubo
andauthored
Merge #171
171: Add sub-settings methods (to get, update and reset) r=curquiza a=tjakubo2 Change requested in #124 Complements #164 Everything done in the same manner as settings/displayed-attributes, please let me know if improvements are needed. Co-authored-by: tjakubo2 <[email protected]>
2 parents 5fc9bfc + 41f136f commit 14f1895

File tree

2 files changed

+400
-0
lines changed

2 files changed

+400
-0
lines changed

src/Meilisearch/Index.cs

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,223 @@ public async Task<UpdateStatus> ResetDisplayedAttributes()
384384
return await httpresponse.Content.ReadFromJsonAsync<UpdateStatus>();
385385
}
386386

387+
/// <summary>
388+
/// Gets the distinct attribute setting.
389+
/// </summary>
390+
/// <returns>Returns the distinct attribute setting.</returns>
391+
public async Task<string> GetDistinctAttribute()
392+
{
393+
return await this.http.GetFromJsonAsync<string>($"/indexes/{this.Uid}/settings/distinct-attribute");
394+
}
395+
396+
/// <summary>
397+
/// Updates the distinct attribute setting.
398+
/// </summary>
399+
/// <param name="distinctAttribute">Name of distinct attribute.</param>
400+
/// <returns>Returns the updateID of the asynchronous task.</returns>
401+
public async Task<UpdateStatus> UpdateDistinctAttribute(string distinctAttribute)
402+
{
403+
JsonSerializerOptions options = new JsonSerializerOptions { IgnoreNullValues = true };
404+
HttpResponseMessage responseMessage = await this.http.PostAsJsonAsync<string>($"/indexes/{this.Uid}/settings/distinct-attribute", distinctAttribute, options);
405+
return await responseMessage.Content.ReadFromJsonAsync<UpdateStatus>();
406+
}
407+
408+
/// <summary>
409+
/// Resets the distinct attribute setting.
410+
/// </summary>
411+
/// <returns>Returns the updateID of the asynchronous task.</returns>
412+
public async Task<UpdateStatus> ResetDistinctAttribute()
413+
{
414+
var httpresponse = await this.http.DeleteAsync($"/indexes/{this.Uid}/settings/distinct-attribute");
415+
return await httpresponse.Content.ReadFromJsonAsync<UpdateStatus>();
416+
}
417+
418+
/// <summary>
419+
/// Gets the filterable attributes setting.
420+
/// </summary>
421+
/// <returns>Returns the filterable attributes setting.</returns>
422+
public async Task<IEnumerable<string>> GetFilterableAttributes()
423+
{
424+
return await this.http.GetFromJsonAsync<IEnumerable<string>>($"/indexes/{this.Uid}/settings/filterable-attributes");
425+
}
426+
427+
/// <summary>
428+
/// Updates the filterable attributes setting.
429+
/// </summary>
430+
/// <param name="filterableAttributes">Collection of filterable attributes.</param>
431+
/// <returns>Returns the updateID of the asynchronous task.</returns>
432+
public async Task<UpdateStatus> UpdateFilterableAttributes(IEnumerable<string> filterableAttributes)
433+
{
434+
JsonSerializerOptions options = new JsonSerializerOptions { IgnoreNullValues = true };
435+
HttpResponseMessage responseMessage = await this.http.PostAsJsonAsync<IEnumerable<string>>($"/indexes/{this.Uid}/settings/filterable-attributes", filterableAttributes, options);
436+
return await responseMessage.Content.ReadFromJsonAsync<UpdateStatus>();
437+
}
438+
439+
/// <summary>
440+
/// Resets the filterable attributes setting.
441+
/// </summary>
442+
/// <returns>Returns the updateID of the asynchronous task.</returns>
443+
public async Task<UpdateStatus> ResetFilterableAttributes()
444+
{
445+
var httpresponse = await this.http.DeleteAsync($"/indexes/{this.Uid}/settings/filterable-attributes");
446+
return await httpresponse.Content.ReadFromJsonAsync<UpdateStatus>();
447+
}
448+
449+
/// <summary>
450+
/// Gets the ranking rules setting.
451+
/// </summary>
452+
/// <returns>Returns the ranking rules setting.</returns>
453+
public async Task<IEnumerable<string>> GetRankingRules()
454+
{
455+
return await this.http.GetFromJsonAsync<IEnumerable<string>>($"/indexes/{this.Uid}/settings/ranking-rules");
456+
}
457+
458+
/// <summary>
459+
/// Updates the ranking rules setting.
460+
/// </summary>
461+
/// <param name="rankingRules">Collection of ranking rules.</param>
462+
/// <returns>Returns the updateID of the asynchronous task.</returns>
463+
public async Task<UpdateStatus> UpdateRankingRules(IEnumerable<string> rankingRules)
464+
{
465+
JsonSerializerOptions options = new JsonSerializerOptions { IgnoreNullValues = true };
466+
HttpResponseMessage responseMessage = await this.http.PostAsJsonAsync<IEnumerable<string>>($"/indexes/{this.Uid}/settings/ranking-rules", rankingRules, options);
467+
return await responseMessage.Content.ReadFromJsonAsync<UpdateStatus>();
468+
}
469+
470+
/// <summary>
471+
/// Resets the ranking rules setting.
472+
/// </summary>
473+
/// <returns>Returns the updateID of the asynchronous task.</returns>
474+
public async Task<UpdateStatus> ResetRankingRules()
475+
{
476+
var httpresponse = await this.http.DeleteAsync($"/indexes/{this.Uid}/settings/ranking-rules");
477+
return await httpresponse.Content.ReadFromJsonAsync<UpdateStatus>();
478+
}
479+
480+
/// <summary>
481+
/// Gets the searchable attributes setting.
482+
/// </summary>
483+
/// <returns>Returns the searchable attributes setting.</returns>
484+
public async Task<IEnumerable<string>> GetSearchableAttributes()
485+
{
486+
return await this.http.GetFromJsonAsync<IEnumerable<string>>($"/indexes/{this.Uid}/settings/searchable-attributes");
487+
}
488+
489+
/// <summary>
490+
/// Updates the searchable attributes setting.
491+
/// </summary>
492+
/// <param name="searchableAttributes">Collection of searchable attributes.</param>
493+
/// <returns>Returns the updateID of the asynchronous task.</returns>
494+
public async Task<UpdateStatus> UpdateSearchableAttributes(IEnumerable<string> searchableAttributes)
495+
{
496+
JsonSerializerOptions options = new JsonSerializerOptions { IgnoreNullValues = true };
497+
HttpResponseMessage responseMessage = await this.http.PostAsJsonAsync<IEnumerable<string>>($"/indexes/{this.Uid}/settings/searchable-attributes", searchableAttributes, options);
498+
return await responseMessage.Content.ReadFromJsonAsync<UpdateStatus>();
499+
}
500+
501+
/// <summary>
502+
/// Resets the searchable attributes setting.
503+
/// </summary>
504+
/// <returns>Returns the updateID of the asynchronous task.</returns>
505+
public async Task<UpdateStatus> ResetSearchableAttributes()
506+
{
507+
var httpresponse = await this.http.DeleteAsync($"/indexes/{this.Uid}/settings/searchable-attributes");
508+
return await httpresponse.Content.ReadFromJsonAsync<UpdateStatus>();
509+
}
510+
511+
/// <summary>
512+
/// Gets the sortable attributes setting.
513+
/// </summary>
514+
/// <returns>Returns the sortable attributes setting.</returns>
515+
public async Task<IEnumerable<string>> GetSortableAttributes()
516+
{
517+
return await this.http.GetFromJsonAsync<IEnumerable<string>>($"/indexes/{this.Uid}/settings/sortable-attributes");
518+
}
519+
520+
/// <summary>
521+
/// Updates the sortable attributes setting.
522+
/// </summary>
523+
/// <param name="sortableAttributes">Collection of sortable attributes.</param>
524+
/// <returns>Returns the updateID of the asynchronous task.</returns>
525+
public async Task<UpdateStatus> UpdateSortableAttributes(IEnumerable<string> sortableAttributes)
526+
{
527+
JsonSerializerOptions options = new JsonSerializerOptions { IgnoreNullValues = true };
528+
HttpResponseMessage responseMessage = await this.http.PostAsJsonAsync<IEnumerable<string>>($"/indexes/{this.Uid}/settings/sortable-attributes", sortableAttributes, options);
529+
return await responseMessage.Content.ReadFromJsonAsync<UpdateStatus>();
530+
}
531+
532+
/// <summary>
533+
/// Resets the sortable attributes setting.
534+
/// </summary>
535+
/// <returns>Returns the updateID of the asynchronous task.</returns>
536+
public async Task<UpdateStatus> ResetSortableAttributes()
537+
{
538+
var httpresponse = await this.http.DeleteAsync($"/indexes/{this.Uid}/settings/sortable-attributes");
539+
return await httpresponse.Content.ReadFromJsonAsync<UpdateStatus>();
540+
}
541+
542+
/// <summary>
543+
/// Gets the stop words setting.
544+
/// </summary>
545+
/// <returns>Returns the stop words setting.</returns>
546+
public async Task<IEnumerable<string>> GetStopWords()
547+
{
548+
return await this.http.GetFromJsonAsync<IEnumerable<string>>($"/indexes/{this.Uid}/settings/stop-words");
549+
}
550+
551+
/// <summary>
552+
/// Updates the stop words setting.
553+
/// </summary>
554+
/// <param name="stopWords">Collection of stop words.</param>
555+
/// <returns>Returns the updateID of the asynchronous task.</returns>
556+
public async Task<UpdateStatus> UpdateStopWords(IEnumerable<string> stopWords)
557+
{
558+
JsonSerializerOptions options = new JsonSerializerOptions { IgnoreNullValues = true };
559+
HttpResponseMessage responseMessage = await this.http.PostAsJsonAsync<IEnumerable<string>>($"/indexes/{this.Uid}/settings/stop-words", stopWords, options);
560+
return await responseMessage.Content.ReadFromJsonAsync<UpdateStatus>();
561+
}
562+
563+
/// <summary>
564+
/// Resets the stop words setting.
565+
/// </summary>
566+
/// <returns>Returns the updateID of the asynchronous task.</returns>
567+
public async Task<UpdateStatus> ResetStopWords()
568+
{
569+
var httpresponse = await this.http.DeleteAsync($"/indexes/{this.Uid}/settings/stop-words");
570+
return await httpresponse.Content.ReadFromJsonAsync<UpdateStatus>();
571+
}
572+
573+
/// <summary>
574+
/// Gets the synonyms setting.
575+
/// </summary>
576+
/// <returns>Returns the synonyms setting.</returns>
577+
public async Task<Dictionary<string, IEnumerable<string>>> GetSynonyms()
578+
{
579+
return await this.http.GetFromJsonAsync<Dictionary<string, IEnumerable<string>>>($"/indexes/{this.Uid}/settings/synonyms");
580+
}
581+
582+
/// <summary>
583+
/// Updates the synonyms setting.
584+
/// </summary>
585+
/// <param name="synonyms">Collection of synonyms.</param>
586+
/// <returns>Returns the updateID of the asynchronous task.</returns>
587+
public async Task<UpdateStatus> UpdateSynonyms(Dictionary<string, IEnumerable<string>> synonyms)
588+
{
589+
JsonSerializerOptions options = new JsonSerializerOptions { IgnoreNullValues = true };
590+
HttpResponseMessage responseMessage = await this.http.PostAsJsonAsync<Dictionary<string, IEnumerable<string>>>($"/indexes/{this.Uid}/settings/synonyms", synonyms, options);
591+
return await responseMessage.Content.ReadFromJsonAsync<UpdateStatus>();
592+
}
593+
594+
/// <summary>
595+
/// Resets the synonyms setting.
596+
/// </summary>
597+
/// <returns>Returns the updateID of the asynchronous task.</returns>
598+
public async Task<UpdateStatus> ResetSynonyms()
599+
{
600+
var httpresponse = await this.http.DeleteAsync($"/indexes/{this.Uid}/settings/synonyms");
601+
return await httpresponse.Content.ReadFromJsonAsync<UpdateStatus>();
602+
}
603+
387604
/// <summary>
388605
/// Get stats.
389606
/// </summary>

0 commit comments

Comments
 (0)