Skip to content

Commit 5c91e87

Browse files
meili-bors[bot]ellnixbrunoocasali
authored
Merge #583
583: Support localized-attributes settings r=brunoocasali a=ellnix # Pull Request ## Related issue Fixes #560 Co-authored-by: ellnix <ellnix@disroot.org> Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
2 parents 1b3cd1d + 9f67ca9 commit 5c91e87

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

.code-samples.meilisearch.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,16 @@ search_parameter_reference_ranking_score_threshold_1: |-
659659
client.index('INDEX_NAME').search('badman', {
660660
rankingScoreThreshold: 0.2
661661
})
662+
search_parameter_reference_locales_1: |-
663+
client.index('INDEX_NAME').search('進撃の巨人', { locales: ['jpn'] })
664+
get_localized_attribute_settings_1: |-
665+
client.index('INDEX_NAME').localized_attributes
666+
update_localized_attribute_settings_1: |-
667+
client.index('INDEX_NAME').update_localized_attributes([
668+
{ attribute_patterns: ['*_ja'], locales: ['jpn'] },
669+
])
670+
reset_localized_attribute_settings_1: |-
671+
client.index('INDEX_NAME').reset_localized_attributes
662672
search_parameter_reference_distinct_1: |-
663673
client.index('INDEX_NAME').search('QUERY TERMS', {
664674
distinct: 'ATTRIBUTE_A'

.rubocop_todo.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-09-10 01:25:16 UTC using RuboCop version 1.65.1.
3+
# on 2025-01-02 22:29:58 UTC using RuboCop version 1.69.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 60
9+
# Offense count: 64
1010
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
1111
# AllowedMethods: refine
1212
Metrics/BlockLength:
13-
Max: 607
13+
Max: 628
1414

1515
# Offense count: 4
1616
# Configuration parameters: CountComments, CountAsOne.
1717
Metrics/ClassLength:
18-
Max: 442
18+
Max: 452
1919

2020
# Offense count: 1
2121
# Configuration parameters: Max, CountKeywordArgs.

lib/meilisearch/index.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,5 +629,21 @@ def update_search_cutoff_ms(search_cutoff_ms_attribute)
629629
def reset_search_cutoff_ms
630630
http_delete("/indexes/#{@uid}/settings/search-cutoff-ms")
631631
end
632+
633+
### SETTINGS - LOCALIZED ATTRIBUTES
634+
635+
def localized_attributes
636+
http_get("/indexes/#{@uid}/settings/localized-attributes")
637+
end
638+
639+
def update_localized_attributes(new_localized_attributes)
640+
new_localized_attributes = Utils.transform_attributes(new_localized_attributes)
641+
642+
http_put("/indexes/#{@uid}/settings/localized-attributes", new_localized_attributes)
643+
end
644+
645+
def reset_localized_attributes
646+
http_delete("/indexes/#{@uid}/settings/localized-attributes")
647+
end
632648
end
633649
end

spec/meilisearch/index/settings_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,4 +775,34 @@
775775
expect(index.search_cutoff_ms).to eq(default_search_cutoff_ms)
776776
end
777777
end
778+
779+
context 'On localized attributes' do
780+
let(:index) { client.index(uid) }
781+
let(:default_localized_attributes) { nil }
782+
783+
before { client.create_index(uid).await }
784+
785+
it '#search_cutoff_ms gets default value' do
786+
expect(index.localized_attributes).to eq(default_localized_attributes)
787+
end
788+
789+
it '#update_localized_attributes updates default value' do
790+
update_task = index.update_localized_attributes([{ attribute_patterns: ['title'], locales: ['eng'] }])
791+
client.wait_for_task(update_task['taskUid'])
792+
793+
expect(index.localized_attributes).to eq([{ 'attributePatterns' => ['title'], 'locales' => ['eng'] }])
794+
end
795+
796+
it '#reset_localized_attributes resets localized attributes' do
797+
update_task = index.update_localized_attributes([{ attribute_patterns: ['title'], locales: ['eng'] }])
798+
client.wait_for_task(update_task['taskUid'])
799+
800+
expect(index.localized_attributes).to eq([{ 'attributePatterns' => ['title'], 'locales' => ['eng'] }])
801+
802+
reset_task = index.reset_localized_attributes
803+
client.wait_for_task(reset_task['taskUid'])
804+
805+
expect(index.localized_attributes).to eq(default_localized_attributes)
806+
end
807+
end
778808
end

0 commit comments

Comments
 (0)