Skip to content

Commit

Permalink
Merge #493
Browse files Browse the repository at this point in the history
493: Support text-separator customization r=brunoocasali a=ellnix

# Pull Request

## Related issue
Fixes #487 

## PR checklist
Please check if your PR fulfills the following requirements:
- [X] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [X] Have you read the contributing guidelines?
- [X] Have you made sure that the title is accurate and descriptive of the changes?

There are linter errors on both this pull request and the #491 since they add new settings, but they cannot reasonably be tackled while adding settings. A separate issue and PR would be more appropriate.

Co-authored-by: ellnix <[email protected]>
Co-authored-by: Bruno Casali <[email protected]>
  • Loading branch information
3 people authored Oct 9, 2023
2 parents 01b1c89 + ea59a10 commit 1eadfde
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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(['|', '&hellip;'])
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
30 changes: 30 additions & 0 deletions lib/meilisearch/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
52 changes: 52 additions & 0 deletions spec/meilisearch/index/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ['|', '&hellip;']
client.wait_for_task(update_task['taskUid'])

expect(index.separator_tokens).to contain_exactly('|', '&hellip;')
end

it 'resets separator tokens' do
update_task = index.update_separator_tokens ['|', '&hellip;']
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

0 comments on commit 1eadfde

Please sign in to comment.