Skip to content

Commit a3fee85

Browse files
meili-bors[bot]Volodymyr Yevtushenko
andauthored
Merge #352
352: Add faceting settings customization r=brunoocasali a=voloyev # Pull Request ## What does this PR do? Fixes #346 ## 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 61b61e8 + 9493c45 commit a3fee85

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-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-27 12:41:01 UTC using RuboCop version 1.32.0.
3+
# on 2022-07-27 15:08:15 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: 45
17+
# Offense count: 46
1818
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
1919
# IgnoredMethods: refine
2020
Metrics/BlockLength:
21-
Max: 597
21+
Max: 626
2222

2323
# Offense count: 2
2424
# Configuration parameters: CountComments, CountAsOne.
2525
Metrics/ClassLength:
26-
Max: 305
26+
Max: 317
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
@@ -411,5 +411,20 @@ def update_typo_tolerance(typo_tolerance_attributes)
411411
def reset_typo_tolerance
412412
http_delete("/indexes/#{@uid}/settings/typo-tolerance")
413413
end
414+
415+
def faceting
416+
http_get("/indexes/#{@uid}/settings/faceting")
417+
end
418+
alias get_faceting faceting
419+
420+
def update_faceting(faceting_attributes)
421+
attributes = Utils.transform_attributes(faceting_attributes)
422+
http_patch("/indexes/#{@uid}/settings/faceting", attributes)
423+
end
424+
alias faceting= update_faceting
425+
426+
def reset_faceting
427+
http_delete("/indexes/#{@uid}/settings/faceting")
428+
end
414429
end
415430
end

spec/meilisearch/index/settings_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,4 +776,45 @@ def update_synonyms(index, synonyms)
776776
expect(index.typo_tolerance).to eq(default_typo_tolerance)
777777
end
778778
end
779+
780+
context 'On faceting' do
781+
let(:index) { client.index(uid) }
782+
let(:faceting) { { maxValuesPerFacet: 333 } }
783+
let(:default_faceting) { { maxValuesPerFacet: 100 } }
784+
785+
before { client.create_index!(uid) }
786+
787+
it 'gets default values of faceting' do
788+
settings = index.faceting.transform_keys(&:to_sym)
789+
790+
expect(settings).to eq(default_faceting)
791+
end
792+
793+
it 'updates faceting' do
794+
update_task = index.update_faceting(faceting)
795+
client.wait_for_task(update_task['taskUid'])
796+
797+
expect(index.faceting.transform_keys(&:to_sym)).to eq(faceting)
798+
end
799+
800+
it 'updates faceting at null' do
801+
update_task = index.update_faceting(faceting)
802+
client.wait_for_task(update_task['taskUid'])
803+
804+
update_task = index.update_faceting(nil)
805+
client.wait_for_task(update_task['taskUid'])
806+
807+
expect(index.faceting.transform_keys(&:to_sym)).to eq(default_faceting)
808+
end
809+
810+
it 'resets faceting' do
811+
update_task = index.update_faceting(faceting)
812+
client.wait_for_task(update_task['taskUid'])
813+
814+
reset_task = index.reset_faceting
815+
client.wait_for_task(reset_task['taskUid'])
816+
817+
expect(index.faceting.transform_keys(&:to_sym)).to eq(default_faceting)
818+
end
819+
end
779820
end

0 commit comments

Comments
 (0)