meilisearch 0.18.3 → 0.19.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9ffb59831da7243cc87f65a0cd0a0d11d311e4691fd1177779fae006f4a750d
4
- data.tar.gz: 04cd78aa37677107d08a355daa016d72d8be0d2980d1da27f1e5102dde45c661
3
+ metadata.gz: 67fd01c01f58eb04e3d5e8d33c12f66a6ed9601d743444d8ade60f93cd05e322
4
+ data.tar.gz: aa37afae83757583053e1fdd821ef8e87f0e518edbfe1c52c2abba3d27610b4a
5
5
  SHA512:
6
- metadata.gz: 1b7cc2bcb9f6c228397ca5cceaa9ad76c0fb3e522f29ea2231ac9a304c762fdc1cc2eda55deaeead572d5b8ab0468681db57b8fe6b28ee078a96324894a54a1c
7
- data.tar.gz: 551fc3177689b479102a2f23329ca7243ae768ba13d7ddeea48e09f531c8305fcd43207e5f20e9b3d28bf5e0c88d7e6ae5247ea115213abc890264369785fbfd
6
+ metadata.gz: 04b69743166d96c14954eb5a06ad77f1d8edd9b7e6884f8fc19f2235ee88897adc570cb68cc39357bedb993eaad0312979f746bf3773bbf54a130bb347b9fa25
7
+ data.tar.gz: 242457a2a1aacebcc754a7380976e289f9691bbf8c2d08a3395f70e2608ae4516286329316c28de0ec2fd342499d93b6384f1f14c04e98c21672f402a79de4c5
data/README.md CHANGED
@@ -187,8 +187,7 @@ JSON output:
187
187
  ]
188
188
  }
189
189
  ],
190
- "nbHits": 1,
191
- "exhaustiveNbHits": false,
190
+ "estimatedTotalHits": 1,
192
191
  "query": "wonder",
193
192
  "limit": 20,
194
193
  "offset": 0,
@@ -198,7 +197,7 @@ JSON output:
198
197
 
199
198
  ## 🤖 Compatibility with Meilisearch
200
199
 
201
- This package only guarantees the compatibility with the [version v0.27.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.27.0).
200
+ This package only guarantees the compatibility with the [version v0.28.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.28.0).
202
201
 
203
202
  ## 💡 Learn More
204
203
 
@@ -6,14 +6,20 @@ module MeiliSearch
6
6
 
7
7
  ### INDEXES
8
8
 
9
- def raw_indexes
10
- http_get('/indexes')
9
+ def raw_indexes(options = {})
10
+ body = Utils.transform_attributes(options.transform_keys(&:to_sym).slice(:limit, :offset))
11
+
12
+ http_get('/indexes', body)
11
13
  end
12
14
 
13
- def indexes
14
- raw_indexes.map do |index_hash|
15
+ def indexes(options = {})
16
+ response = raw_indexes(options)
17
+
18
+ response['results'].map! do |index_hash|
15
19
  index_object(index_hash['uid'], index_hash['primaryKey'])
16
20
  end
21
+
22
+ response
17
23
  end
18
24
 
19
25
  # Usage:
@@ -29,7 +35,7 @@ module MeiliSearch
29
35
  # Waits for the task to be achieved, be careful when using it.
30
36
  def create_index!(index_uid, options = {})
31
37
  task = create_index(index_uid, options)
32
- wait_for_task(task['uid'])
38
+ wait_for_task(task['taskUid'])
33
39
  end
34
40
 
35
41
  def delete_index(index_uid)
@@ -52,12 +58,14 @@ module MeiliSearch
52
58
 
53
59
  ### KEYS
54
60
 
55
- def keys
56
- http_get '/keys'
61
+ def keys(limit: nil, offset: nil)
62
+ body = { limit: limit, offset: offset }.compact
63
+
64
+ http_get '/keys', body
57
65
  end
58
66
 
59
- def key(key_uid)
60
- http_get "/keys/#{key_uid}"
67
+ def key(uid_or_key)
68
+ http_get "/keys/#{uid_or_key}"
61
69
  end
62
70
 
63
71
  def create_key(key_options)
@@ -66,14 +74,15 @@ module MeiliSearch
66
74
  http_post '/keys', body
67
75
  end
68
76
 
69
- def update_key(key_uid, key_options)
77
+ def update_key(uid_or_key, key_options)
70
78
  body = Utils.transform_attributes(key_options)
79
+ body = body.slice('description', 'name')
71
80
 
72
- http_patch "/keys/#{key_uid}", body
81
+ http_patch "/keys/#{uid_or_key}", body
73
82
  end
74
83
 
75
- def delete_key(key_uid)
76
- http_delete "/keys/#{key_uid}"
84
+ def delete_key(uid_or_key)
85
+ http_delete "/keys/#{uid_or_key}"
77
86
  end
78
87
 
79
88
  ### HEALTH
@@ -105,15 +114,10 @@ module MeiliSearch
105
114
  http_post '/dumps'
106
115
  end
107
116
 
108
- def dump_status(dump_uid)
109
- http_get "/dumps/#{dump_uid}/status"
110
- end
111
- alias get_dump_status dump_status
112
-
113
117
  ### TASKS
114
118
 
115
- def tasks
116
- task_endpoint.task_list
119
+ def tasks(options = {})
120
+ task_endpoint.task_list(options)
117
121
  end
118
122
 
119
123
  def task(task_uid)
@@ -90,7 +90,10 @@ module MeiliSearch
90
90
  {
91
91
  'Content-Type' => 'application/json',
92
92
  'Authorization' => ("Bearer #{@api_key}" unless @api_key.nil?),
93
- 'User-Agent' => MeiliSearch.qualified_version
93
+ 'User-Agent' => [
94
+ @options.fetch(:client_agents, []),
95
+ MeiliSearch.qualified_version
96
+ ].flatten.join(';')
94
97
  }.compact
95
98
  end
96
99
 
@@ -30,7 +30,7 @@ module MeiliSearch
30
30
  end
31
31
 
32
32
  def update(body)
33
- http_put indexes_path(id: @uid), Utils.transform_attributes(body)
33
+ http_patch indexes_path(id: @uid), Utils.transform_attributes(body)
34
34
  end
35
35
 
36
36
  alias update_index update
@@ -54,15 +54,20 @@ module MeiliSearch
54
54
 
55
55
  ### DOCUMENTS
56
56
 
57
- def document(document_id)
57
+ def document(document_id, fields: nil)
58
58
  encode_document = URI.encode_www_form_component(document_id)
59
- http_get "/indexes/#{@uid}/documents/#{encode_document}"
59
+ body = { fields: fields&.join(',') }.compact
60
+
61
+ http_get("/indexes/#{@uid}/documents/#{encode_document}", body)
60
62
  end
61
63
  alias get_document document
62
64
  alias get_one_document document
63
65
 
64
66
  def documents(options = {})
65
- http_get "/indexes/#{@uid}/documents", Utils.transform_attributes(options)
67
+ body = Utils.transform_attributes(options.transform_keys(&:to_sym).slice(:limit, :offset, :fields))
68
+ body = body.transform_values { |v| v.respond_to?(:join) ? v.join(',') : v }
69
+
70
+ http_get "/indexes/#{@uid}/documents", body
66
71
  end
67
72
  alias get_documents documents
68
73
 
@@ -75,7 +80,7 @@ module MeiliSearch
75
80
 
76
81
  def add_documents!(documents, primary_key = nil)
77
82
  task = add_documents(documents, primary_key)
78
- wait_for_task(task['uid'])
83
+ wait_for_task(task['taskUid'])
79
84
  end
80
85
  alias replace_documents! add_documents!
81
86
  alias add_or_replace_documents! add_documents!
@@ -109,7 +114,7 @@ module MeiliSearch
109
114
 
110
115
  def update_documents!(documents, primary_key = nil)
111
116
  task = update_documents(documents, primary_key)
112
- wait_for_task(task['uid'])
117
+ wait_for_task(task['taskUid'])
113
118
  end
114
119
  alias add_or_update_documents! update_documents!
115
120
 
@@ -125,7 +130,7 @@ module MeiliSearch
125
130
  tasks = add_documents_in_batches(documents, batch_size, primary_key)
126
131
  responses = []
127
132
  tasks.each do |task_obj|
128
- responses.append(wait_for_task(task_obj['uid']))
133
+ responses.append(wait_for_task(task_obj['taskUid']))
129
134
  end
130
135
  responses
131
136
  end
@@ -142,7 +147,7 @@ module MeiliSearch
142
147
  tasks = update_documents_in_batches(documents, batch_size, primary_key)
143
148
  responses = []
144
149
  tasks.each do |task_obj|
145
- responses.append(wait_for_task(task_obj['uid']))
150
+ responses.append(wait_for_task(task_obj['taskUid']))
146
151
  end
147
152
  responses
148
153
  end
@@ -158,7 +163,7 @@ module MeiliSearch
158
163
 
159
164
  def delete_documents!(documents_ids)
160
165
  task = delete_documents(documents_ids)
161
- wait_for_task(task['uid'])
166
+ wait_for_task(task['taskUid'])
162
167
  end
163
168
  alias delete_multiple_documents! delete_documents!
164
169
 
@@ -170,7 +175,7 @@ module MeiliSearch
170
175
 
171
176
  def delete_document!(document_id)
172
177
  task = delete_document(document_id)
173
- wait_for_task(task['uid'])
178
+ wait_for_task(task['taskUid'])
174
179
  end
175
180
  alias delete_one_document! delete_document!
176
181
 
@@ -180,7 +185,7 @@ module MeiliSearch
180
185
 
181
186
  def delete_all_documents!
182
187
  task = delete_all_documents
183
- wait_for_task(task['uid'])
188
+ wait_for_task(task['taskUid'])
184
189
  end
185
190
 
186
191
  ### SEARCH
@@ -188,7 +193,10 @@ module MeiliSearch
188
193
  def search(query, options = {})
189
194
  parsed_options = Utils.transform_attributes({ q: query.to_s }.merge(options.compact))
190
195
 
191
- http_post "/indexes/#{@uid}/search", parsed_options
196
+ response = http_post "/indexes/#{@uid}/search", parsed_options
197
+ response['nbHits'] ||= response['estimatedTotalHits']
198
+
199
+ response
192
200
  end
193
201
 
194
202
  ### TASKS
@@ -199,7 +207,7 @@ module MeiliSearch
199
207
  private :task_endpoint
200
208
 
201
209
  def task(task_uid)
202
- task_endpoint.index_task(@uid, task_uid)
210
+ task_endpoint.index_task(task_uid)
203
211
  end
204
212
 
205
213
  def tasks
@@ -236,7 +244,7 @@ module MeiliSearch
236
244
  alias get_settings settings
237
245
 
238
246
  def update_settings(settings)
239
- http_post "/indexes/#{@uid}/settings", Utils.transform_attributes(settings)
247
+ http_patch "/indexes/#{@uid}/settings", Utils.transform_attributes(settings)
240
248
  end
241
249
  alias settings= update_settings
242
250
 
@@ -252,7 +260,7 @@ module MeiliSearch
252
260
  alias get_ranking_rules ranking_rules
253
261
 
254
262
  def update_ranking_rules(ranking_rules)
255
- http_post "/indexes/#{@uid}/settings/ranking-rules", ranking_rules
263
+ http_put "/indexes/#{@uid}/settings/ranking-rules", ranking_rules
256
264
  end
257
265
  alias ranking_rules= update_ranking_rules
258
266
 
@@ -268,7 +276,7 @@ module MeiliSearch
268
276
  alias get_synonyms synonyms
269
277
 
270
278
  def update_synonyms(synonyms)
271
- http_post "/indexes/#{@uid}/settings/synonyms", synonyms
279
+ http_put "/indexes/#{@uid}/settings/synonyms", synonyms
272
280
  end
273
281
  alias synonyms= update_synonyms
274
282
 
@@ -285,7 +293,7 @@ module MeiliSearch
285
293
 
286
294
  def update_stop_words(stop_words)
287
295
  body = stop_words.nil? || stop_words.is_a?(Array) ? stop_words : [stop_words]
288
- http_post "/indexes/#{@uid}/settings/stop-words", body
296
+ http_put "/indexes/#{@uid}/settings/stop-words", body
289
297
  end
290
298
  alias stop_words= update_stop_words
291
299
 
@@ -301,7 +309,7 @@ module MeiliSearch
301
309
  alias get_distinct_attribute distinct_attribute
302
310
 
303
311
  def update_distinct_attribute(distinct_attribute)
304
- http_post "/indexes/#{@uid}/settings/distinct-attribute", distinct_attribute
312
+ http_put "/indexes/#{@uid}/settings/distinct-attribute", distinct_attribute
305
313
  end
306
314
  alias distinct_attribute= update_distinct_attribute
307
315
 
@@ -317,7 +325,7 @@ module MeiliSearch
317
325
  alias get_searchable_attributes searchable_attributes
318
326
 
319
327
  def update_searchable_attributes(searchable_attributes)
320
- http_post "/indexes/#{@uid}/settings/searchable-attributes", searchable_attributes
328
+ http_put "/indexes/#{@uid}/settings/searchable-attributes", searchable_attributes
321
329
  end
322
330
  alias searchable_attributes= update_searchable_attributes
323
331
 
@@ -333,7 +341,7 @@ module MeiliSearch
333
341
  alias get_displayed_attributes displayed_attributes
334
342
 
335
343
  def update_displayed_attributes(displayed_attributes)
336
- http_post "/indexes/#{@uid}/settings/displayed-attributes", displayed_attributes
344
+ http_put "/indexes/#{@uid}/settings/displayed-attributes", displayed_attributes
337
345
  end
338
346
  alias displayed_attributes= update_displayed_attributes
339
347
 
@@ -349,7 +357,7 @@ module MeiliSearch
349
357
  alias get_filterable_attributes filterable_attributes
350
358
 
351
359
  def update_filterable_attributes(filterable_attributes)
352
- http_post "/indexes/#{@uid}/settings/filterable-attributes", filterable_attributes
360
+ http_put "/indexes/#{@uid}/settings/filterable-attributes", filterable_attributes
353
361
  end
354
362
  alias filterable_attributes= update_filterable_attributes
355
363
 
@@ -365,12 +373,58 @@ module MeiliSearch
365
373
  alias get_sortable_attributes sortable_attributes
366
374
 
367
375
  def update_sortable_attributes(sortable_attributes)
368
- http_post "/indexes/#{@uid}/settings/sortable-attributes", sortable_attributes
376
+ http_put "/indexes/#{@uid}/settings/sortable-attributes", sortable_attributes
369
377
  end
370
378
  alias sortable_attributes= update_sortable_attributes
371
379
 
372
380
  def reset_sortable_attributes
373
381
  http_delete "/indexes/#{@uid}/settings/sortable-attributes"
374
382
  end
383
+
384
+ ### SETTINGS - PAGINATION
385
+
386
+ def pagination
387
+ http_get("/indexes/#{@uid}/settings/pagination")
388
+ end
389
+ alias get_pagination pagination
390
+
391
+ def update_pagination(pagination)
392
+ http_patch "/indexes/#{@uid}/settings/pagination", pagination
393
+ end
394
+ alias pagination= update_sortable_attributes
395
+
396
+ def reset_pagination
397
+ http_delete "/indexes/#{@uid}/settings/pagination"
398
+ end
399
+
400
+ def typo_tolerance
401
+ http_get("/indexes/#{@uid}/settings/typo-tolerance")
402
+ end
403
+ alias get_typo_tolerance typo_tolerance
404
+
405
+ def update_typo_tolerance(typo_tolerance_attributes)
406
+ attributes = Utils.transform_attributes(typo_tolerance_attributes)
407
+ http_patch("/indexes/#{@uid}/settings/typo-tolerance", attributes)
408
+ end
409
+ alias typo_tolerance= update_typo_tolerance
410
+
411
+ def reset_typo_tolerance
412
+ http_delete("/indexes/#{@uid}/settings/typo-tolerance")
413
+ end
414
+
415
+ def faceting
416
+ http_get("/indexes/#{@uid}/settings/faceting")
417
+ end
418
+ alias get_faceting faceting
419
+
420
+ def update_faceting(faceting_attributes)
421
+ attributes = Utils.transform_attributes(faceting_attributes)
422
+ http_patch("/indexes/#{@uid}/settings/faceting", attributes)
423
+ end
424
+ alias faceting= update_faceting
425
+
426
+ def reset_faceting
427
+ http_delete("/indexes/#{@uid}/settings/faceting")
428
+ end
375
429
  end
376
430
  end
@@ -5,8 +5,13 @@ require 'timeout'
5
5
 
6
6
  module MeiliSearch
7
7
  class Task < HTTPRequest
8
- def task_list
9
- http_get '/tasks/'
8
+ ALLOWED_PARAMS = [:limit, :from, :index_uid, :type, :status].freeze
9
+
10
+ def task_list(options = {})
11
+ body = Utils.transform_attributes(options.transform_keys(&:to_sym).slice(*ALLOWED_PARAMS))
12
+ body = body.transform_values { |v| v.respond_to?(:join) ? v.join(',') : v }
13
+
14
+ http_get '/tasks/', body
10
15
  end
11
16
 
12
17
  def task(task_uid)
@@ -14,11 +19,11 @@ module MeiliSearch
14
19
  end
15
20
 
16
21
  def index_tasks(index_uid)
17
- http_get "/indexes/#{index_uid}/tasks"
22
+ http_get '/tasks', { indexUid: [index_uid].flatten.join(',') }
18
23
  end
19
24
 
20
- def index_task(index_uid, task_uid)
21
- http_get "/indexes/#{index_uid}/tasks/#{task_uid}"
25
+ def index_task(task_uid)
26
+ http_get "/tasks/#{task_uid}"
22
27
  end
23
28
 
24
29
  def wait_for_task(task_uid, timeout_in_ms = 5000, interval_in_ms = 50)
@@ -7,21 +7,21 @@ module MeiliSearch
7
7
  alg: 'HS256'
8
8
  }.freeze
9
9
 
10
- def generate_tenant_token(search_rules, api_key: nil, expires_at: nil)
10
+ def generate_tenant_token(api_key_uid, search_rules, api_key: nil, expires_at: nil)
11
11
  signature = retrieve_valid_key!(api_key, @api_key)
12
12
  expiration = validate_expires_at!(expires_at)
13
13
  rules = validate_search_rules!(search_rules)
14
- unsigned_data = build_payload(expiration, rules, signature)
14
+ unsigned_data = build_payload(expiration, rules, api_key_uid)
15
15
 
16
16
  combine(unsigned_data, to_base64(sign_data(signature, unsigned_data)))
17
17
  end
18
18
 
19
19
  private
20
20
 
21
- def build_payload(expiration, rules, signature)
21
+ def build_payload(expiration, rules, api_key_uid)
22
22
  payload = {
23
23
  searchRules: rules,
24
- apiKeyPrefix: signature[0..7],
24
+ apiKeyUid: api_key_uid,
25
25
  exp: expiration
26
26
  }
27
27
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MeiliSearch
4
- VERSION = '0.18.3'
4
+ VERSION = '0.19.2'
5
5
 
6
6
  def self.qualified_version
7
7
  "Meilisearch Ruby (v#{VERSION})"
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.18.3
4
+ version: 0.19.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Meili
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-09 00:00:00.000000000 Z
11
+ date: 2022-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty