Skip to content

Commit

Permalink
Merge #491
Browse files Browse the repository at this point in the history
491: Support user dictionary loading r=brunoocasali a=ellnix

# Pull Request

## Related issue
Fixes #488 

## 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?


I attempted to keep to the repo's style and make as few edits as possible.



Co-authored-by: ellnix <[email protected]>
  • Loading branch information
meili-bors[bot] and ellnix authored Oct 10, 2023
2 parents 8680ee7 + 78459aa commit c73ad5e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 12 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions lib/meilisearch/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 29 additions & 0 deletions spec/meilisearch/index/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c73ad5e

Please sign in to comment.