Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support user dictionary loading #491

Merged
merged 6 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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