Skip to content

Commit

Permalink
Merge #351
Browse files Browse the repository at this point in the history
351: Implement the proximity precision option  r=ellnix a=KatsukiFujimoto

# Pull Request

## Related issue
N/A

## What does this PR do?
- Implements the proximity precision option so that you can set it through a model file.
  - This option can be useful when you prefer shorter indexing time to higher search precision.
  - https://www.meilisearch.com/docs/reference/api/settings#proximity-precision
- Adds sample code for it in README.

## 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?


Co-authored-by: KatsukiFujimoto <kf1996cnbl@gmail.com>
  • Loading branch information
meili-bors[bot] and KatsukiFujimoto authored May 8, 2024
2 parents 22795de + d9e0d94 commit b7b1aaf
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 26 deletions.
33 changes: 7 additions & 26 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 2024-01-10 10:49:28 UTC using RuboCop version 1.27.0.
# on 2024-04-08 13:44:25 UTC using RuboCop version 1.27.0.
# 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 Down Expand Up @@ -67,7 +67,7 @@ Lint/UnusedMethodArgument:
Exclude:
- 'lib/meilisearch-rails.rb'

# Offense count: 11
# Offense count: 12
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 104
Expand All @@ -81,14 +81,14 @@ Metrics/BlockLength:
# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 156
Max: 157

# Offense count: 8
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 27

# Offense count: 16
# Offense count: 18
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 103
Expand Down Expand Up @@ -128,13 +128,7 @@ RSpec/BeforeAfterAll:
Exclude:
- 'spec/integration_spec.rb'

# Offense count: 7
# Configuration parameters: IgnoredMetadata.
RSpec/DescribeClass:
Exclude:
- 'spec/integration_spec.rb'

# Offense count: 46
# Offense count: 56
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 19
Expand All @@ -154,24 +148,11 @@ RSpec/InstanceVariable:
Exclude:
- 'spec/integration_spec.rb'

# Offense count: 1
# Configuration parameters: EnforcedStyle.
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
Exclude:
- 'spec/integration_spec.rb'

# Offense count: 1
RSpec/MultipleDescribes:
Exclude:
- 'spec/integration_spec.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
RSpec/MultipleSubjects:
Exclude:
- 'spec/ms_clean_up_job_spec.rb'

# Offense count: 1
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Expand Down Expand Up @@ -231,7 +212,7 @@ Style/OptionalBooleanParameter:
Exclude:
- 'lib/meilisearch-rails.rb'

# Offense count: 13
# Offense count: 11
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Expand All @@ -248,7 +229,7 @@ Style/TrailingCommaInArguments:
Exclude:
- 'spec/integration_spec.rb'

# Offense count: 19
# Offense count: 20
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class Book < ApplicationRecord
crop_length 10
faceting max_values_per_facet: 2000
pagination max_total_hits: 1000
proximity_precision 'byWord'
end
end
```
Expand Down
1 change: 1 addition & 0 deletions lib/meilisearch-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class IndexSettings
pagination
faceting
typo_tolerance
proximity_precision
].freeze

CAMELIZE_OPTIONS = %i[pagination faceting typo_tolerance].freeze
Expand Down
36 changes: 36 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1235,3 +1235,39 @@ def self.name
end
end
end

describe 'proximity_precision' do
before do
stub_const(
'OtherColor',
Class.new do
include ActiveModel::Model
include MeiliSearch::Rails
end
)
end

context 'when the value is byWord' do
before do
OtherColor.meilisearch synchronize: true, index_uid: safe_index_uid('OtherColors') do
proximity_precision 'byWord'
end
end

it 'sets the value byWord to proximity precision' do
expect(OtherColor.index.get_settings['proximityPrecision']).to eq('byWord')
end
end

context 'when the value is byAttribute' do
before do
OtherColor.meilisearch synchronize: true, index_uid: safe_index_uid('OtherColors') do
proximity_precision 'byAttribute'
end
end

it 'sets the value byAttribute to proximity precision' do
expect(OtherColor.index.get_settings['proximityPrecision']).to eq('byAttribute')
end
end
end

0 comments on commit b7b1aaf

Please sign in to comment.