diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index ad238f64..9cf60aee 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -615,3 +615,15 @@ update_dictionary_1: |- client.index('books').update_dictionary(['J. R. R.', 'W. E. B.']) reset_dictionary_1: |- client.index('books').reset_dictionary +get_separator_tokens_1: |- + client.index('articles').separator_tokens +update_separator_tokens_1: |- + client.index('articles').update_separator_tokens(['|', '…']) +reset_separator_tokens_1: |- + client.index('articles').reset_separator_tokens +get_non_separator_tokens_1: |- + client.index('articles').non_separator_tokens +update_non_separator_tokens_1: |- + client.index('articles').update_non_separator_tokens(['@', '#']) +reset_non_separator_tokens_1: |- + client.index('articles').reset_non_separator_tokens diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bb2ab4a6..1154e166 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,37 +1,21 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2023-10-10 10:50:01 UTC using RuboCop version 1.50.2. +# on 2023-10-10 14:01:22 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. -# Include: **/*.gemspec -Gemspec/RequireMFA: - Exclude: - - 'meilisearch.gemspec' - -# Offense count: 50 +# Offense count: 52 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. # AllowedMethods: refine Metrics/BlockLength: - Max: 633 + Max: 671 # Offense count: 2 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 338 + Max: 358 # Offense count: 1 # Configuration parameters: Max, CountKeywordArgs. diff --git a/lib/meilisearch/index.rb b/lib/meilisearch/index.rb index 5b4e71ce..df5d5e99 100644 --- a/lib/meilisearch/index.rb +++ b/lib/meilisearch/index.rb @@ -476,5 +476,34 @@ def update_dictionary(dictionary_attributes) def reset_dictionary http_delete("/indexes/#{@uid}/settings/dictionary") end + ### SETTINGS - SEPARATOR TOKENS + + def separator_tokens + http_get("/indexes/#{@uid}/settings/separator-tokens") + end + + def update_separator_tokens(separator_tokens_attributes) + attributes = Utils.transform_attributes(separator_tokens_attributes) + http_put("/indexes/#{@uid}/settings/separator-tokens", attributes) + end + + def reset_separator_tokens + http_delete("/indexes/#{@uid}/settings/separator-tokens") + end + + ### SETTINGS - NON SEPARATOR TOKENS + + def non_separator_tokens + http_get("/indexes/#{@uid}/settings/non-separator-tokens") + end + + def update_non_separator_tokens(non_separator_tokens_attributes) + attributes = Utils.transform_attributes(non_separator_tokens_attributes) + http_put("/indexes/#{@uid}/settings/non-separator-tokens", attributes) + end + + def reset_non_separator_tokens + http_delete("/indexes/#{@uid}/settings/non-separator-tokens") + end end end diff --git a/spec/meilisearch/index/settings_spec.rb b/spec/meilisearch/index/settings_spec.rb index b52bb218..cac99242 100644 --- a/spec/meilisearch/index/settings_spec.rb +++ b/spec/meilisearch/index/settings_spec.rb @@ -829,4 +829,56 @@ def update_synonyms(index, synonyms) expect(index.dictionary).to be_empty end end + + context 'On separator tokens' do + let(:index) { client.index(uid) } + + before { client.create_index!(uid) } + + describe 'separator_tokens' do + it 'has no default value' do + expect(index.separator_tokens).to be_empty + end + + it 'updates separator tokens' do + update_task = index.update_separator_tokens ['|', '…'] + client.wait_for_task(update_task['taskUid']) + + expect(index.separator_tokens).to contain_exactly('|', '…') + end + + it 'resets separator tokens' do + update_task = index.update_separator_tokens ['|', '…'] + client.wait_for_task(update_task['taskUid']) + + reset_task = index.reset_separator_tokens + client.wait_for_task(reset_task['taskUid']) + + expect(index.separator_tokens).to be_empty + end + end + + describe '#non_separator_tokens' do + it 'has no default value' do + expect(index.non_separator_tokens).to be_empty + end + + it 'updates non separator tokens' do + update_task = index.update_non_separator_tokens ['@', '#'] + client.wait_for_task(update_task['taskUid']) + + expect(index.non_separator_tokens).to contain_exactly('@', '#') + end + + it 'resets non separator tokens' do + update_task = index.update_non_separator_tokens ['@', '#'] + client.wait_for_task(update_task['taskUid']) + + reset_task = index.reset_non_separator_tokens + client.wait_for_task(reset_task['taskUid']) + + expect(index.non_separator_tokens).to be_empty + end + end + end end