From 6845e780786857deb67f9089398357c1646f4b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 18 May 2022 13:23:48 +0200 Subject: [PATCH] Allow setting relevancy_strictness Closes #91 --- docs/data-sources/index.md | 1 + docs/resources/index.md | 1 + internal/provider/data_source_index.go | 12 +++++------- internal/provider/resource_index.go | 24 ++++++++++++------------ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/data-sources/index.md b/docs/data-sources/index.md index 56f4604..f279b73 100644 --- a/docs/data-sources/index.md +++ b/docs/data-sources/index.md @@ -158,6 +158,7 @@ Read-Only: - `custom_ranking` (List of String) - `ranking` (List of String) +- `relevancy_strictness` (Number) - `replicas` (Set of String) diff --git a/docs/resources/index.md b/docs/resources/index.md index 2295978..ac11a87 100644 --- a/docs/resources/index.md +++ b/docs/resources/index.md @@ -242,6 +242,7 @@ Optional: - `custom_ranking` (List of String) List of attributes for custom ranking criterion. - `ranking` (List of String) List of ranking criteria. +- `relevancy_strictness` (Number) Relevancy threshold below which less relevant results aren’t included in the results - `replicas` (Set of String) List of replica names. Names of virtual replicas should be surrounded with `virtual()`. diff --git a/internal/provider/data_source_index.go b/internal/provider/data_source_index.go index bcc4641..df47649 100644 --- a/internal/provider/data_source_index.go +++ b/internal/provider/data_source_index.go @@ -78,13 +78,11 @@ func dataSourceIndex() *schema.Resource { Computed: true, Description: "List of attributes for custom ranking criterion.", }, - // TODO: Add after the PR below merged. - // https://github.com/algolia/algoliasearch-client-go/pull/661 - // "relevancy_strictness": { - // Type: schema.TypeInt, - // Computed: true, - // Description: "Relevancy threshold below which less relevant results aren’t included in the results", - // }, + "relevancy_strictness": { + Type: schema.TypeInt, + Computed: true, + Description: "Relevancy threshold below which less relevant results aren’t included in the results", + }, "replicas": { Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, diff --git a/internal/provider/resource_index.go b/internal/provider/resource_index.go index bcb1302..b268be5 100644 --- a/internal/provider/resource_index.go +++ b/internal/provider/resource_index.go @@ -105,15 +105,13 @@ func resourceIndex() *schema.Resource { Optional: true, Description: "List of attributes for custom ranking criterion.", }, - // TODO: Add after the PR below merged. - // https://github.com/algolia/algoliasearch-client-go/pull/661 - // "relevancy_strictness": { - // Type: schema.TypeInt, - // Optional: true, - // Default: 100, - // ValidateFunc: validation.IntBetween(0, 100), - // Description: "Relevancy threshold below which less relevant results aren’t included in the results", - // }, + "relevancy_strictness": { + Type: schema.TypeInt, + Optional: true, + Default: 100, + ValidateFunc: validation.IntBetween(0, 100), + Description: "Relevancy threshold below which less relevant results aren’t included in the results", + }, "replicas": { Type: schema.TypeSet, Elem: &schema.Schema{Type: schema.TypeString}, @@ -697,9 +695,10 @@ func refreshIndexState(ctx context.Context, d *schema.ResourceData, m interface{ "attributes_to_retrieve": settings.AttributesToRetrieve.Get(), }}, "ranking_config": []interface{}{map[string]interface{}{ - "ranking": settings.Ranking.Get(), - "custom_ranking": settings.CustomRanking.Get(), - "replicas": settings.Replicas.Get(), + "ranking": settings.Ranking.Get(), + "custom_ranking": settings.CustomRanking.Get(), + "replicas": settings.Replicas.Get(), + "relevancy_strictness": settings.RelevancyStrictness.Get(), }}, "faceting_config": []interface{}{map[string]interface{}{ "max_values_per_facet": settings.MaxValuesPerFacet.Get(), @@ -841,6 +840,7 @@ func unmarshalRankingConfig(configured interface{}, settings *search.Settings) { settings.Ranking = opt.Ranking(castStringList(config["ranking"])...) settings.CustomRanking = opt.CustomRanking(castStringList(config["custom_ranking"])...) settings.Replicas = opt.Replicas(castStringSet(config["replicas"])...) + settings.RelevancyStrictness = opt.RelevancyStrictness(config["relevancy_strictness"].(int)) } func unmarshalFacetingConfig(configured interface{}, settings *search.Settings) {