diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 38b711ae..07bbb7ea 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -659,6 +659,16 @@ search_parameter_reference_ranking_score_threshold_1: |- client.index('INDEX_NAME').search('badman', { rankingScoreThreshold: 0.2 }) +search_parameter_reference_locales_1: |- + client.index('INDEX_NAME').search('進撃の巨人', { locales: ['jpn'] }) +get_localized_attribute_settings_1: |- + client.index('INDEX_NAME').localized_attributes +update_localized_attribute_settings_1: |- + client.index('INDEX_NAME').update_localized_attributes([ + { attribute_patterns: ['*_ja'], locales: ['jpn'] }, + ]) +reset_localized_attribute_settings_1: |- + client.index('INDEX_NAME').reset_localized_attributes search_parameter_reference_distinct_1: |- client.index('INDEX_NAME').search('QUERY TERMS', { distinct: 'ATTRIBUTE_A' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 44a59326..b06393f3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,21 +1,21 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-09-10 01:25:16 UTC using RuboCop version 1.65.1. +# on 2025-01-02 22:29:58 UTC using RuboCop version 1.69.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 60 +# Offense count: 64 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. # AllowedMethods: refine Metrics/BlockLength: - Max: 607 + Max: 628 # Offense count: 4 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 442 + Max: 452 # Offense count: 1 # Configuration parameters: Max, CountKeywordArgs. diff --git a/lib/meilisearch/index.rb b/lib/meilisearch/index.rb index 2de94164..b4b611fa 100644 --- a/lib/meilisearch/index.rb +++ b/lib/meilisearch/index.rb @@ -629,5 +629,21 @@ def update_search_cutoff_ms(search_cutoff_ms_attribute) def reset_search_cutoff_ms http_delete("/indexes/#{@uid}/settings/search-cutoff-ms") end + + ### SETTINGS - LOCALIZED ATTRIBUTES + + def localized_attributes + http_get("/indexes/#{@uid}/settings/localized-attributes") + end + + def update_localized_attributes(new_localized_attributes) + new_localized_attributes = Utils.transform_attributes(new_localized_attributes) + + http_put("/indexes/#{@uid}/settings/localized-attributes", new_localized_attributes) + end + + def reset_localized_attributes + http_delete("/indexes/#{@uid}/settings/localized-attributes") + end end end diff --git a/spec/meilisearch/index/settings_spec.rb b/spec/meilisearch/index/settings_spec.rb index dc32c9ab..5324807d 100644 --- a/spec/meilisearch/index/settings_spec.rb +++ b/spec/meilisearch/index/settings_spec.rb @@ -775,4 +775,34 @@ expect(index.search_cutoff_ms).to eq(default_search_cutoff_ms) end end + + context 'On localized attributes' do + let(:index) { client.index(uid) } + let(:default_localized_attributes) { nil } + + before { client.create_index(uid).await } + + it '#search_cutoff_ms gets default value' do + expect(index.localized_attributes).to eq(default_localized_attributes) + end + + it '#update_localized_attributes updates default value' do + update_task = index.update_localized_attributes([{ attribute_patterns: ['title'], locales: ['eng'] }]) + client.wait_for_task(update_task['taskUid']) + + expect(index.localized_attributes).to eq([{ 'attributePatterns' => ['title'], 'locales' => ['eng'] }]) + end + + it '#reset_localized_attributes resets localized attributes' do + update_task = index.update_localized_attributes([{ attribute_patterns: ['title'], locales: ['eng'] }]) + client.wait_for_task(update_task['taskUid']) + + expect(index.localized_attributes).to eq([{ 'attributePatterns' => ['title'], 'locales' => ['eng'] }]) + + reset_task = index.reset_localized_attributes + client.wait_for_task(reset_task['taskUid']) + + expect(index.localized_attributes).to eq(default_localized_attributes) + end + end end