Skip to content

Commit b7b1aaf

Browse files
Merge #351
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>
2 parents 22795de + d9e0d94 commit b7b1aaf

File tree

4 files changed

+45
-26
lines changed

4 files changed

+45
-26
lines changed

.rubocop_todo.yml

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-01-10 10:49:28 UTC using RuboCop version 1.27.0.
3+
# on 2024-04-08 13:44:25 UTC using RuboCop version 1.27.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -67,7 +67,7 @@ Lint/UnusedMethodArgument:
6767
Exclude:
6868
- 'lib/meilisearch-rails.rb'
6969

70-
# Offense count: 11
70+
# Offense count: 12
7171
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
7272
Metrics/AbcSize:
7373
Max: 104
@@ -81,14 +81,14 @@ Metrics/BlockLength:
8181
# Offense count: 1
8282
# Configuration parameters: CountComments, CountAsOne.
8383
Metrics/ClassLength:
84-
Max: 156
84+
Max: 157
8585

8686
# Offense count: 8
8787
# Configuration parameters: IgnoredMethods.
8888
Metrics/CyclomaticComplexity:
8989
Max: 27
9090

91-
# Offense count: 16
91+
# Offense count: 18
9292
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
9393
Metrics/MethodLength:
9494
Max: 103
@@ -128,13 +128,7 @@ RSpec/BeforeAfterAll:
128128
Exclude:
129129
- 'spec/integration_spec.rb'
130130

131-
# Offense count: 7
132-
# Configuration parameters: IgnoredMetadata.
133-
RSpec/DescribeClass:
134-
Exclude:
135-
- 'spec/integration_spec.rb'
136-
137-
# Offense count: 46
131+
# Offense count: 56
138132
# Configuration parameters: CountAsOne.
139133
RSpec/ExampleLength:
140134
Max: 19
@@ -154,24 +148,11 @@ RSpec/InstanceVariable:
154148
Exclude:
155149
- 'spec/integration_spec.rb'
156150

157-
# Offense count: 1
158-
# Configuration parameters: EnforcedStyle.
159-
# SupportedStyles: have_received, receive
160-
RSpec/MessageSpies:
161-
Exclude:
162-
- 'spec/integration_spec.rb'
163-
164151
# Offense count: 1
165152
RSpec/MultipleDescribes:
166153
Exclude:
167154
- 'spec/integration_spec.rb'
168155

169-
# Offense count: 1
170-
# This cop supports safe auto-correction (--auto-correct).
171-
RSpec/MultipleSubjects:
172-
Exclude:
173-
- 'spec/ms_clean_up_job_spec.rb'
174-
175156
# Offense count: 1
176157
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
177158
RSpec/VerifiedDoubles:
@@ -231,7 +212,7 @@ Style/OptionalBooleanParameter:
231212
Exclude:
232213
- 'lib/meilisearch-rails.rb'
233214

234-
# Offense count: 13
215+
# Offense count: 11
235216
# This cop supports safe auto-correction (--auto-correct).
236217
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
237218
# SupportedStyles: single_quotes, double_quotes
@@ -248,7 +229,7 @@ Style/TrailingCommaInArguments:
248229
Exclude:
249230
- 'spec/integration_spec.rb'
250231

251-
# Offense count: 19
232+
# Offense count: 20
252233
# This cop supports safe auto-correction (--auto-correct).
253234
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
254235
# URISchemes: http, https

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ class Book < ApplicationRecord
207207
crop_length 10
208208
faceting max_values_per_facet: 2000
209209
pagination max_total_hits: 1000
210+
proximity_precision 'byWord'
210211
end
211212
end
212213
```

lib/meilisearch-rails.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class IndexSettings
6767
pagination
6868
faceting
6969
typo_tolerance
70+
proximity_precision
7071
].freeze
7172

7273
CAMELIZE_OPTIONS = %i[pagination faceting typo_tolerance].freeze

spec/integration_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,3 +1235,39 @@ def self.name
12351235
end
12361236
end
12371237
end
1238+
1239+
describe 'proximity_precision' do
1240+
before do
1241+
stub_const(
1242+
'OtherColor',
1243+
Class.new do
1244+
include ActiveModel::Model
1245+
include MeiliSearch::Rails
1246+
end
1247+
)
1248+
end
1249+
1250+
context 'when the value is byWord' do
1251+
before do
1252+
OtherColor.meilisearch synchronize: true, index_uid: safe_index_uid('OtherColors') do
1253+
proximity_precision 'byWord'
1254+
end
1255+
end
1256+
1257+
it 'sets the value byWord to proximity precision' do
1258+
expect(OtherColor.index.get_settings['proximityPrecision']).to eq('byWord')
1259+
end
1260+
end
1261+
1262+
context 'when the value is byAttribute' do
1263+
before do
1264+
OtherColor.meilisearch synchronize: true, index_uid: safe_index_uid('OtherColors') do
1265+
proximity_precision 'byAttribute'
1266+
end
1267+
end
1268+
1269+
it 'sets the value byAttribute to proximity precision' do
1270+
expect(OtherColor.index.get_settings['proximityPrecision']).to eq('byAttribute')
1271+
end
1272+
end
1273+
end

0 commit comments

Comments
 (0)