Skip to content

Commit 1875bac

Browse files
meili-bors[bot]André MommertNymuxyzo
authored
Merge #540
540: Support searchCutoffMs setting r=curquiza a=andre-m-dev # Pull Request ## Related issue Fixes #532 ## What does this PR do? - Support searchCutoffMs setting ## 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: André Mommert <[email protected]> Co-authored-by: André <[email protected]>
2 parents 74b5165 + 137829d commit 1875bac

File tree

13 files changed

+98
-36
lines changed

13 files changed

+98
-36
lines changed

.code-samples.meilisearch.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ update_settings_1: |-
190190
},
191191
faceting: {
192192
max_values_per_facet: 200
193-
}
193+
},
194+
search_cutoff_ms: 150
194195
})
195196
reset_settings_1: |-
196197
client.index('movies').reset_settings
@@ -642,3 +643,9 @@ update_proximity_precision_settings_1: |-
642643
client.index('books').update_proximity_precision('byAttribute')
643644
reset_proximity_precision_settings_1: |-
644645
client.index('books').reset_proximity_precision
646+
get_search_cutoff_1: |-
647+
client.index('movies').search_cutoff_ms
648+
update_search_cutoff_1: |-
649+
client.index('movies').update_search_cutoff_ms(150)
650+
reset_search_cutoff_1: |-
651+
client.index('movies').reset_search_cutoff_ms

.rubocop_todo.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-02-16 18:01:53 UTC using RuboCop version 1.50.2.
3+
# on 2024-06-01 14:58:01 UTC using RuboCop version 1.63.5.
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
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 63
9+
# Offense count: 60
1010
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
1111
# AllowedMethods: refine
1212
Metrics/BlockLength:
13-
Max: 581
13+
Max: 607
1414

1515
# Offense count: 4
1616
# Configuration parameters: CountComments, CountAsOne.
1717
Metrics/ClassLength:
18-
Max: 421
18+
Max: 430
1919

2020
# Offense count: 1
2121
# Configuration parameters: Max, CountKeywordArgs.

lib/meilisearch/index.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def reset_stop_words
386386
Models::Task.new(response, task_endpoint)
387387
end
388388

389-
### SETTINGS - DINSTINCT ATTRIBUTE
389+
### SETTINGS - DISTINCT ATTRIBUTE
390390

391391
def distinct_attribute
392392
http_get "/indexes/#{@uid}/settings/distinct-attribute"
@@ -591,5 +591,19 @@ def update_proximity_precision(proximity_precision_attribute)
591591
def reset_proximity_precision
592592
http_delete("/indexes/#{@uid}/settings/proximity-precision")
593593
end
594+
595+
### SETTINGS - SEARCH CUTOFF MS
596+
597+
def search_cutoff_ms
598+
http_get("/indexes/#{@uid}/settings/search-cutoff-ms")
599+
end
600+
601+
def update_search_cutoff_ms(search_cutoff_ms_attribute)
602+
http_put("/indexes/#{@uid}/settings/search-cutoff-ms", search_cutoff_ms_attribute)
603+
end
604+
605+
def reset_search_cutoff_ms
606+
http_delete("/indexes/#{@uid}/settings/search-cutoff-ms")
607+
end
594608
end
595609
end

spec/meilisearch/client/health_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@
1111
it 'is unhealthy when the url is invalid' do
1212
expect(wrong_client.healthy?).to be false
1313
end
14+
15+
it 'returns the health information' do
16+
response = client.health
17+
expect(response).to be_a(Hash)
18+
expect(response).to have_key('status')
19+
end
1420
end

spec/meilisearch/client/requests_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
RSpec.describe 'MeiliSearch::Client requests' do
44
let(:key) { SecureRandom.uuid }
55

6-
before(:each) do
6+
before do
77
expect(MeiliSearch::Client).to receive(:post)
88
.with(kind_of(String), hash_including(body: "{\"primaryKey\":\"#{key}\",\"uid\":\"#{key}\"}"))
99
.and_call_original

spec/meilisearch/client/token_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def initialize(api_key)
5353
it 'decodes successfully using @api_key from instance' do
5454
expect do
5555
JWT.decode token, client_key, true, VERIFY_OPTIONS
56-
end.to_not raise_error
56+
end.not_to raise_error
5757
end
5858

5959
it 'tries to decode without the right signature raises a error' do
@@ -89,7 +89,7 @@ def initialize(api_key)
8989
it 'allows generate token with a nil expires_at' do
9090
expect do
9191
instance.generate_tenant_token('uid', search_rules, expires_at: nil)
92-
end.to_not raise_error
92+
end.not_to raise_error
9393
end
9494

9595
it 'decodes successfully the expires_at param' do
@@ -117,7 +117,7 @@ def initialize(api_key)
117117
it 'allows generate token without expires_at' do
118118
expect do
119119
instance.generate_tenant_token('uid', search_rules)
120-
end.to_not raise_error
120+
end.not_to raise_error
121121
end
122122
end
123123

spec/meilisearch/index/base_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
client.create_index('books').await
66

77
index = client.fetch_index('books')
8-
expect(index).to be_a(MeiliSearch::Index)
8+
expect(index).to be_a(described_class)
99
expect(index.uid).to eq('books')
1010
expect(index.created_at).to be_a(Time)
1111
expect(index.created_at).to be_within(60).of(Time.now)
@@ -59,7 +59,7 @@
5959
task.await
6060

6161
index = client.fetch_index('uid')
62-
expect(index).to be_a(MeiliSearch::Index)
62+
expect(index).to be_a(described_class)
6363
expect(index.uid).to eq('uid')
6464
expect(index.primary_key).to eq('new_primary_key')
6565
expect(index.fetch_primary_key).to eq('new_primary_key')
@@ -77,7 +77,7 @@
7777
task.await
7878

7979
index = client.fetch_index('books')
80-
expect(index).to be_a(MeiliSearch::Index)
80+
expect(index).to be_a(described_class)
8181
expect(index.uid).to eq('books')
8282
expect(index.primary_key).to eq('international_standard_book_number')
8383
expect(index.fetch_primary_key).to eq('international_standard_book_number')
@@ -111,7 +111,7 @@
111111
index = new_client.fetch_index('books')
112112
expect(index.options).to eq({ max_retries: 1, timeout: 2, convert_body?: true })
113113

114-
expect(MeiliSearch::Index).to receive(:get).with(
114+
expect(described_class).to receive(:get).with(
115115
"#{URL}/indexes/books",
116116
{
117117
headers: expected_headers,
@@ -139,7 +139,7 @@
139139
index = new_client.fetch_index('books')
140140
expect(index.options).to eq(options.merge({ convert_body?: true }))
141141

142-
expect(MeiliSearch::Index).to receive(:get).with(
142+
expect(described_class).to receive(:get).with(
143143
"#{URL}/indexes/books",
144144
{
145145
headers: expected_headers,
@@ -194,7 +194,7 @@
194194
task.await
195195

196196
index = client.fetch_index('uid')
197-
expect(index).to be_a(MeiliSearch::Index)
197+
expect(index).to be_a(described_class)
198198
expect(index.uid).to eq('uid')
199199
expect(index.primary_key).to eq('new_primary_key')
200200
expect(index.fetch_primary_key).to eq('new_primary_key')

spec/meilisearch/index/search/q_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,9 @@
7272
context 'with finite pagination params' do
7373
it 'responds with specialized fields' do
7474
response = index.search('coco', { page: 2, hits_per_page: 2 })
75-
7675
expect(response.keys).to contain_exactly(*FINITE_PAGINATED_SEARCH_RESPONSE_KEYS)
77-
end
7876

79-
it 'responds with specialized fields' do
8077
response = index.search('coco', { page: 2, hitsPerPage: 2 })
81-
8278
expect(response.keys).to contain_exactly(*FINITE_PAGINATED_SEARCH_RESPONSE_KEYS)
8379
end
8480
end

spec/meilisearch/index/search/vector_search.rb renamed to spec/meilisearch/index/search/vector_search_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
new_index = client.index('vector_test_search')
1515
new_index.add_documents(documents).await
1616

17-
expect(new_index.search('q', vector: [0, 1, 2])['hits']).not_to be_empty
17+
expect(new_index.search(vector: [9, 9, 9])['hits']).to be_empty
18+
expect(new_index.search('All Things Must Pass')['hits']).not_to be_empty
1819
end
1920
end

spec/meilisearch/index/settings_spec.rb

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
let(:default_displayed_attributes) { ['*'] }
1616
let(:default_pagination) { { maxTotalHits: 1000 } }
1717
let(:default_proximity_precision) { 'byWord' }
18+
let(:default_search_cutoff_ms) { nil }
1819
let(:settings_keys) do
1920
[
2021
'rankingRules',
@@ -31,7 +32,8 @@
3132
'dictionary',
3233
'nonSeparatorTokens',
3334
'separatorTokens',
34-
'proximityPrecision'
35+
'proximityPrecision',
36+
'searchCutoffMs'
3537
]
3638
end
3739
let(:uid) { random_uid }
@@ -55,7 +57,8 @@
5557
'dictionary' => [],
5658
'separatorTokens' => [],
5759
'nonSeparatorTokens' => [],
58-
'proximityPrecision' => default_proximity_precision
60+
'proximityPrecision' => default_proximity_precision,
61+
'searchCutoffMs' => default_search_cutoff_ms
5962
)
6063
end
6164

@@ -97,7 +100,8 @@
97100
distinct_attribute: 'title',
98101
stop_words: ['the', 'a'],
99102
synonyms: { wow: ['world of warcraft'] },
100-
proximity_precision: 'byAttribute'
103+
proximity_precision: 'byAttribute',
104+
search_cutoff_ms: 333
101105
).await
102106

103107
task = index.reset_settings
@@ -109,7 +113,8 @@
109113
'distinctAttribute' => nil,
110114
'stopWords' => [],
111115
'synonyms' => {},
112-
'proximityPrecision' => default_proximity_precision
116+
'proximityPrecision' => default_proximity_precision,
117+
'searchCutoffMs' => default_search_cutoff_ms
113118
)
114119
end
115120
end
@@ -740,4 +745,34 @@
740745
end
741746
end
742747
end
748+
749+
context 'On search cutoff' do
750+
let(:index) { client.index(uid) }
751+
let(:default_search_cutoff_ms) { nil }
752+
753+
before { client.create_index(uid).await }
754+
755+
it '#search_cutoff_ms gets default value' do
756+
expect(index.search_cutoff_ms).to eq(default_search_cutoff_ms)
757+
end
758+
759+
it '#update_search_cutoff_ms updates default value' do
760+
update_task = index.update_search_cutoff_ms(800)
761+
client.wait_for_task(update_task['taskUid'])
762+
763+
expect(index.search_cutoff_ms).to eq(800)
764+
end
765+
766+
it '#reset_search_cutoff_ms resets search cutoff ms' do
767+
update_task = index.update_search_cutoff_ms(300)
768+
client.wait_for_task(update_task['taskUid'])
769+
770+
expect(index.search_cutoff_ms).to eq(300)
771+
772+
reset_task = index.reset_search_cutoff_ms
773+
client.wait_for_task(reset_task['taskUid'])
774+
775+
expect(index.search_cutoff_ms).to eq(default_search_cutoff_ms)
776+
end
777+
end
743778
end

0 commit comments

Comments
 (0)