diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 02e7b17a..c84129d1 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -609,3 +609,15 @@ facet_search_2: |- genres: 'count' } ) +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/lib/meilisearch/index.rb b/lib/meilisearch/index.rb index ea39c77c..35e51ddb 100644 --- a/lib/meilisearch/index.rb +++ b/lib/meilisearch/index.rb @@ -461,5 +461,35 @@ def update_faceting(faceting_attributes) def reset_faceting http_delete("/indexes/#{@uid}/settings/faceting") 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 55297c97..1763ebb5 100644 --- a/spec/meilisearch/index/settings_spec.rb +++ b/spec/meilisearch/index/settings_spec.rb @@ -800,4 +800,56 @@ def update_synonyms(index, synonyms) expect(index.faceting.transform_keys(&:to_sym).keys).to include(*default_faceting.keys) 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