Skip to content

Commit

Permalink
Merge pull request #92 from greg0ire/relevancy-strictness
Browse files Browse the repository at this point in the history
Allow setting relevancy_strictness
  • Loading branch information
k-yomo authored May 18, 2022
2 parents 4414dde + c9c600e commit ee3b67e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ Read-Only:

- `custom_ranking` (List of String)
- `ranking` (List of String)
- `relevancy_strictness` (Number)
- `replicas` (Set of String)


Expand Down
1 change: 1 addition & 0 deletions docs/resources/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.


Expand Down
12 changes: 5 additions & 7 deletions internal/provider/data_source_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
24 changes: 12 additions & 12 deletions internal/provider/resource_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ee3b67e

Please sign in to comment.