From 1f37bf671c31442f3076d2a03c35e837501d954c Mon Sep 17 00:00:00 2001 From: ellnix Date: Thu, 2 Jan 2025 23:25:14 +0100 Subject: [PATCH 1/6] Add tests for localized_attributes settings --- spec/meilisearch/index/settings_spec.rb | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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 From be2644c0c7f0217994afa119191cf1eb41c745ee Mon Sep 17 00:00:00 2001 From: ellnix Date: Thu, 2 Jan 2025 23:25:54 +0100 Subject: [PATCH 2/6] Add setters and getters for localized_attributes --- lib/meilisearch/index.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/meilisearch/index.rb b/lib/meilisearch/index.rb index 2de94164..41f65088 100644 --- a/lib/meilisearch/index.rb +++ b/lib/meilisearch/index.rb @@ -629,5 +629,20 @@ 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 From 11bf6c43d1857e0b551e411b4304accfc7e549aa Mon Sep 17 00:00:00 2001 From: ellnix Date: Thu, 2 Jan 2025 23:29:31 +0100 Subject: [PATCH 3/6] Add code-samples for localized-attributes --- .code-samples.meilisearch.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 38b711ae..d3e92bf8 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' From fcc12489f3892b38ef2a76347b6890836306f725 Mon Sep 17 00:00:00 2001 From: ellnix Date: Thu, 2 Jan 2025 23:30:22 +0100 Subject: [PATCH 4/6] Re-generate rubocop config --- .rubocop_todo.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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. From 42cca33257f23e76a1312c126607fad1104feb06 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Thu, 9 Jan 2025 02:44:25 +1300 Subject: [PATCH 5/6] Update .code-samples.meilisearch.yaml --- .code-samples.meilisearch.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index d3e92bf8..07bbb7ea 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -665,7 +665,7 @@ 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'] }, + { attribute_patterns: ['*_ja'], locales: ['jpn'] }, ]) reset_localized_attribute_settings_1: |- client.index('INDEX_NAME').reset_localized_attributes From 9f67ca989556a534e7f6d737d27eb1bc02e64c5a Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Thu, 9 Jan 2025 02:44:30 +1300 Subject: [PATCH 6/6] Update lib/meilisearch/index.rb --- lib/meilisearch/index.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/meilisearch/index.rb b/lib/meilisearch/index.rb index 41f65088..b4b611fa 100644 --- a/lib/meilisearch/index.rb +++ b/lib/meilisearch/index.rb @@ -638,6 +638,7 @@ def localized_attributes 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