Skip to content

Commit

Permalink
Merge #584
Browse files Browse the repository at this point in the history
584: Suppport prefix and facet search settings r=brunoocasali a=ellnix

# Pull Request

## Related issue
Fixes #580

---

Appended "_setting" to all facet search settings to avoid collisions
with the `facet_search` method and avoid confusion.

Co-authored-by: ellnix <[email protected]>
  • Loading branch information
meili-bors[bot] and ellnix authored Jan 8, 2025
2 parents 4040605 + 6a93a5c commit 54ae665
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,18 @@ update_proximity_precision_settings_1: |-
client.index('books').update_proximity_precision('byAttribute')
reset_proximity_precision_settings_1: |-
client.index('books').reset_proximity_precision
get_facet_search_settings_1: |-
client.index('INDEX_UID').facet_search_setting
update_facet_search_settings_1: |-
client.index('INDEX_UID').update_facet_search_setting(false)
reset_facet_search_settings_1: |-
client.index('INDEX_UID').reset_facet_search_setting
get_prefix_search_settings_1: |-
client.index('INDEX_UID').prefix_search
update_prefix_search_settings_1: |-
client.index('INDEX_UID').update_prefix_search('disabled')
reset_prefix_search_settings_1: |-
client.index('INDEX_UID').reset_prefix_search
get_search_cutoff_1: |-
client.index('movies').search_cutoff_ms
update_search_cutoff_1: |-
Expand Down
8 changes: 4 additions & 4 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2025-01-02 22:29:58 UTC using RuboCop version 1.69.2.
# on 2025-01-08 15:54:24 UTC using RuboCop version 1.69.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: 64
# Offense count: 66
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 628
Max: 670

# Offense count: 4
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 452
Max: 470

# Offense count: 1
# Configuration parameters: Max, CountKeywordArgs.
Expand Down
28 changes: 28 additions & 0 deletions lib/meilisearch/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -645,5 +645,33 @@ def update_localized_attributes(new_localized_attributes)
def reset_localized_attributes
http_delete("/indexes/#{@uid}/settings/localized-attributes")
end

### SETTINGS - FACET SEARCH

def facet_search_setting
http_get("/indexes/#{@uid}/settings/facet-search")
end

def update_facet_search_setting(new_facet_search_setting)
http_put("/indexes/#{@uid}/settings/facet-search", new_facet_search_setting)
end

def reset_facet_search_setting
http_delete("/indexes/#{@uid}/settings/facet-search")
end

### SETTINGS - PREFIX SEARCH

def prefix_search
http_get("/indexes/#{@uid}/settings/prefix-search")
end

def update_prefix_search(new_prefix_search_setting)
http_put("/indexes/#{@uid}/settings/prefix-search", new_prefix_search_setting)
end

def reset_prefix_search
http_delete("/indexes/#{@uid}/settings/prefix-search")
end
end
end
60 changes: 60 additions & 0 deletions spec/meilisearch/index/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -805,4 +805,64 @@
expect(index.localized_attributes).to eq(default_localized_attributes)
end
end

context 'On facet search' do
let(:index) { client.index(uid) }
let(:default_facet_search_setting) { true }

before { client.create_index(uid).await }

it '#facet_search_setting gets default value' do
expect(index.facet_search_setting).to eq(default_facet_search_setting)
end

it '#update_facet_search_setting updates default value' do
update_task = index.update_facet_search_setting(false)
client.wait_for_task(update_task['taskUid'])

expect(index.facet_search_setting).to eq(false)
end

it '#reset_facet_search_setting resets facet search' do
update_task = index.update_facet_search_setting(false)
client.wait_for_task(update_task['taskUid'])

expect(index.facet_search_setting).to eq(false)

reset_task = index.reset_facet_search_setting
client.wait_for_task(reset_task['taskUid'])

expect(index.facet_search_setting).to eq(default_facet_search_setting)
end
end

context 'On prefix search' do
let(:index) { client.index(uid) }
let(:default_prefix_search) { 'indexingTime' }

before { client.create_index(uid).await }

it '#prefix_search gets default value' do
expect(index.prefix_search).to eq(default_prefix_search)
end

it '#update_prefix_search updates default value' do
update_task = index.update_prefix_search('disabled')
client.wait_for_task(update_task['taskUid'])

expect(index.prefix_search).to eq('disabled')
end

it '#reset_prefix_search resets prefix search' do
update_task = index.update_prefix_search('disabled')
client.wait_for_task(update_task['taskUid'])

expect(index.prefix_search).to eq('disabled')

reset_task = index.reset_prefix_search
client.wait_for_task(reset_task['taskUid'])

expect(index.prefix_search).to eq(default_prefix_search)
end
end
end

0 comments on commit 54ae665

Please sign in to comment.