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

Implement new proximityPrecision #512

Merged
merged 6 commits into from Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .code-samples.meilisearch.yaml
Expand Up @@ -631,3 +631,9 @@ update_non_separator_tokens_1: |-
client.index('articles').update_non_separator_tokens(['@', '#'])
reset_non_separator_tokens_1: |-
client.index('articles').reset_non_separator_tokens
get_proximity_precision_settings_1: |-
client.index('books').proximity_precision
update_proximity_precision_settings_1: |-
client.index('books').update_proximity_precision('byAttribute')
reset_proximity_precision_settings_1: |-
client.index('books').reset_proximity_precision
6 changes: 3 additions & 3 deletions .rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-10-11 10:43:57 UTC using RuboCop version 1.50.2.
# on 2024-01-16 21:52:52 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
Expand All @@ -10,12 +10,12 @@
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 671
Max: 694

# Offense count: 2
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 363
Max: 373

# Offense count: 1
# Configuration parameters: Max, CountKeywordArgs.
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -9,9 +9,9 @@ gemspec

group :development, :test do
gem 'byebug'
gem 'codecov'
gem 'rspec', '~> 3.0'
gem 'simplecov'
gem 'codecov'

# Used only for testing, none of the classes are exposed to the public API.
gem 'jwt'
Expand Down
14 changes: 14 additions & 0 deletions lib/meilisearch/index.rb
Expand Up @@ -514,5 +514,19 @@ def update_non_separator_tokens(non_separator_tokens_attributes)
def reset_non_separator_tokens
http_delete("/indexes/#{@uid}/settings/non-separator-tokens")
end

### SETTINGS - PROXIMITY PRECISION

def proximity_precision
http_get("/indexes/#{@uid}/settings/proximity-precision")
end

def update_proximity_precision(proximity_precision_attribute)
http_put("/indexes/#{@uid}/settings/proximity-precision", proximity_precision_attribute)
end

def reset_proximity_precision
http_delete("/indexes/#{@uid}/settings/proximity-precision")
end
end
end
32 changes: 30 additions & 2 deletions spec/meilisearch/index/settings_spec.rb
Expand Up @@ -14,6 +14,7 @@
let(:default_searchable_attributes) { ['*'] }
let(:default_displayed_attributes) { ['*'] }
let(:default_pagination) { { maxTotalHits: 1000 } }
let(:default_proximity_precision) { 'byWord' }
let(:settings_keys) do
[
'rankingRules',
Expand All @@ -29,7 +30,8 @@
'pagination',
'dictionary',
'nonSeparatorTokens',
'separatorTokens'
'separatorTokens',
'proximityPrecision'
]
end
let(:uid) { random_uid }
Expand All @@ -52,6 +54,7 @@
expect(settings['pagination'].transform_keys(&:to_sym)).to eq(default_pagination)
expect(settings['filterableAttributes']).to eq([])
expect(settings['sortableAttributes']).to eq([])
expect(settings['proximityPrecision']).to eq(default_proximity_precision)
end

it 'updates multiples settings at the same time' do
Expand Down Expand Up @@ -85,7 +88,8 @@
ranking_rules: ['title:asc', 'typo'],
distinct_attribute: 'title',
stop_words: ['the', 'a'],
synonyms: { wow: ['world of warcraft'] }
synonyms: { wow: ['world of warcraft'] },
proximity_precision: 'byAttribute'
)
client.wait_for_task(task['taskUid'])

Expand All @@ -99,6 +103,7 @@
expect(settings['distinctAttribute']).to be_nil
expect(settings['stopWords']).to be_empty
expect(settings['synonyms']).to be_empty
expect(settings['proximityPrecision']).to eq(default_proximityPrecision)
ellnix marked this conversation as resolved.
Show resolved Hide resolved
end
end

Expand Down Expand Up @@ -880,5 +885,28 @@ def update_synonyms(index, synonyms)
expect(index.non_separator_tokens).to be_empty
end
end

describe '#proximity_precision' do
it 'has byWord as default value' do
expect(index.proximity_precision).to eq('byWord')
end

it 'updates proximity precision' do
update_task = index.update_proximity_precision('byAttribute')
client.wait_for_task(update_task['taskUid'])

expect(index.proximity_precision).to eq('byAttribute')
end

it 'resets proximity precision' do
update_task = index.update_proximity_precision('byAttribute')
client.wait_for_task(update_task['taskUid'])

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

expect(index.proximity_precision).to eq('byWord')
end
end
end
end