Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
512: Implement new proximityPrecision r=ellnix a=andre-m-dev

# Pull Request

## Related issue
Fixes meilisearch#511 

## What does this PR do?
- Add proximityPrecision

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [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: Andre <>
  • Loading branch information
meili-bors[bot] authored Jan 16, 2024
2 parents ed4dc30 + ec31baa commit 40f80cb
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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_proximity_precision)
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

0 comments on commit 40f80cb

Please sign in to comment.