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 the proximity precision option #351

Merged
merged 3 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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