meilisearch 0.27.0 → 0.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +0 -2
- data/lib/meilisearch/client.rb +13 -5
- data/lib/meilisearch/index.rb +140 -77
- data/lib/meilisearch/models/task.rb +160 -0
- data/lib/meilisearch/utils.rb +73 -48
- data/lib/meilisearch/version.rb +1 -1
- data/lib/meilisearch.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc7926e5e9f849ba9fb7377e4d1fe416abdba271c6518e511311da9750e209dc
|
4
|
+
data.tar.gz: 4dbb041794de52a349af301d713958de08fd4ceb4ac2afc0baa176e980d52f1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65b4e041307fa52c979bae5efb07428fbb2db6d67564bf00f151c8d45aa636e83eb1b6c87716a5cab92802f734073f919912ea97f6efc88acfaa9866375a9ea4
|
7
|
+
data.tar.gz: 054ed5ae299c6cce0e8a183ef828e233b634dfef5fee89c9dc213062171071455120957596b169dd7ce1b23b6027e1829725290d70c303532bb87fb96e6d287b
|
data/README.md
CHANGED
@@ -251,8 +251,6 @@ JSON output:
|
|
251
251
|
}
|
252
252
|
```
|
253
253
|
|
254
|
-
You can enable it by querying PATCH /experimental-features with { "scoreDetails": true }
|
255
|
-
|
256
254
|
This feature is only available with Meilisearch v1.3 and newer (optional).
|
257
255
|
|
258
256
|
#### Custom Search With attributes on at search time <!-- omit in toc -->
|
data/lib/meilisearch/client.rb
CHANGED
@@ -16,7 +16,8 @@ module MeiliSearch
|
|
16
16
|
def swap_indexes(*options)
|
17
17
|
mapped_array = options.map { |arr| { indexes: arr } }
|
18
18
|
|
19
|
-
http_post '/swap-indexes', mapped_array
|
19
|
+
response = http_post '/swap-indexes', mapped_array
|
20
|
+
Models::Task.new(response, task_endpoint)
|
20
21
|
end
|
21
22
|
|
22
23
|
def indexes(options = {})
|
@@ -35,14 +36,20 @@ module MeiliSearch
|
|
35
36
|
def create_index(index_uid, options = {})
|
36
37
|
body = Utils.transform_attributes(options.merge(uid: index_uid))
|
37
38
|
|
38
|
-
http_post '/indexes', body
|
39
|
+
response = http_post '/indexes', body
|
40
|
+
|
41
|
+
Models::Task.new(response, task_endpoint)
|
39
42
|
end
|
40
43
|
|
41
44
|
# Synchronous version of create_index.
|
42
45
|
# Waits for the task to be achieved, be careful when using it.
|
43
46
|
def create_index!(index_uid, options = {})
|
44
|
-
|
45
|
-
|
47
|
+
Utils.soft_deprecate(
|
48
|
+
'Client#create_index!',
|
49
|
+
"client.create_index('#{index_uid}').await"
|
50
|
+
)
|
51
|
+
|
52
|
+
create_index(index_uid, options).await
|
46
53
|
end
|
47
54
|
|
48
55
|
def delete_index(index_uid)
|
@@ -118,7 +125,8 @@ module MeiliSearch
|
|
118
125
|
### DUMPS
|
119
126
|
|
120
127
|
def create_dump
|
121
|
-
http_post '/dumps'
|
128
|
+
response = http_post '/dumps'
|
129
|
+
Models::Task.new(response, task_endpoint)
|
122
130
|
end
|
123
131
|
|
124
132
|
### SNAPSHOTS
|
data/lib/meilisearch/index.rb
CHANGED
@@ -30,13 +30,15 @@ module MeiliSearch
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def update(body)
|
33
|
-
http_patch indexes_path(id: @uid), Utils.transform_attributes(body)
|
33
|
+
response = http_patch indexes_path(id: @uid), Utils.transform_attributes(body)
|
34
|
+
Models::Task.new(response, task_endpoint)
|
34
35
|
end
|
35
36
|
|
36
37
|
alias update_index update
|
37
38
|
|
38
39
|
def delete
|
39
|
-
http_delete indexes_path(id: @uid)
|
40
|
+
response = http_delete indexes_path(id: @uid)
|
41
|
+
Models::Task.new(response, task_endpoint)
|
40
42
|
end
|
41
43
|
alias delete_index delete
|
42
44
|
|
@@ -86,28 +88,38 @@ module MeiliSearch
|
|
86
88
|
|
87
89
|
def add_documents(documents, primary_key = nil)
|
88
90
|
documents = [documents] if documents.is_a?(Hash)
|
89
|
-
http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact
|
91
|
+
response = http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact
|
92
|
+
|
93
|
+
Models::Task.new(response, task_endpoint)
|
90
94
|
end
|
91
95
|
alias replace_documents add_documents
|
92
96
|
alias add_or_replace_documents add_documents
|
93
97
|
|
94
98
|
def add_documents!(documents, primary_key = nil)
|
95
|
-
|
96
|
-
|
99
|
+
Utils.soft_deprecate(
|
100
|
+
'Index#add_documents!',
|
101
|
+
'index.add_documents(...).await'
|
102
|
+
)
|
103
|
+
|
104
|
+
add_documents(documents, primary_key).await
|
97
105
|
end
|
98
106
|
alias replace_documents! add_documents!
|
99
107
|
alias add_or_replace_documents! add_documents!
|
100
108
|
|
101
109
|
def add_documents_json(documents, primary_key = nil)
|
102
110
|
options = { convert_body?: false }
|
103
|
-
http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options
|
111
|
+
response = http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options
|
112
|
+
|
113
|
+
Models::Task.new(response, task_endpoint)
|
104
114
|
end
|
105
115
|
alias replace_documents_json add_documents_json
|
106
116
|
alias add_or_replace_documents_json add_documents_json
|
107
117
|
|
108
118
|
def add_documents_ndjson(documents, primary_key = nil)
|
109
119
|
options = { headers: { 'Content-Type' => 'application/x-ndjson' }, convert_body?: false }
|
110
|
-
http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options
|
120
|
+
response = http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options
|
121
|
+
|
122
|
+
Models::Task.new(response, task_endpoint)
|
111
123
|
end
|
112
124
|
alias replace_documents_ndjson add_documents_ndjson
|
113
125
|
alias add_or_replace_documents_ndjson add_documents_ndjson
|
@@ -115,58 +127,62 @@ module MeiliSearch
|
|
115
127
|
def add_documents_csv(documents, primary_key = nil, delimiter = nil)
|
116
128
|
options = { headers: { 'Content-Type' => 'text/csv' }, convert_body?: false }
|
117
129
|
|
118
|
-
http_post "/indexes/#{@uid}/documents", documents, {
|
130
|
+
response = http_post "/indexes/#{@uid}/documents", documents, {
|
119
131
|
primaryKey: primary_key,
|
120
132
|
csvDelimiter: delimiter
|
121
133
|
}.compact, options
|
134
|
+
|
135
|
+
Models::Task.new(response, task_endpoint)
|
122
136
|
end
|
123
137
|
alias replace_documents_csv add_documents_csv
|
124
138
|
alias add_or_replace_documents_csv add_documents_csv
|
125
139
|
|
126
140
|
def update_documents(documents, primary_key = nil)
|
127
141
|
documents = [documents] if documents.is_a?(Hash)
|
128
|
-
http_put "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact
|
142
|
+
response = http_put "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact
|
143
|
+
|
144
|
+
Models::Task.new(response, task_endpoint)
|
129
145
|
end
|
130
146
|
alias add_or_update_documents update_documents
|
131
147
|
|
132
148
|
def update_documents!(documents, primary_key = nil)
|
133
|
-
|
134
|
-
|
149
|
+
Utils.soft_deprecate(
|
150
|
+
'Index#update_documents!',
|
151
|
+
'index.update_documents(...).await'
|
152
|
+
)
|
153
|
+
|
154
|
+
update_documents(documents, primary_key).await
|
135
155
|
end
|
136
156
|
alias add_or_update_documents! update_documents!
|
137
157
|
|
138
158
|
def add_documents_in_batches(documents, batch_size = 1000, primary_key = nil)
|
139
|
-
|
140
|
-
|
141
|
-
tasks.append(add_documents(batch, primary_key))
|
159
|
+
documents.each_slice(batch_size).map do |batch|
|
160
|
+
add_documents(batch, primary_key)
|
142
161
|
end
|
143
|
-
tasks
|
144
162
|
end
|
145
163
|
|
146
164
|
def add_documents_in_batches!(documents, batch_size = 1000, primary_key = nil)
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
165
|
+
Utils.soft_deprecate(
|
166
|
+
'Index#add_documents_in_batches!',
|
167
|
+
'index.add_documents_in_batches(...).each(&:await)'
|
168
|
+
)
|
169
|
+
|
170
|
+
add_documents_in_batches(documents, batch_size, primary_key).each(&:await)
|
153
171
|
end
|
154
172
|
|
155
173
|
def update_documents_in_batches(documents, batch_size = 1000, primary_key = nil)
|
156
|
-
|
157
|
-
|
158
|
-
tasks.append(update_documents(batch, primary_key))
|
174
|
+
documents.each_slice(batch_size).map do |batch|
|
175
|
+
update_documents(batch, primary_key)
|
159
176
|
end
|
160
|
-
tasks
|
161
177
|
end
|
162
178
|
|
163
179
|
def update_documents_in_batches!(documents, batch_size = 1000, primary_key = nil)
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
180
|
+
Utils.soft_deprecate(
|
181
|
+
'Index#update_documents_in_batches!',
|
182
|
+
'index.update_documents_in_batches(...).each(&:await)'
|
183
|
+
)
|
184
|
+
|
185
|
+
update_documents_in_batches(documents, batch_size, primary_key).each(&:await)
|
170
186
|
end
|
171
187
|
|
172
188
|
# Public: Delete documents from an index
|
@@ -178,44 +194,61 @@ module MeiliSearch
|
|
178
194
|
# Returns a Task object.
|
179
195
|
def delete_documents(options = {})
|
180
196
|
Utils.version_error_handler(__method__) do
|
181
|
-
if options.is_a?(Hash) && options.key?(:filter)
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
197
|
+
response = if options.is_a?(Hash) && options.key?(:filter)
|
198
|
+
http_post "/indexes/#{@uid}/documents/delete", options
|
199
|
+
else
|
200
|
+
# backwards compatibility:
|
201
|
+
# expect to be a array or/number/string to send alongside as documents_ids.
|
202
|
+
options = [options] unless options.is_a?(Array)
|
187
203
|
|
188
|
-
|
189
|
-
|
204
|
+
http_post "/indexes/#{@uid}/documents/delete-batch", options
|
205
|
+
end
|
206
|
+
|
207
|
+
Models::Task.new(response, task_endpoint)
|
190
208
|
end
|
191
209
|
end
|
192
210
|
alias delete_multiple_documents delete_documents
|
193
211
|
|
194
212
|
def delete_documents!(documents_ids)
|
195
|
-
|
196
|
-
|
213
|
+
Utils.soft_deprecate(
|
214
|
+
'Index#delete_documents!',
|
215
|
+
'index.delete_documents(...).await'
|
216
|
+
)
|
217
|
+
|
218
|
+
delete_documents(documents_ids).await
|
197
219
|
end
|
198
220
|
alias delete_multiple_documents! delete_documents!
|
199
221
|
|
200
222
|
def delete_document(document_id)
|
201
223
|
encode_document = URI.encode_www_form_component(document_id)
|
202
|
-
http_delete "/indexes/#{@uid}/documents/#{encode_document}"
|
224
|
+
response = http_delete "/indexes/#{@uid}/documents/#{encode_document}"
|
225
|
+
|
226
|
+
Models::Task.new(response, task_endpoint)
|
203
227
|
end
|
204
228
|
alias delete_one_document delete_document
|
205
229
|
|
206
230
|
def delete_document!(document_id)
|
207
|
-
|
208
|
-
|
231
|
+
Utils.soft_deprecate(
|
232
|
+
'Index#delete_document!',
|
233
|
+
'index.delete_document(...).await'
|
234
|
+
)
|
235
|
+
|
236
|
+
delete_document(document_id).await
|
209
237
|
end
|
210
238
|
alias delete_one_document! delete_document!
|
211
239
|
|
212
240
|
def delete_all_documents
|
213
|
-
http_delete "/indexes/#{@uid}/documents"
|
241
|
+
response = http_delete "/indexes/#{@uid}/documents"
|
242
|
+
Models::Task.new(response, task_endpoint)
|
214
243
|
end
|
215
244
|
|
216
245
|
def delete_all_documents!
|
217
|
-
|
218
|
-
|
246
|
+
Utils.soft_deprecate(
|
247
|
+
'Index#delete_all_documents!',
|
248
|
+
'index.delete_all_documents(...).await'
|
249
|
+
)
|
250
|
+
|
251
|
+
delete_all_documents.await
|
219
252
|
end
|
220
253
|
|
221
254
|
### SEARCH
|
@@ -288,12 +321,14 @@ module MeiliSearch
|
|
288
321
|
alias get_settings settings
|
289
322
|
|
290
323
|
def update_settings(settings)
|
291
|
-
http_patch "/indexes/#{@uid}/settings", Utils.transform_attributes(settings)
|
324
|
+
response = http_patch "/indexes/#{@uid}/settings", Utils.transform_attributes(settings)
|
325
|
+
Models::Task.new(response, task_endpoint)
|
292
326
|
end
|
293
327
|
alias settings= update_settings
|
294
328
|
|
295
329
|
def reset_settings
|
296
|
-
http_delete "/indexes/#{@uid}/settings"
|
330
|
+
response = http_delete "/indexes/#{@uid}/settings"
|
331
|
+
Models::Task.new(response, task_endpoint)
|
297
332
|
end
|
298
333
|
|
299
334
|
### SETTINGS - RANKING RULES
|
@@ -304,12 +339,14 @@ module MeiliSearch
|
|
304
339
|
alias get_ranking_rules ranking_rules
|
305
340
|
|
306
341
|
def update_ranking_rules(ranking_rules)
|
307
|
-
http_put "/indexes/#{@uid}/settings/ranking-rules", ranking_rules
|
342
|
+
response = http_put "/indexes/#{@uid}/settings/ranking-rules", ranking_rules
|
343
|
+
Models::Task.new(response, task_endpoint)
|
308
344
|
end
|
309
345
|
alias ranking_rules= update_ranking_rules
|
310
346
|
|
311
347
|
def reset_ranking_rules
|
312
|
-
http_delete "/indexes/#{@uid}/settings/ranking-rules"
|
348
|
+
response = http_delete "/indexes/#{@uid}/settings/ranking-rules"
|
349
|
+
Models::Task.new(response, task_endpoint)
|
313
350
|
end
|
314
351
|
|
315
352
|
### SETTINGS - SYNONYMS
|
@@ -320,12 +357,14 @@ module MeiliSearch
|
|
320
357
|
alias get_synonyms synonyms
|
321
358
|
|
322
359
|
def update_synonyms(synonyms)
|
323
|
-
http_put "/indexes/#{@uid}/settings/synonyms", synonyms
|
360
|
+
response = http_put "/indexes/#{@uid}/settings/synonyms", synonyms
|
361
|
+
Models::Task.new(response, task_endpoint)
|
324
362
|
end
|
325
363
|
alias synonyms= update_synonyms
|
326
364
|
|
327
365
|
def reset_synonyms
|
328
|
-
http_delete "/indexes/#{@uid}/settings/synonyms"
|
366
|
+
response = http_delete "/indexes/#{@uid}/settings/synonyms"
|
367
|
+
Models::Task.new(response, task_endpoint)
|
329
368
|
end
|
330
369
|
|
331
370
|
### SETTINGS - STOP-WORDS
|
@@ -337,12 +376,14 @@ module MeiliSearch
|
|
337
376
|
|
338
377
|
def update_stop_words(stop_words)
|
339
378
|
body = stop_words.nil? || stop_words.is_a?(Array) ? stop_words : [stop_words]
|
340
|
-
http_put "/indexes/#{@uid}/settings/stop-words", body
|
379
|
+
response = http_put "/indexes/#{@uid}/settings/stop-words", body
|
380
|
+
Models::Task.new(response, task_endpoint)
|
341
381
|
end
|
342
382
|
alias stop_words= update_stop_words
|
343
383
|
|
344
384
|
def reset_stop_words
|
345
|
-
http_delete "/indexes/#{@uid}/settings/stop-words"
|
385
|
+
response = http_delete "/indexes/#{@uid}/settings/stop-words"
|
386
|
+
Models::Task.new(response, task_endpoint)
|
346
387
|
end
|
347
388
|
|
348
389
|
### SETTINGS - DINSTINCT ATTRIBUTE
|
@@ -353,12 +394,14 @@ module MeiliSearch
|
|
353
394
|
alias get_distinct_attribute distinct_attribute
|
354
395
|
|
355
396
|
def update_distinct_attribute(distinct_attribute)
|
356
|
-
http_put "/indexes/#{@uid}/settings/distinct-attribute", distinct_attribute
|
397
|
+
response = http_put "/indexes/#{@uid}/settings/distinct-attribute", distinct_attribute
|
398
|
+
Models::Task.new(response, task_endpoint)
|
357
399
|
end
|
358
400
|
alias distinct_attribute= update_distinct_attribute
|
359
401
|
|
360
402
|
def reset_distinct_attribute
|
361
|
-
http_delete "/indexes/#{@uid}/settings/distinct-attribute"
|
403
|
+
response = http_delete "/indexes/#{@uid}/settings/distinct-attribute"
|
404
|
+
Models::Task.new(response, task_endpoint)
|
362
405
|
end
|
363
406
|
|
364
407
|
### SETTINGS - SEARCHABLE ATTRIBUTES
|
@@ -369,12 +412,14 @@ module MeiliSearch
|
|
369
412
|
alias get_searchable_attributes searchable_attributes
|
370
413
|
|
371
414
|
def update_searchable_attributes(searchable_attributes)
|
372
|
-
http_put "/indexes/#{@uid}/settings/searchable-attributes", searchable_attributes
|
415
|
+
response = http_put "/indexes/#{@uid}/settings/searchable-attributes", searchable_attributes
|
416
|
+
Models::Task.new(response, task_endpoint)
|
373
417
|
end
|
374
418
|
alias searchable_attributes= update_searchable_attributes
|
375
419
|
|
376
420
|
def reset_searchable_attributes
|
377
|
-
http_delete "/indexes/#{@uid}/settings/searchable-attributes"
|
421
|
+
response = http_delete "/indexes/#{@uid}/settings/searchable-attributes"
|
422
|
+
Models::Task.new(response, task_endpoint)
|
378
423
|
end
|
379
424
|
|
380
425
|
### SETTINGS - DISPLAYED ATTRIBUTES
|
@@ -385,12 +430,14 @@ module MeiliSearch
|
|
385
430
|
alias get_displayed_attributes displayed_attributes
|
386
431
|
|
387
432
|
def update_displayed_attributes(displayed_attributes)
|
388
|
-
http_put "/indexes/#{@uid}/settings/displayed-attributes", displayed_attributes
|
433
|
+
response = http_put "/indexes/#{@uid}/settings/displayed-attributes", displayed_attributes
|
434
|
+
Models::Task.new(response, task_endpoint)
|
389
435
|
end
|
390
436
|
alias displayed_attributes= update_displayed_attributes
|
391
437
|
|
392
438
|
def reset_displayed_attributes
|
393
|
-
http_delete "/indexes/#{@uid}/settings/displayed-attributes"
|
439
|
+
response = http_delete "/indexes/#{@uid}/settings/displayed-attributes"
|
440
|
+
Models::Task.new(response, task_endpoint)
|
394
441
|
end
|
395
442
|
|
396
443
|
### SETTINGS - FILTERABLE ATTRIBUTES
|
@@ -401,12 +448,14 @@ module MeiliSearch
|
|
401
448
|
alias get_filterable_attributes filterable_attributes
|
402
449
|
|
403
450
|
def update_filterable_attributes(filterable_attributes)
|
404
|
-
http_put "/indexes/#{@uid}/settings/filterable-attributes", filterable_attributes
|
451
|
+
response = http_put "/indexes/#{@uid}/settings/filterable-attributes", filterable_attributes
|
452
|
+
Models::Task.new(response, task_endpoint)
|
405
453
|
end
|
406
454
|
alias filterable_attributes= update_filterable_attributes
|
407
455
|
|
408
456
|
def reset_filterable_attributes
|
409
|
-
http_delete "/indexes/#{@uid}/settings/filterable-attributes"
|
457
|
+
response = http_delete "/indexes/#{@uid}/settings/filterable-attributes"
|
458
|
+
Models::Task.new(response, task_endpoint)
|
410
459
|
end
|
411
460
|
|
412
461
|
### SETTINGS - SORTABLE ATTRIBUTES
|
@@ -417,12 +466,14 @@ module MeiliSearch
|
|
417
466
|
alias get_sortable_attributes sortable_attributes
|
418
467
|
|
419
468
|
def update_sortable_attributes(sortable_attributes)
|
420
|
-
http_put "/indexes/#{@uid}/settings/sortable-attributes", sortable_attributes
|
469
|
+
response = http_put "/indexes/#{@uid}/settings/sortable-attributes", sortable_attributes
|
470
|
+
Models::Task.new(response, task_endpoint)
|
421
471
|
end
|
422
472
|
alias sortable_attributes= update_sortable_attributes
|
423
473
|
|
424
474
|
def reset_sortable_attributes
|
425
|
-
http_delete "/indexes/#{@uid}/settings/sortable-attributes"
|
475
|
+
response = http_delete "/indexes/#{@uid}/settings/sortable-attributes"
|
476
|
+
Models::Task.new(response, task_endpoint)
|
426
477
|
end
|
427
478
|
|
428
479
|
### SETTINGS - PAGINATION
|
@@ -433,12 +484,14 @@ module MeiliSearch
|
|
433
484
|
alias get_pagination pagination
|
434
485
|
|
435
486
|
def update_pagination(pagination)
|
436
|
-
http_patch "/indexes/#{@uid}/settings/pagination", pagination
|
487
|
+
response = http_patch "/indexes/#{@uid}/settings/pagination", pagination
|
488
|
+
Models::Task.new(response, task_endpoint)
|
437
489
|
end
|
438
490
|
alias pagination= update_sortable_attributes
|
439
491
|
|
440
492
|
def reset_pagination
|
441
|
-
http_delete "/indexes/#{@uid}/settings/pagination"
|
493
|
+
response = http_delete "/indexes/#{@uid}/settings/pagination"
|
494
|
+
Models::Task.new(response, task_endpoint)
|
442
495
|
end
|
443
496
|
|
444
497
|
def typo_tolerance
|
@@ -448,12 +501,14 @@ module MeiliSearch
|
|
448
501
|
|
449
502
|
def update_typo_tolerance(typo_tolerance_attributes)
|
450
503
|
attributes = Utils.transform_attributes(typo_tolerance_attributes)
|
451
|
-
http_patch("/indexes/#{@uid}/settings/typo-tolerance", attributes)
|
504
|
+
response = http_patch("/indexes/#{@uid}/settings/typo-tolerance", attributes)
|
505
|
+
Models::Task.new(response, task_endpoint)
|
452
506
|
end
|
453
507
|
alias typo_tolerance= update_typo_tolerance
|
454
508
|
|
455
509
|
def reset_typo_tolerance
|
456
|
-
http_delete("/indexes/#{@uid}/settings/typo-tolerance")
|
510
|
+
response = http_delete("/indexes/#{@uid}/settings/typo-tolerance")
|
511
|
+
Models::Task.new(response, task_endpoint)
|
457
512
|
end
|
458
513
|
|
459
514
|
def faceting
|
@@ -463,12 +518,14 @@ module MeiliSearch
|
|
463
518
|
|
464
519
|
def update_faceting(faceting_attributes)
|
465
520
|
attributes = Utils.transform_attributes(faceting_attributes)
|
466
|
-
http_patch("/indexes/#{@uid}/settings/faceting", attributes)
|
521
|
+
response = http_patch("/indexes/#{@uid}/settings/faceting", attributes)
|
522
|
+
Models::Task.new(response, task_endpoint)
|
467
523
|
end
|
468
524
|
alias faceting= update_faceting
|
469
525
|
|
470
526
|
def reset_faceting
|
471
|
-
http_delete("/indexes/#{@uid}/settings/faceting")
|
527
|
+
response = http_delete("/indexes/#{@uid}/settings/faceting")
|
528
|
+
Models::Task.new(response, task_endpoint)
|
472
529
|
end
|
473
530
|
|
474
531
|
### SETTINGS - DICTIONARY
|
@@ -479,11 +536,13 @@ module MeiliSearch
|
|
479
536
|
|
480
537
|
def update_dictionary(dictionary_attributes)
|
481
538
|
attributes = Utils.transform_attributes(dictionary_attributes)
|
482
|
-
http_put("/indexes/#{@uid}/settings/dictionary", attributes)
|
539
|
+
response = http_put("/indexes/#{@uid}/settings/dictionary", attributes)
|
540
|
+
Models::Task.new(response, task_endpoint)
|
483
541
|
end
|
484
542
|
|
485
543
|
def reset_dictionary
|
486
|
-
http_delete("/indexes/#{@uid}/settings/dictionary")
|
544
|
+
response = http_delete("/indexes/#{@uid}/settings/dictionary")
|
545
|
+
Models::Task.new(response, task_endpoint)
|
487
546
|
end
|
488
547
|
### SETTINGS - SEPARATOR TOKENS
|
489
548
|
|
@@ -493,11 +552,13 @@ module MeiliSearch
|
|
493
552
|
|
494
553
|
def update_separator_tokens(separator_tokens_attributes)
|
495
554
|
attributes = Utils.transform_attributes(separator_tokens_attributes)
|
496
|
-
http_put("/indexes/#{@uid}/settings/separator-tokens", attributes)
|
555
|
+
response = http_put("/indexes/#{@uid}/settings/separator-tokens", attributes)
|
556
|
+
Models::Task.new(response, task_endpoint)
|
497
557
|
end
|
498
558
|
|
499
559
|
def reset_separator_tokens
|
500
|
-
http_delete("/indexes/#{@uid}/settings/separator-tokens")
|
560
|
+
response = http_delete("/indexes/#{@uid}/settings/separator-tokens")
|
561
|
+
Models::Task.new(response, task_endpoint)
|
501
562
|
end
|
502
563
|
|
503
564
|
### SETTINGS - NON SEPARATOR TOKENS
|
@@ -508,11 +569,13 @@ module MeiliSearch
|
|
508
569
|
|
509
570
|
def update_non_separator_tokens(non_separator_tokens_attributes)
|
510
571
|
attributes = Utils.transform_attributes(non_separator_tokens_attributes)
|
511
|
-
http_put("/indexes/#{@uid}/settings/non-separator-tokens", attributes)
|
572
|
+
response = http_put("/indexes/#{@uid}/settings/non-separator-tokens", attributes)
|
573
|
+
Models::Task.new(response, task_endpoint)
|
512
574
|
end
|
513
575
|
|
514
576
|
def reset_non_separator_tokens
|
515
|
-
http_delete("/indexes/#{@uid}/settings/non-separator-tokens")
|
577
|
+
response = http_delete("/indexes/#{@uid}/settings/non-separator-tokens")
|
578
|
+
Models::Task.new(response, task_endpoint)
|
516
579
|
end
|
517
580
|
|
518
581
|
### SETTINGS - PROXIMITY PRECISION
|
@@ -0,0 +1,160 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module MeiliSearch
|
6
|
+
module Models
|
7
|
+
class Task
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
# Maintain backwards compatibility with task hash return type
|
11
|
+
def_delegators :metadata, :[], :dig, :keys, :key?, :has_key?
|
12
|
+
|
13
|
+
attr_reader :metadata
|
14
|
+
|
15
|
+
def initialize(metadata_hash, task_endpoint)
|
16
|
+
self.metadata = metadata_hash
|
17
|
+
validate_required_fields! metadata
|
18
|
+
|
19
|
+
@task_endpoint = task_endpoint
|
20
|
+
end
|
21
|
+
|
22
|
+
def uid
|
23
|
+
@metadata['taskUid']
|
24
|
+
end
|
25
|
+
|
26
|
+
def type
|
27
|
+
@metadata['type']
|
28
|
+
end
|
29
|
+
|
30
|
+
def status
|
31
|
+
@metadata['status']
|
32
|
+
end
|
33
|
+
|
34
|
+
def enqueued?
|
35
|
+
refresh if status_enqueued?
|
36
|
+
|
37
|
+
status_enqueued?
|
38
|
+
end
|
39
|
+
|
40
|
+
def processing?
|
41
|
+
refresh if status_processing? || status_enqueued?
|
42
|
+
|
43
|
+
status_processing?
|
44
|
+
end
|
45
|
+
|
46
|
+
def unfinished?
|
47
|
+
refresh if status_processing? || status_enqueued?
|
48
|
+
|
49
|
+
status_processing? || status_enqueued?
|
50
|
+
end
|
51
|
+
alias waiting? unfinished?
|
52
|
+
|
53
|
+
def finished?
|
54
|
+
!unfinished?
|
55
|
+
end
|
56
|
+
|
57
|
+
def succeeded?
|
58
|
+
Utils.warn_on_unfinished_task(self) if unfinished?
|
59
|
+
|
60
|
+
status == 'succeeded'
|
61
|
+
end
|
62
|
+
alias has_succeeded? succeeded?
|
63
|
+
|
64
|
+
def failed?
|
65
|
+
Utils.warn_on_unfinished_task(self) if unfinished?
|
66
|
+
|
67
|
+
status == 'failed'
|
68
|
+
end
|
69
|
+
alias has_failed? failed?
|
70
|
+
|
71
|
+
def cancelled?
|
72
|
+
Utils.warn_on_unfinished_task(self) if unfinished?
|
73
|
+
|
74
|
+
status_cancelled?
|
75
|
+
end
|
76
|
+
|
77
|
+
def deleted?
|
78
|
+
refresh unless @deleted
|
79
|
+
|
80
|
+
!!@deleted
|
81
|
+
end
|
82
|
+
|
83
|
+
def error
|
84
|
+
@metadata['error']
|
85
|
+
end
|
86
|
+
|
87
|
+
def refresh(with: nil)
|
88
|
+
self.metadata = with || @task_endpoint.task(uid)
|
89
|
+
|
90
|
+
self
|
91
|
+
rescue MeiliSearch::ApiError => e
|
92
|
+
raise e unless e.http_code == 404
|
93
|
+
|
94
|
+
@deleted = true
|
95
|
+
|
96
|
+
self
|
97
|
+
end
|
98
|
+
|
99
|
+
def await(timeout_in_ms = 5000, interval_in_ms = 50)
|
100
|
+
refresh with: @task_endpoint.wait_for_task(uid, timeout_in_ms, interval_in_ms) unless finished?
|
101
|
+
|
102
|
+
self
|
103
|
+
end
|
104
|
+
|
105
|
+
def cancel
|
106
|
+
return true if status_cancelled?
|
107
|
+
return false if status_finished?
|
108
|
+
|
109
|
+
@task_endpoint.cancel_tasks(uids: [uid]).await
|
110
|
+
|
111
|
+
cancelled?
|
112
|
+
end
|
113
|
+
|
114
|
+
def delete
|
115
|
+
return false unless status_finished?
|
116
|
+
|
117
|
+
@task_endpoint.delete_tasks(uids: [uid]).await
|
118
|
+
|
119
|
+
deleted?
|
120
|
+
end
|
121
|
+
|
122
|
+
def to_h
|
123
|
+
@metadata
|
124
|
+
end
|
125
|
+
alias to_hash to_h
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def validate_required_fields!(task_hash)
|
130
|
+
raise ArgumentError, 'Cannot instantiate a task without an ID' unless task_hash['taskUid']
|
131
|
+
raise ArgumentError, 'Cannot instantiate a task without a type' unless task_hash['type']
|
132
|
+
raise ArgumentError, 'Cannot instantiate a task without a status' unless task_hash['status']
|
133
|
+
end
|
134
|
+
|
135
|
+
def status_enqueued?
|
136
|
+
status == 'enqueued'
|
137
|
+
end
|
138
|
+
|
139
|
+
def status_processing?
|
140
|
+
status == 'processing'
|
141
|
+
end
|
142
|
+
|
143
|
+
def status_finished?
|
144
|
+
['succeeded', 'failed', 'cancelled'].include? status
|
145
|
+
end
|
146
|
+
|
147
|
+
def status_cancelled?
|
148
|
+
status == 'cancelled'
|
149
|
+
end
|
150
|
+
|
151
|
+
def metadata=(metadata)
|
152
|
+
@metadata = metadata
|
153
|
+
|
154
|
+
uid = @metadata['taskUid'] || @metadata['uid']
|
155
|
+
@metadata['uid'] = uid
|
156
|
+
@metadata['taskUid'] = uid
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
data/lib/meilisearch/utils.rb
CHANGED
@@ -1,73 +1,98 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'logger'
|
4
|
+
|
3
5
|
module MeiliSearch
|
4
6
|
module Utils
|
5
7
|
SNAKE_CASE = /[^a-zA-Z0-9]+(.)/
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
class << self
|
10
|
+
attr_writer :logger
|
11
|
+
|
12
|
+
def logger
|
13
|
+
@logger ||= Logger.new($stdout)
|
14
|
+
end
|
15
|
+
|
16
|
+
def soft_deprecate(subject, replacement)
|
17
|
+
logger.warn("[meilisearch-ruby] #{subject} is DEPRECATED, please use #{replacement} instead.")
|
16
18
|
end
|
17
|
-
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
def warn_on_unfinished_task(task_uid)
|
21
|
+
message = <<~UNFINISHED_TASK_WARNING
|
22
|
+
[meilisearch-ruby] Task #{task_uid}'s finished state (succeeded?/failed?/cancelled?) is being checked before finishing.
|
23
|
+
[meilisearch-ruby] Tasks in meilisearch are processed in the background asynchronously.
|
24
|
+
[meilisearch-ruby] Please use the #finished? method to check if the task is finished or the #await method to wait for the task to finish.
|
25
|
+
UNFINISHED_TASK_WARNING
|
26
|
+
|
27
|
+
message.lines.each do |line|
|
28
|
+
logger.warn(line)
|
24
29
|
end
|
25
|
-
|
30
|
+
end
|
26
31
|
|
27
|
-
|
28
|
-
|
29
|
-
|
32
|
+
def transform_attributes(body)
|
33
|
+
case body
|
34
|
+
when Array
|
35
|
+
body.map { |item| transform_attributes(item) }
|
36
|
+
when Hash
|
37
|
+
warn_on_non_conforming_attribute_names(body)
|
38
|
+
parse(body)
|
39
|
+
else
|
40
|
+
body
|
41
|
+
end
|
42
|
+
end
|
30
43
|
|
31
|
-
|
32
|
-
|
44
|
+
def filter(original_options, allowed_params = [])
|
45
|
+
original_options.transform_keys(&:to_sym).slice(*allowed_params)
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse_query(original_options, allowed_params = [])
|
49
|
+
only_allowed_params = filter(original_options, allowed_params)
|
33
50
|
|
34
|
-
|
35
|
-
|
36
|
-
|
51
|
+
Utils.transform_attributes(only_allowed_params).then do |body|
|
52
|
+
body.transform_values do |v|
|
53
|
+
v.respond_to?(:join) ? v.join(',') : v.to_s
|
54
|
+
end
|
37
55
|
end
|
38
56
|
end
|
39
|
-
end
|
40
57
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
58
|
+
def version_error_handler(method_name)
|
59
|
+
yield if block_given?
|
60
|
+
rescue MeiliSearch::ApiError => e
|
61
|
+
message = message_builder(e.http_message, method_name)
|
45
62
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
63
|
+
raise MeiliSearch::ApiError.new(e.http_code, message, e.http_body)
|
64
|
+
rescue StandardError => e
|
65
|
+
raise e.class, message_builder(e.message, method_name)
|
66
|
+
end
|
50
67
|
|
51
|
-
|
52
|
-
|
53
|
-
raise e.class, message_builder(e.message, method_name)
|
54
|
-
end
|
68
|
+
def warn_on_non_conforming_attribute_names(body)
|
69
|
+
return if body.nil?
|
55
70
|
|
56
|
-
|
57
|
-
|
71
|
+
non_snake_case = body.keys.grep_v(/^[a-z0-9_]+$/)
|
72
|
+
return if non_snake_case.empty?
|
58
73
|
|
59
|
-
|
60
|
-
|
74
|
+
message = <<~MSG
|
75
|
+
[meilisearch-ruby] Attributes will be expected to be snake_case in future versions.
|
76
|
+
[meilisearch-ruby] Non-conforming attributes: #{non_snake_case.join(', ')}
|
77
|
+
MSG
|
61
78
|
|
62
|
-
|
63
|
-
|
79
|
+
logger.warn(message)
|
80
|
+
end
|
64
81
|
|
65
|
-
|
66
|
-
MSG
|
82
|
+
private
|
67
83
|
|
68
|
-
|
69
|
-
|
84
|
+
def parse(body)
|
85
|
+
body
|
86
|
+
.transform_keys(&:to_s)
|
87
|
+
.transform_keys do |key|
|
88
|
+
key.include?('_') ? key.downcase.gsub(SNAKE_CASE, &:upcase).gsub('_', '') : key
|
89
|
+
end
|
90
|
+
end
|
70
91
|
|
71
|
-
|
92
|
+
def message_builder(current_message, method_name)
|
93
|
+
"#{current_message}\nHint: It might not be working because maybe you're not up " \
|
94
|
+
"to date with the Meilisearch version that `#{method_name}` call requires."
|
95
|
+
end
|
96
|
+
end
|
72
97
|
end
|
73
98
|
end
|
data/lib/meilisearch/version.rb
CHANGED
data/lib/meilisearch.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meilisearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.27.
|
4
|
+
version: 0.27.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Meili
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- lib/meilisearch/error.rb
|
44
44
|
- lib/meilisearch/http_request.rb
|
45
45
|
- lib/meilisearch/index.rb
|
46
|
+
- lib/meilisearch/models/task.rb
|
46
47
|
- lib/meilisearch/multi_search.rb
|
47
48
|
- lib/meilisearch/task.rb
|
48
49
|
- lib/meilisearch/tenant_token.rb
|