From 20c02c8f07bbe945cd38617ce86dd5a9a09a8428 Mon Sep 17 00:00:00 2001 From: ellnix <103502144+ellnix@users.noreply.github.com> Date: Wed, 4 Oct 2023 15:31:00 +0200 Subject: [PATCH 1/6] Implement dictionary methods --- lib/meilisearch/index.rb | 17 +++++++++++++++ spec/meilisearch/index/settings_spec.rb | 29 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/lib/meilisearch/index.rb b/lib/meilisearch/index.rb index ea39c77c..fc018388 100644 --- a/lib/meilisearch/index.rb +++ b/lib/meilisearch/index.rb @@ -461,5 +461,22 @@ 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 + alias get_dictionary dictionary + + def update_dictionary(dictionary_attributes) + attributes = Utils.transform_attributes(dictionary_attributes) + http_put("/indexes/#{@uid}/settings/dictionary", attributes) + end + alias dictionary= update_dictionary + + 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..9bdc5d5e 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 From a2b19e8bd9e8ae2c404c0992bfe6aea3ac08a6ae Mon Sep 17 00:00:00 2001 From: ellnix <103502144+ellnix@users.noreply.github.com> Date: Wed, 4 Oct 2023 15:35:03 +0200 Subject: [PATCH 2/6] Update .code-samples with dictionary methods --- .code-samples.meilisearch.yaml | 6 ++++++ 1 file changed, 6 insertions(+) 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 From e0ca5c9a01c736678a710579d0d2be772faa7b45 Mon Sep 17 00:00:00 2001 From: ellnix <103502144+ellnix@users.noreply.github.com> Date: Wed, 4 Oct 2023 18:26:05 +0200 Subject: [PATCH 3/6] Fix double quoted strings without interpolation --- spec/meilisearch/index/settings_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/meilisearch/index/settings_spec.rb b/spec/meilisearch/index/settings_spec.rb index 9bdc5d5e..b52bb218 100644 --- a/spec/meilisearch/index/settings_spec.rb +++ b/spec/meilisearch/index/settings_spec.rb @@ -813,14 +813,14 @@ def update_synonyms(index, synonyms) end it 'updates dictionary' do - update_task = index.update_dictionary(["J. R. R.", "W. E. B."]) + 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.") + 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."]) + update_task = index.update_dictionary(['J. R. R.', 'W. E. B.']) client.wait_for_task(update_task['taskUid']) reset_task = index.reset_dictionary From 457a6d22cd415b349397b28895b036310914f0e0 Mon Sep 17 00:00:00 2001 From: ellnix <103502144+ellnix@users.noreply.github.com> Date: Fri, 6 Oct 2023 17:41:47 +0200 Subject: [PATCH 4/6] Remove unnecessary dictionary getter alias --- lib/meilisearch/index.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/meilisearch/index.rb b/lib/meilisearch/index.rb index fc018388..7bcacffb 100644 --- a/lib/meilisearch/index.rb +++ b/lib/meilisearch/index.rb @@ -467,7 +467,6 @@ def reset_faceting def dictionary http_get("/indexes/#{@uid}/settings/dictionary") end - alias get_dictionary dictionary def update_dictionary(dictionary_attributes) attributes = Utils.transform_attributes(dictionary_attributes) From 6b4d2ee2b1e16e2dbf4691a9441ed9327006a800 Mon Sep 17 00:00:00 2001 From: ellnix <103502144+ellnix@users.noreply.github.com> Date: Sat, 7 Oct 2023 14:32:49 +0200 Subject: [PATCH 5/6] Remove unnecessary user dictionary setter alias --- lib/meilisearch/index.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/meilisearch/index.rb b/lib/meilisearch/index.rb index 7bcacffb..5b4e71ce 100644 --- a/lib/meilisearch/index.rb +++ b/lib/meilisearch/index.rb @@ -472,7 +472,6 @@ def update_dictionary(dictionary_attributes) attributes = Utils.transform_attributes(dictionary_attributes) http_put("/indexes/#{@uid}/settings/dictionary", attributes) end - alias dictionary= update_dictionary def reset_dictionary http_delete("/indexes/#{@uid}/settings/dictionary") From 78459aaf7943289789bf13ba16fa9d6ff2a0d299 Mon Sep 17 00:00:00 2001 From: ellnix <103502144+ellnix@users.noreply.github.com> Date: Tue, 10 Oct 2023 12:50:41 +0200 Subject: [PATCH 6/6] Re-generate .rubocop_todo.yml --- .rubocop_todo.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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.