Skip to content

Commit 61b61e8

Browse files
meili-bors[bot]Volodymyr Yevtushenko
andauthored
Merge #350
350: Add typo tolerance customization settings r=brunoocasali a=voloyev # Pull Request ## What does this PR do? Fixes #313 ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: Volodymyr Yevtushenko <[email protected]>
2 parents b48c52a + 1cb57fb commit 61b61e8

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

.rubocop_todo.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2022-07-25 19:23:49 UTC using RuboCop version 1.31.2.
3+
# on 2022-07-27 12:41:01 UTC using RuboCop version 1.32.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -14,16 +14,16 @@ Gemspec/RequireMFA:
1414
Exclude:
1515
- 'meilisearch.gemspec'
1616

17-
# Offense count: 44
17+
# Offense count: 45
1818
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
1919
# IgnoredMethods: refine
2020
Metrics/BlockLength:
21-
Max: 554
21+
Max: 597
2222

2323
# Offense count: 2
2424
# Configuration parameters: CountComments, CountAsOne.
2525
Metrics/ClassLength:
26-
Max: 293
26+
Max: 305
2727

2828
# Offense count: 1
2929
# Configuration parameters: Max, CountKeywordArgs.

lib/meilisearch/index.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,5 +396,20 @@ def update_pagination(pagination)
396396
def reset_pagination
397397
http_delete "/indexes/#{@uid}/settings/pagination"
398398
end
399+
400+
def typo_tolerance
401+
http_get("/indexes/#{@uid}/settings/typo-tolerance")
402+
end
403+
alias get_typo_tolerance typo_tolerance
404+
405+
def update_typo_tolerance(typo_tolerance_attributes)
406+
attributes = Utils.transform_attributes(typo_tolerance_attributes)
407+
http_patch("/indexes/#{@uid}/settings/typo-tolerance", attributes)
408+
end
409+
alias typo_tolerance= update_typo_tolerance
410+
411+
def reset_typo_tolerance
412+
http_delete("/indexes/#{@uid}/settings/typo-tolerance")
413+
end
399414
end
400415
end

spec/meilisearch/index/settings_spec.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,4 +722,58 @@ def update_synonyms(index, synonyms)
722722
expect(index.pagination.transform_keys(&:to_sym)).to eq(default_pagination)
723723
end
724724
end
725+
726+
context 'On typo tolerance' do
727+
let(:index) { client.index(uid) }
728+
729+
let(:default_typo_tolerance) do
730+
{
731+
'enabled' => true,
732+
'minWordSizeForTypos' =>
733+
{
734+
'oneTypo' => 5,
735+
'twoTypos' => 9
736+
},
737+
'disableOnWords' => [],
738+
'disableOnAttributes' => []
739+
}
740+
end
741+
742+
let(:new_typo_tolerance) do
743+
{
744+
'enabled' => true,
745+
'minWordSizeForTypos' => {
746+
'oneTypo' => 6,
747+
'twoTypos' => 10
748+
},
749+
'disableOnWords' => [],
750+
'disableOnAttributes' => ['title']
751+
}
752+
end
753+
754+
before { client.create_index!(uid) }
755+
756+
it 'gets default typo tolerance settings' do
757+
settings = index.typo_tolerance
758+
759+
expect(settings).to eq(default_typo_tolerance)
760+
end
761+
762+
it 'updates typo tolerance settings' do
763+
update_task = index.update_typo_tolerance(new_typo_tolerance)
764+
client.wait_for_task(update_task['taskUid'])
765+
766+
expect(index.typo_tolerance).to eq(new_typo_tolerance)
767+
end
768+
769+
it 'resets typo tolerance settings' do
770+
update_task = index.update_typo_tolerance(new_typo_tolerance)
771+
client.wait_for_task(update_task['taskUid'])
772+
773+
reset_task = index.reset_typo_tolerance
774+
client.wait_for_task(reset_task['taskUid'])
775+
776+
expect(index.typo_tolerance).to eq(default_typo_tolerance)
777+
end
778+
end
725779
end

0 commit comments

Comments
 (0)