Skip to content

Commit

Permalink
Merge #583
Browse files Browse the repository at this point in the history
583: Support localized-attributes settings r=brunoocasali a=ellnix

# Pull Request

## Related issue
Fixes #560


Co-authored-by: ellnix <[email protected]>
Co-authored-by: Bruno Casali <[email protected]>
  • Loading branch information
3 people authored Jan 8, 2025
2 parents 1b3cd1d + 9f67ca9 commit 5c91e87
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
16 changes: 16 additions & 0 deletions lib/meilisearch/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 30 additions & 0 deletions spec/meilisearch/index/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5c91e87

Please sign in to comment.