diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 02e7b17a..ad238f64 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -609,3 +609,9 @@ facet_search_2: |- genres: 'count' } ) +get_dictionary_1: |- + client.index('books').dictionary +update_dictionary_1: |- + client.index('books').update_dictionary(['J. R. R.', 'W. E. B.']) +reset_dictionary_1: |- + client.index('books').reset_dictionary diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d0befccd..bb2ab4a6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,11 +1,19 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2023-05-20 02:24:12 UTC using RuboCop version 1.50.2. +# on 2023-10-10 10:50:01 UTC using RuboCop version 1.50.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: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include. +# Include: **/*.gemfile, **/Gemfile, **/gems.rb +Bundler/OrderedGems: + Exclude: + - 'Gemfile' + # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: Severity, Include. @@ -14,16 +22,16 @@ Gemspec/RequireMFA: Exclude: - 'meilisearch.gemspec' -# Offense count: 47 +# Offense count: 50 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. # AllowedMethods: refine Metrics/BlockLength: - Max: 624 + Max: 633 # Offense count: 2 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 328 + Max: 338 # Offense count: 1 # Configuration parameters: Max, CountKeywordArgs. diff --git a/lib/meilisearch/index.rb b/lib/meilisearch/index.rb index ea39c77c..5b4e71ce 100644 --- a/lib/meilisearch/index.rb +++ b/lib/meilisearch/index.rb @@ -461,5 +461,20 @@ def update_faceting(faceting_attributes) def reset_faceting http_delete("/indexes/#{@uid}/settings/faceting") end + + ### SETTINGS - DICTIONARY + + def dictionary + http_get("/indexes/#{@uid}/settings/dictionary") + end + + def update_dictionary(dictionary_attributes) + attributes = Utils.transform_attributes(dictionary_attributes) + http_put("/indexes/#{@uid}/settings/dictionary", attributes) + end + + def reset_dictionary + http_delete("/indexes/#{@uid}/settings/dictionary") + end end end diff --git a/spec/meilisearch/index/settings_spec.rb b/spec/meilisearch/index/settings_spec.rb index 55297c97..b52bb218 100644 --- a/spec/meilisearch/index/settings_spec.rb +++ b/spec/meilisearch/index/settings_spec.rb @@ -800,4 +800,33 @@ def update_synonyms(index, synonyms) expect(index.faceting.transform_keys(&:to_sym).keys).to include(*default_faceting.keys) end end + + context 'On user-defined dictionary' do + let(:index) { client.index(uid) } + + before { client.create_index!(uid) } + + it 'has no default value' do + settings = index.dictionary + + expect(settings).to be_empty + end + + it 'updates dictionary' do + update_task = index.update_dictionary(['J. R. R.', 'W. E. B.']) + client.wait_for_task(update_task['taskUid']) + + expect(index.dictionary).to contain_exactly('J. R. R.', 'W. E. B.') + end + + it 'resets dictionary' do + update_task = index.update_dictionary(['J. R. R.', 'W. E. B.']) + client.wait_for_task(update_task['taskUid']) + + reset_task = index.reset_dictionary + client.wait_for_task(reset_task['taskUid']) + + expect(index.dictionary).to be_empty + end + end end