meilisearch 0.18.2 → 0.19.1

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: 9b69f3c0d8bf43393b59abe4e44aabf40ff673dd08bde8f6e60d1c996be8b7bf
4
- data.tar.gz: d2ff90fe7e1cf738dc4e3297cf7e7215e80c7a63317d06144681fab39206d1b2
3
+ metadata.gz: baef66d6ee72247efa51f7789857e45da0380221c2c8bca1def9faf7c94604dc
4
+ data.tar.gz: 671cc838677bf43b043cad0157ee9132a0485d4099076fde963a13a4a27f5e54
5
5
  SHA512:
6
- metadata.gz: 59dfc2b7ced1fec8a75c32b4b02b49d42a8a63af862bcb86931692be8e9c92b89657b93958c150937ddbe295d645eff5192a181ef439885462c2f6174c1519c3
7
- data.tar.gz: 71b81d762f8c609a7e2d50ac0052e6c8e0b904c28b2cb7b98f0c55934122c97c1160a4c0b4a2659adcf474a59be85ea609a75183e69550ca4971d177afb8e2b0
6
+ metadata.gz: bab42e61c5daed521738024b4ff881ec36422aa820ea2dd009025d802d444cedabb208a31e9db8c15fd6dfc6ad6d0b900d14eeb34382fe33ae7d1bf3c4c5ed92
7
+ data.tar.gz: abc4c9088b6c396aa6256ed8d35aea3d06f74ec32cadf2645712baf452b3c6e85f490521bc805b885d7d0c84643378819bee3ccfa2be1dd1bdb90f86b97020d8
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019-2021 Meili
3
+ Copyright (c) 2019-2022 Meili SAS
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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.26.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.26.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)
@@ -57,8 +57,8 @@ module MeiliSearch
57
57
  class TimeoutError < StandardError
58
58
  attr_reader :message
59
59
 
60
- def initialize
61
- @message = 'The update was not processed in the expected time'
60
+ def initialize(message = nil)
61
+ @message = "The request was not processed in the expected time. #{message}"
62
62
  super(@message)
63
63
  end
64
64
  end
@@ -103,8 +103,10 @@ module MeiliSearch
103
103
 
104
104
  begin
105
105
  response = http_method.call(@base_url + relative_path, config)
106
- rescue Errno::ECONNREFUSED => e
106
+ rescue Errno::ECONNREFUSED, Errno::EPIPE => e
107
107
  raise CommunicationError, e.message
108
+ rescue Net::ReadTimeout, Net::OpenTimeout => e
109
+ raise TimeoutError, e.message
108
110
  end
109
111
 
110
112
  validate(response)
@@ -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,28 @@ 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
375
399
  end
376
400
  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.2'
4
+ VERSION = '0.19.1'
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.2
4
+ version: 0.19.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Meili
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-14 00:00:00.000000000 Z
11
+ date: 2022-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty