meilisearch 0.32.0 → 0.33.0

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.
@@ -3,6 +3,11 @@
3
3
  require 'meilisearch/http_request'
4
4
 
5
5
  module Meilisearch
6
+ # Manages a Meilisearch indexes.
7
+ # index = client.index(INDEX_UID)
8
+ #
9
+ # Indexes store documents to be searched.
10
+ # @see https://www.meilisearch.com/docs/learn/getting_started/indexes Learn more about indexes
6
11
  class Index < HTTPRequest
7
12
  attr_reader :uid, :primary_key, :created_at, :updated_at
8
13
 
@@ -12,23 +17,56 @@ module Meilisearch
12
17
  super(url, api_key, options)
13
18
  end
14
19
 
20
+ # Fetch the latest info about the index from the Meilisearch instance and return self.
21
+ #
22
+ # @see https://www.meilisearch.com/docs/reference/api/indexes#get-one-index Meilisearch API Reference
23
+ # @return [self]
15
24
  def fetch_info
16
25
  index_hash = http_get indexes_path(id: @uid)
17
26
  set_base_properties index_hash
18
27
  self
19
28
  end
20
29
 
30
+ # Fetch the latest info about the index from the Meilisearch instance and return the primary key.
31
+ #
32
+ # @see https://www.meilisearch.com/docs/reference/api/indexes#get-one-index Meilisearch API Reference
33
+ # @return [String]
21
34
  def fetch_primary_key
22
35
  fetch_info.primary_key
23
36
  end
24
37
  alias get_primary_key fetch_primary_key
25
38
 
39
+ # Fetch the latest info about the index from the Meilisearch instance and return the raw hash.
40
+ #
41
+ # @see https://www.meilisearch.com/docs/reference/api/indexes#get-one-index Meilisearch API Reference
42
+ # @return [Hash{String => String}]
26
43
  def fetch_raw_info
27
44
  index_hash = http_get indexes_path(id: @uid)
28
45
  set_base_properties index_hash
29
46
  index_hash
30
47
  end
31
48
 
49
+ # Update index uid (rename) and/or primary key.
50
+ #
51
+ # Rename an index by providing a new uid:
52
+ # client.index('movies').update(uid: 'films')
53
+ #
54
+ # Update the primary key:
55
+ # client.index('movies').update(primary_key: 'movie_id')
56
+ #
57
+ # Or do both at once:
58
+ # client.index('movies').update(uid: 'films', primary_key: 'movie_id')
59
+ #
60
+ # When renaming an index, all documents, settings, and stats are preserved.
61
+ # Renaming fails if the target uid already exists, the index is missing, or the uid format is invalid.
62
+ #
63
+ # To swap the names of two indexes atomically, see {Client#swap_indexes} instead.
64
+ #
65
+ # @see https://www.meilisearch.com/docs/reference/api/indexes#update-an-index Meilisearch API Reference
66
+ # @param body [Hash{String => String}] The options hash to update the index
67
+ # @option body [String] :uid The new uid for the index (to rename it)
68
+ # @option body [String] :primary_key The new primary key for the index
69
+ # @return [Models::Task] Task tracking the update
32
70
  def update(body)
33
71
  response = http_patch indexes_path(id: @uid), Utils.transform_attributes(body)
34
72
  Models::Task.new(response, task_endpoint)
@@ -36,6 +74,9 @@ module Meilisearch
36
74
 
37
75
  alias update_index update
38
76
 
77
+ # Delete index
78
+ #
79
+ # @see https://www.meilisearch.com/docs/reference/api/indexes#delete-an-index Meilisearch API Reference
39
80
  def delete
40
81
  response = http_delete indexes_path(id: @uid)
41
82
  Models::Task.new(response, task_endpoint)
@@ -56,6 +97,12 @@ module Meilisearch
56
97
 
57
98
  ### DOCUMENTS
58
99
 
100
+ # Get a document, optionally limiting fields.
101
+ #
102
+ # @param document_id [String, Integer] The ID of the document to fetch
103
+ # @param fields [nil, Array<Symbol>] Fields to fetch from the document, defaults to all
104
+ # @return [nil, Hash{String => Object}] The requested document.
105
+ # @see https://www.meilisearch.com/docs/reference/api/documents#get-one-document Meilisearch API Reference
59
106
  def document(document_id, fields: nil)
60
107
  encode_document = URI.encode_www_form_component(document_id)
61
108
  body = { fields: fields&.join(',') }.compact
@@ -65,27 +112,49 @@ module Meilisearch
65
112
  alias get_document document
66
113
  alias get_one_document document
67
114
 
68
- # Public: Retrieve documents from a index.
115
+ # Retrieve documents from a index.
69
116
  #
70
- # options - The hash options used to refine the selection (default: {}):
117
+ # @param options [Hash{Symbol => Object}] The hash options used to refine the selection (default: {}):
71
118
  # :limit - Number of documents to return (optional).
72
119
  # :offset - Number of documents to skip (optional).
73
120
  # :fields - Array of document attributes to show (optional).
74
121
  # :filter - Filter queries by an attribute's value.
75
122
  # Available ONLY with Meilisearch v1.2 and newer (optional).
123
+ # :sort - A list of attributes written as an array or as a comma-separated string (optional)
124
+ # :ids - Array of ids to be retrieved (optional)
76
125
  #
77
- # Returns the documents results object.
126
+ # @return [Hash{String => Object}] The documents results object.
127
+ # @see https://www.meilisearch.com/docs/reference/api/documents#get-documents-with-post Meilisearch API Reference
78
128
  def documents(options = {})
79
129
  Utils.version_error_handler(__method__) do
80
130
  if options.key?(:filter)
81
- http_post "/indexes/#{@uid}/documents/fetch", Utils.filter(options, [:limit, :offset, :fields, :filter])
131
+ http_post "/indexes/#{@uid}/documents/fetch", Utils.filter(options, [:limit, :offset, :fields, :filter, :sort, :ids])
82
132
  else
83
- http_get "/indexes/#{@uid}/documents", Utils.parse_query(options, [:limit, :offset, :fields])
133
+ http_get "/indexes/#{@uid}/documents", Utils.parse_query(options, [:limit, :offset, :fields, :sort, :ids])
84
134
  end
85
135
  end
86
136
  end
87
137
  alias get_documents documents
88
138
 
139
+ # Add documents to an index.
140
+ #
141
+ # Documents that already exist in the index are overwritten, with missing fields removed. Identitiy is checked by the value of the primary key field.
142
+ #
143
+ # client.index('movies').add_documents([
144
+ # {
145
+ # id: 287947,
146
+ # title: 'Shazam',
147
+ # poster: 'https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg',
148
+ # overview: 'A boy is given the ability to become an adult superhero in times of need with a single magic word.',
149
+ # release_date: '2019-03-23'
150
+ # }
151
+ # ])
152
+ #
153
+ # @param documents [Array<Hash{Object => Object>}] The documents to be added.
154
+ # @param primary_key [String] The name of the primary key field, auto inferred if missing.
155
+ #
156
+ # @return [Models::Task] The async task that adds the documents.
157
+ # @see https://www.meilisearch.com/docs/reference/api/documents#add-or-replace-documents Meilisearch API Reference
89
158
  def add_documents(documents, primary_key = nil)
90
159
  documents = [documents] if documents.is_a?(Hash)
91
160
  response = http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact
@@ -95,6 +164,14 @@ module Meilisearch
95
164
  alias replace_documents add_documents
96
165
  alias add_or_replace_documents add_documents
97
166
 
167
+ # Synchronous version of {#add_documents}.
168
+ #
169
+ # @deprecated
170
+ # use {Models::Task#await} on task returned from {#add_documents}
171
+ #
172
+ # index.add_documents(...).await
173
+ #
174
+ # Waits for the task to be achieved with a busy loop, be careful when using it.
98
175
  def add_documents!(documents, primary_key = nil)
99
176
  Utils.soft_deprecate(
100
177
  'Index#add_documents!',
@@ -106,6 +183,14 @@ module Meilisearch
106
183
  alias replace_documents! add_documents!
107
184
  alias add_or_replace_documents! add_documents!
108
185
 
186
+ # Add or replace documents from a JSON string.
187
+ #
188
+ # Documents that already exist in the index are overwritten, with missing fields removed. Identitiy is checked by the value of the primary key field.
189
+ #
190
+ # @param documents [String] JSON document that includes your documents.
191
+ # @param primary_key [String] The name of the primary key field, auto inferred if missing.
192
+ #
193
+ # @return [Models::Task] The async task that adds the documents.
109
194
  def add_documents_json(documents, primary_key = nil)
110
195
  options = { convert_body?: false }
111
196
  response = http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options
@@ -115,6 +200,17 @@ module Meilisearch
115
200
  alias replace_documents_json add_documents_json
116
201
  alias add_or_replace_documents_json add_documents_json
117
202
 
203
+ # Add or replace documents from a NDJSON string.
204
+ #
205
+ # Documents that already exist in the index are overwritten, with missing fields removed. Identitiy is checked by the value of the primary key field.
206
+ # Newline delimited JSON is a JSON specification that is easier to stream.
207
+ #
208
+ # @param documents [String] JSON document that includes your documents.
209
+ # @param primary_key [String] The name of the primary key field, auto inferred if missing.
210
+ #
211
+ # @return [Models::Task] The async task that adds the documents.
212
+ #
213
+ # @see https://github.com/ndjson/ndjson-spec NDJSON spec
118
214
  def add_documents_ndjson(documents, primary_key = nil)
119
215
  options = { headers: { 'Content-Type' => 'application/x-ndjson' }, convert_body?: false }
120
216
  response = http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options
@@ -124,6 +220,16 @@ module Meilisearch
124
220
  alias replace_documents_ndjson add_documents_ndjson
125
221
  alias add_or_replace_documents_ndjson add_documents_ndjson
126
222
 
223
+ # Add or replace documents from a CSV string.
224
+ #
225
+ # Documents that already exist in the index are overwritten, with missing fields removed. Identitiy is checked by the value of the primary key field.
226
+ # CSV text is delimited by commas by default but Meilisearch allows specifying custom delimeters.
227
+ #
228
+ # @param documents [String] JSON document that includes your documents.
229
+ # @param primary_key [String] The name of the primary key field, auto inferred if missing.
230
+ # @param delimiter [String] The delimiter character in your CSV text.
231
+ #
232
+ # @return [Models::Task] The async task that adds the documents.
127
233
  def add_documents_csv(documents, primary_key = nil, delimiter = nil)
128
234
  options = { headers: { 'Content-Type' => 'text/csv' }, convert_body?: false }
129
235
 
@@ -137,6 +243,15 @@ module Meilisearch
137
243
  alias replace_documents_csv add_documents_csv
138
244
  alias add_or_replace_documents_csv add_documents_csv
139
245
 
246
+ # Add documents to an index.
247
+ #
248
+ # Documents that already exist in the index are updated, with missing fields ignored. Identitiy is checked by the value of the primary key field.
249
+ #
250
+ # @param documents [Array<Hash{Object => Object>}] The documents to be added.
251
+ # @param primary_key [String] The name of the primary key field, auto inferred if missing.
252
+ #
253
+ # @return [Models::Task] The async task that adds the documents.
254
+ # @see https://www.meilisearch.com/docs/reference/api/documents#add-or-replace-documents Meilisearch API Reference
140
255
  def update_documents(documents, primary_key = nil)
141
256
  documents = [documents] if documents.is_a?(Hash)
142
257
  response = http_put "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact
@@ -145,6 +260,14 @@ module Meilisearch
145
260
  end
146
261
  alias add_or_update_documents update_documents
147
262
 
263
+ # Add or update documents from a JSON string.
264
+ #
265
+ # Documents that already exist in the index are updated, with missing fields ignored. Identitiy is checked by the value of the primary key field.
266
+ #
267
+ # @param documents [String] JSON document that includes your documents.
268
+ # @param primary_key [String] The name of the primary key field, auto inferred if missing.
269
+ #
270
+ # @return [Models::Task] The async task that adds the documents.
148
271
  def update_documents_json(documents, primary_key = nil)
149
272
  options = { convert_body?: false }
150
273
  response = http_put "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options
@@ -153,6 +276,17 @@ module Meilisearch
153
276
  end
154
277
  alias add_or_update_documents_json update_documents_json
155
278
 
279
+ # Add or update documents from a NDJSON string.
280
+ #
281
+ # Documents that already exist in the index are updated, with missing fields ignored. Identitiy is checked by the value of the primary key field.
282
+ # Newline delimited JSON is a JSON specification that is easier to stream.
283
+ #
284
+ # @param documents [String] JSON document that includes your documents.
285
+ # @param primary_key [String] The name of the primary key field, auto inferred if missing.
286
+ #
287
+ # @return [Models::Task] The async task that adds the documents.
288
+ #
289
+ # @see https://github.com/ndjson/ndjson-spec NDJSON spec
156
290
  def update_documents_ndjson(documents, primary_key = nil)
157
291
  options = { headers: { 'Content-Type' => 'application/x-ndjson' }, convert_body?: false }
158
292
  response = http_put "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options
@@ -161,6 +295,16 @@ module Meilisearch
161
295
  end
162
296
  alias add_or_update_documents_ndjson update_documents_ndjson
163
297
 
298
+ # Add or update documents from a CSV string.
299
+ #
300
+ # Documents that already exist in the index are updated, with missing fields ignored. Identitiy is checked by the value of the primary key field.
301
+ # CSV text is delimited by commas by default but Meilisearch allows specifying custom delimeters.
302
+ #
303
+ # @param documents [String] JSON document that includes your documents.
304
+ # @param primary_key [String] The name of the primary key field, auto inferred if missing.
305
+ # @param delimiter [String] The delimiter character in your CSV text.
306
+ #
307
+ # @return [Models::Task] The async task that adds the documents.
164
308
  def update_documents_csv(documents, primary_key = nil, delimiter = nil)
165
309
  options = { headers: { 'Content-Type' => 'text/csv' }, convert_body?: false }
166
310
 
@@ -173,12 +317,29 @@ module Meilisearch
173
317
  end
174
318
  alias add_or_update_documents_csv add_documents_csv
175
319
 
320
+ # Batched version of {#update_documents_ndjson}
321
+ #
322
+ # @param documents [String] JSON document that includes your documents.
323
+ # @param batch_size [Integer] The number of documents to update at a time.
324
+ # @param primary_key [String] The name of the primary key field, auto inferred if missing.
325
+ #
326
+ # @return [Array<Models::Task>] An array of tasks for each batch.
327
+ #
328
+ # @see https://github.com/ndjson/ndjson-spec NDJSON spec
176
329
  def update_documents_ndjson_in_batches(documents, batch_size = 1000, primary_key = nil)
177
330
  documents.lines.each_slice(batch_size).map do |batch|
178
331
  update_documents_ndjson(batch.join, primary_key)
179
332
  end
180
333
  end
181
334
 
335
+ # Batched version of {#update_documents_csv}.
336
+ #
337
+ # @param documents [String] JSON document that includes your documents.
338
+ # @param batch_size [Integer] The number of documents to update at a time.
339
+ # @param primary_key [String] The name of the primary key field, auto inferred if missing.
340
+ # @param delimiter [String] The delimiter character in your CSV text.
341
+ #
342
+ # @return [Array<Models::Task>] An array of tasks for each batch.
182
343
  def update_documents_csv_in_batches(documents, batch_size = 1000, primary_key = nil, delimiter = nil)
183
344
  lines = documents.lines
184
345
  heading = lines.first
@@ -187,6 +348,14 @@ module Meilisearch
187
348
  end
188
349
  end
189
350
 
351
+ # Synchronous version of {#update_documents}.
352
+ #
353
+ # @deprecated
354
+ # use {Models::Task#await} on task returned from {#update_documents}
355
+ #
356
+ # index.update_documents(...).await
357
+ #
358
+ # Waits for the task to be achieved with a busy loop, be careful when using it.
190
359
  def update_documents!(documents, primary_key = nil)
191
360
  Utils.soft_deprecate(
192
361
  'Index#update_documents!',
@@ -197,18 +366,40 @@ module Meilisearch
197
366
  end
198
367
  alias add_or_update_documents! update_documents!
199
368
 
369
+ # Batched version of {#add_documents}.
370
+ #
371
+ # @param documents [String] JSON document that includes your documents.
372
+ # @param batch_size [Integer] The number of documents to update at a time.
373
+ # @param primary_key [String] The name of the primary key field, auto inferred if missing.
374
+ #
375
+ # @return [Array<Models::Task>] An array of tasks for each batch.
200
376
  def add_documents_in_batches(documents, batch_size = 1000, primary_key = nil)
201
377
  documents.each_slice(batch_size).map do |batch|
202
378
  add_documents(batch, primary_key)
203
379
  end
204
380
  end
205
381
 
382
+ # Batched version of {#add_documents_ndjson}.
383
+ #
384
+ # @param documents [String] JSON document that includes your documents.
385
+ # @param batch_size [Integer] The number of documents to update at a time.
386
+ # @param primary_key [String] The name of the primary key field, auto inferred if missing.
387
+ #
388
+ # @return [Array<Models::Task>] An array of tasks for each batch.
206
389
  def add_documents_ndjson_in_batches(documents, batch_size = 1000, primary_key = nil)
207
390
  documents.lines.each_slice(batch_size).map do |batch|
208
391
  add_documents_ndjson(batch.join, primary_key)
209
392
  end
210
393
  end
211
394
 
395
+ # Batched version of {#add_documents_csv}.
396
+ #
397
+ # @param documents [String] JSON document that includes your documents.
398
+ # @param batch_size [Integer] The number of documents to update at a time.
399
+ # @param primary_key [String] The name of the primary key field, auto inferred if missing.
400
+ # @param delimiter [String] The delimiter character in your CSV text.
401
+ #
402
+ # @return [Array<Models::Task>] An array of tasks for each batch.
212
403
  def add_documents_csv_in_batches(documents, batch_size = 1000, primary_key = nil, delimiter = nil)
213
404
  lines = documents.lines
214
405
  heading = lines.first
@@ -217,6 +408,14 @@ module Meilisearch
217
408
  end
218
409
  end
219
410
 
411
+ # Synchronous version of {#add_documents_in_batches}.
412
+ #
413
+ # @deprecated
414
+ # use {Models::Task#await} on task returned from {#add_documents_in_batches}
415
+ #
416
+ # index.add_documents_in_batches(...).await
417
+ #
418
+ # Waits for the task to be achieved with a busy loop, be careful when using it.
220
419
  def add_documents_in_batches!(documents, batch_size = 1000, primary_key = nil)
221
420
  Utils.soft_deprecate(
222
421
  'Index#add_documents_in_batches!',
@@ -226,12 +425,27 @@ module Meilisearch
226
425
  add_documents_in_batches(documents, batch_size, primary_key).each(&:await)
227
426
  end
228
427
 
428
+ # Batched version of {#update_documents}.
429
+ #
430
+ # @param documents [String] JSON document that includes your documents.
431
+ # @param batch_size [Integer] The number of documents to update at a time.
432
+ # @param primary_key [String] The name of the primary key field, auto inferred if missing.
433
+ #
434
+ # @return [Array<Models::Task>] An array of tasks for each batch.
229
435
  def update_documents_in_batches(documents, batch_size = 1000, primary_key = nil)
230
436
  documents.each_slice(batch_size).map do |batch|
231
437
  update_documents(batch, primary_key)
232
438
  end
233
439
  end
234
440
 
441
+ # Synchronous version of {#update_documents_in_batches}.
442
+ #
443
+ # @deprecated
444
+ # use {Models::Task#await} on task returned from {#update_documents_in_batches}
445
+ #
446
+ # index.update_documents_in_batches(...).await
447
+ #
448
+ # Waits for the task to be achieved with a busy loop, be careful when using it.
235
449
  def update_documents_in_batches!(documents, batch_size = 1000, primary_key = nil)
236
450
  Utils.soft_deprecate(
237
451
  'Index#update_documents_in_batches!',
@@ -243,23 +457,25 @@ module Meilisearch
243
457
 
244
458
  # Update documents by function
245
459
  #
246
- # options - A Hash containing the function string and related options
247
- # context:
248
- # filter:
249
- # function:
460
+ # @param options [Hash{String => Object}]
461
+ #
462
+ # @see https://www.meilisearch.com/docs/reference/api/documents#update-documents-with-function Meilisearch API Documentation
250
463
  def update_documents_by_function(options)
251
464
  response = http_post "/indexes/#{@uid}/documents/edit", options
252
465
 
253
466
  Models::Task.new(response, task_endpoint)
254
467
  end
255
468
 
256
- # Public: Delete documents from an index
469
+ # Delete documents from an index.
257
470
  #
258
- # options: A Hash or an Array containing documents_ids or a hash with filter:.
471
+ # index.delete_documents([1, 2, 3, 4])
472
+ # index.delete_documents({ filter: "age > 10" })
473
+ #
474
+ # @param options [Array<[String, Integer]>, Hash{Symbol => String}] A Hash or an Array containing documents_ids or a hash with filter: key.
259
475
  # filter: - A hash containing a filter that should match documents.
260
476
  # Available ONLY with Meilisearch v1.2 and newer (optional)
261
477
  #
262
- # Returns a Task object.
478
+ # @return [Models::Task] An object representing the async deletion task.
263
479
  def delete_documents(options = {})
264
480
  Utils.version_error_handler(__method__) do
265
481
  response = if options.is_a?(Hash) && options.key?(:filter)
@@ -277,6 +493,14 @@ module Meilisearch
277
493
  end
278
494
  alias delete_multiple_documents delete_documents
279
495
 
496
+ # Synchronous version of {#delete_documents}.
497
+ #
498
+ # @deprecated
499
+ # use {Models::Task#await} on task returned from {#delete_documents}
500
+ #
501
+ # index.delete_documents(...).await
502
+ #
503
+ # Waits for the task to be achieved with a busy loop, be careful when using it.
280
504
  def delete_documents!(documents_ids)
281
505
  Utils.soft_deprecate(
282
506
  'Index#delete_documents!',
@@ -287,6 +511,13 @@ module Meilisearch
287
511
  end
288
512
  alias delete_multiple_documents! delete_documents!
289
513
 
514
+ # Delete a single document by id.
515
+ #
516
+ # index.delete_document(15)
517
+ #
518
+ # @param document_id [String, Integer] The ID of the document to delete.
519
+ #
520
+ # @return [Models::Task] An object representing the async deletion task.
290
521
  def delete_document(document_id)
291
522
  if document_id.nil? || document_id.to_s.empty?
292
523
  raise Meilisearch::InvalidDocumentId, 'document_id cannot be empty or nil'
@@ -299,6 +530,14 @@ module Meilisearch
299
530
  end
300
531
  alias delete_one_document delete_document
301
532
 
533
+ # Synchronous version of {#delete_document}.
534
+ #
535
+ # @deprecated
536
+ # use {Models::Task#await} on task returned from {#delete_document}
537
+ #
538
+ # index.delete_document(...).await
539
+ #
540
+ # Waits for the task to be achieved with a busy loop, be careful when using it.
302
541
  def delete_document!(document_id)
303
542
  Utils.soft_deprecate(
304
543
  'Index#delete_document!',
@@ -309,11 +548,24 @@ module Meilisearch
309
548
  end
310
549
  alias delete_one_document! delete_document!
311
550
 
551
+ # Delete all documents in the index.
552
+ #
553
+ # index.delete_all_documents
554
+ #
555
+ # @return [Models::Task] An object representing the async deletion task.
312
556
  def delete_all_documents
313
557
  response = http_delete "/indexes/#{@uid}/documents"
314
558
  Models::Task.new(response, task_endpoint)
315
559
  end
316
560
 
561
+ # Synchronous version of {#delete_all_documents}.
562
+ #
563
+ # @deprecated
564
+ # use {Models::Task#await} on task returned from {#delete_all_documents}
565
+ #
566
+ # index.delete_all_documents(...).await
567
+ #
568
+ # Waits for the task to be achieved with a busy loop, be careful when using it.
317
569
  def delete_all_documents!
318
570
  Utils.soft_deprecate(
319
571
  'Index#delete_all_documents!',
@@ -325,9 +577,15 @@ module Meilisearch
325
577
 
326
578
  ### SEARCH
327
579
 
328
- # options: A Hash
329
- # show_ranking_score - To see the ranking scores for returned documents
330
- # attributes_to_search_on - Customize attributes to search on at search time.
580
+ # Run a search on this index.
581
+ #
582
+ # Check Meilisearch API Reference for all options.
583
+ #
584
+ # @param query [String] The query string for the search.
585
+ # @param options [Hash{Symbol => Object}] Search options.
586
+ #
587
+ # @return [Hash{String => Object}] Search results
588
+ # @see https://www.meilisearch.com/docs/reference/api/search#search-in-an-index-with-post Meilisearch API Reference
331
589
  def search(query, options = {})
332
590
  attributes = { q: query.to_s }.merge(options.compact)
333
591
 
@@ -339,7 +597,16 @@ module Meilisearch
339
597
  response
340
598
  end
341
599
 
342
- # document_id: Identifier of the target document
600
+ # Run a search for semantically similar documents.
601
+ #
602
+ # An embedder must be configured and specified.
603
+ # Check Meilisearch API Reference for all options.
604
+ #
605
+ # @param document_id [String, Integer] The base document for comparisons.
606
+ # @param options [Hash{Symbol => Object}] Search options. Including a mandatory :embedder option.
607
+ #
608
+ # @return [Hash{String => Object}] Search results
609
+ # @see https://www.meilisearch.com/docs/reference/api/similar#get-similar-documents-with-post Meilisearch API Reference
343
610
  def search_similar_documents(document_id, **options)
344
611
  options.merge!(id: document_id)
345
612
  options = Utils.transform_attributes(options)
@@ -349,6 +616,26 @@ module Meilisearch
349
616
 
350
617
  ### FACET SEARCH
351
618
 
619
+ # Search for facet values.
620
+ #
621
+ # client.index('books').facet_search('genres', 'fiction', filter: 'rating > 3')
622
+ # # {
623
+ # # "facetHits": [
624
+ # # {
625
+ # # "value": "fiction",
626
+ # # "count": 7
627
+ # # }
628
+ # # ],
629
+ # # "facetQuery": "fiction",
630
+ # # "processingTimeMs": 0
631
+ # # }
632
+ #
633
+ # @param name [String] Facet name to search values on.
634
+ # @param query [String] Search query for a given facet value.
635
+ # @param options [Hash{Symbol => Object}] Additional options, see API Reference.
636
+ # @return [Hash{String => Object}] Facet search result.
637
+ #
638
+ # @see https://www.meilisearch.com/docs/reference/api/facet_search Meilisearch API Reference
352
639
  def facet_search(name, query = '', **options)
353
640
  options.merge!(facet_name: name, facet_query: query)
354
641
  options = Utils.transform_attributes(options)
@@ -363,49 +650,103 @@ module Meilisearch
363
650
  end
364
651
  private :task_endpoint
365
652
 
653
+ # Get a task belonging to this index, in Hash form.
654
+ #
655
+ # @see Task#index_task
366
656
  def task(task_uid)
367
657
  task_endpoint.index_task(task_uid)
368
658
  end
369
659
 
660
+ # Get all tasks belonging to this index, in Hash form.
661
+ #
662
+ # @see Task#index_tasks
370
663
  def tasks
371
664
  task_endpoint.index_tasks(@uid)
372
665
  end
373
666
 
667
+ # Wait for a given task to finish in a busy loop.
668
+ #
669
+ # @see Task#wait_for_task
374
670
  def wait_for_task(task_uid, timeout_in_ms = 5000, interval_in_ms = 50)
375
671
  task_endpoint.wait_for_task(task_uid, timeout_in_ms, interval_in_ms)
376
672
  end
377
673
 
378
674
  ### STATS
379
675
 
676
+ # Get stats of this index.
677
+ #
678
+ # @return [Hash{String => Object}]
679
+ # @see https://www.meilisearch.com/docs/reference/api/stats#get-stats-of-an-index Meilisearch API Reference
380
680
  def stats
381
681
  http_get "/indexes/#{@uid}/stats"
382
682
  end
383
683
 
684
+ # Get the number of documents in the index.
685
+ #
686
+ # Calls {#stats}
687
+ #
688
+ # @return [Integer]
384
689
  def number_of_documents
385
690
  stats['numberOfDocuments']
386
691
  end
387
692
 
693
+ # Whether the index is currently in the middle of indexing documents.
694
+ #
695
+ # Calls {#stats}
696
+ # @return [Boolean]
388
697
  def indexing?
389
698
  stats['isIndexing']
390
699
  end
391
700
 
701
+ ### COMPACT
702
+
703
+ # Run database compaction for this index.
704
+ #
705
+ # @note Meilisearch must temporarily duplicate the database during compaction. You need at least twice the current size of your database in free disk space.
706
+ #
707
+ # @see https://www.meilisearch.com/docs/reference/api/compact Meilisearch API Reference
708
+ # @return [Models::Task] The index compaction async task.
709
+ def compact
710
+ response = http_post "/indexes/#{@uid}/compact"
711
+ Models::Task.new(response, task_endpoint)
712
+ end
713
+
714
+ # Get the filed distribution of documents in the index.
715
+ #
716
+ # Calls {#stats}
392
717
  def field_distribution
393
718
  stats['fieldDistribution']
394
719
  end
395
720
 
396
721
  ### SETTINGS - GENERAL
397
722
 
723
+ # Get all index settings.
724
+ #
725
+ # @return [Hash{String => Object}] See the {settings object}[https://www.meilisearch.com/docs/reference/api/settings#settings-object].
726
+ # @see https://www.meilisearch.com/docs/reference/api/settings#all-settings Meilisearch API Reference
398
727
  def settings
399
728
  http_get "/indexes/#{@uid}/settings"
400
729
  end
401
730
  alias get_settings settings
402
731
 
732
+ # Update index settings.
733
+ #
734
+ # @param settings [Hash{Symbol => Object}] The new settings.
735
+ # Settings missing from this parameter are not affected.
736
+ # See {all settings}[https://www.meilisearch.com/docs/reference/api/settings#body].
737
+ #
738
+ # @return [Models::Task] The setting update async task.
739
+ # @see https://www.meilisearch.com/docs/reference/api/settings#update-settings Meilisearch API Reference
403
740
  def update_settings(settings)
404
741
  response = http_patch "/indexes/#{@uid}/settings", Utils.transform_attributes(settings)
405
742
  Models::Task.new(response, task_endpoint)
406
743
  end
407
744
  alias settings= update_settings
408
745
 
746
+ # Reset all index settings to defaults.
747
+ #
748
+ # @return [Models::Task] The setting update async task.
749
+ # @see https://www.meilisearch.com/docs/reference/api/settings#reset-settings Meilisearch API Reference
409
750
  def reset_settings
410
751
  response = http_delete "/indexes/#{@uid}/settings"
411
752
  Models::Task.new(response, task_endpoint)
@@ -413,17 +754,45 @@ module Meilisearch
413
754
 
414
755
  ### SETTINGS - RANKING RULES
415
756
 
757
+ # Get the index's ranking rules.
758
+ #
759
+ # Ranking rules are built-in rules that rank search results according to certain criteria.
760
+ # They are applied in the same order in which they appear in the rankingRules array.
761
+ #
762
+ # @return [Array<String>]
763
+ # @see https://www.meilisearch.com/docs/reference/api/settings#ranking-rules Meilisearch API Reference
416
764
  def ranking_rules
417
765
  http_get "/indexes/#{@uid}/settings/ranking-rules"
418
766
  end
419
767
  alias get_ranking_rules ranking_rules
420
768
 
769
+ # Update ranking rules.
770
+ #
771
+ # client.index('movies').update_ranking_rules([
772
+ # 'words',
773
+ # 'typo',
774
+ # 'proximity',
775
+ # 'attribute',
776
+ # 'sort',
777
+ # 'exactness',
778
+ # 'release_date:asc',
779
+ # 'rank:desc'
780
+ # ])
781
+ #
782
+ # See {#ranking_rules} for more details.
783
+ #
784
+ # @return [Models::Task] The async update task.
421
785
  def update_ranking_rules(ranking_rules)
422
786
  response = http_put "/indexes/#{@uid}/settings/ranking-rules", ranking_rules
423
787
  Models::Task.new(response, task_endpoint)
424
788
  end
425
789
  alias ranking_rules= update_ranking_rules
426
790
 
791
+ # Reset ranking rules to defaults.
792
+ #
793
+ # See {#ranking_rules} for more details.
794
+ #
795
+ # @return [Models::Task] The async update task that does the reset.
427
796
  def reset_ranking_rules
428
797
  response = http_delete "/indexes/#{@uid}/settings/ranking-rules"
429
798
  Models::Task.new(response, task_endpoint)
@@ -431,17 +800,33 @@ module Meilisearch
431
800
 
432
801
  ### SETTINGS - SYNONYMS
433
802
 
803
+ # Get the index's synonyms object.
804
+ #
805
+ # The synonyms object contains words and their respective synonyms.
806
+ # A synonym in Meilisearch is considered equal to its associated word for the purposes of calculating search results.
807
+ #
808
+ # @return [Hash{String => Array<String>}]
809
+ # @see https://www.meilisearch.com/docs/reference/api/settings#synonyms Meilisearch API Reference
434
810
  def synonyms
435
811
  http_get "/indexes/#{@uid}/settings/synonyms"
436
812
  end
437
813
  alias get_synonyms synonyms
438
814
 
815
+ # Set the synonyms setting.
816
+ #
817
+ # @param synonyms [Array<String>]
818
+ # @return [Models::Task] The async update task.
819
+ # @see #synonyms
439
820
  def update_synonyms(synonyms)
440
821
  response = http_put "/indexes/#{@uid}/settings/synonyms", synonyms
441
822
  Models::Task.new(response, task_endpoint)
442
823
  end
443
824
  alias synonyms= update_synonyms
444
825
 
826
+ # Reset synonyms setting to its default.
827
+ #
828
+ # @see #synonyms
829
+ # @return [Models::Task] The async update task that does the reset.
445
830
  def reset_synonyms
446
831
  response = http_delete "/indexes/#{@uid}/settings/synonyms"
447
832
  Models::Task.new(response, task_endpoint)
@@ -449,11 +834,22 @@ module Meilisearch
449
834
 
450
835
  ### SETTINGS - STOP-WORDS
451
836
 
837
+ # Get the index's stop-words list.
838
+ #
839
+ # Words added to the stopWords list are ignored in future search queries.
840
+ #
841
+ # @return [Array<String>]
842
+ # @see https://www.meilisearch.com/docs/reference/api/settings#stop-words Meilisearch API Reference
452
843
  def stop_words
453
844
  http_get "/indexes/#{@uid}/settings/stop-words"
454
845
  end
455
846
  alias get_stop_words stop_words
456
847
 
848
+ # Set the stop-words setting.
849
+ #
850
+ # @param stop_words [Array<String>]
851
+ # @return [Models::Task] The async update task.
852
+ # @see #stop_words
457
853
  def update_stop_words(stop_words)
458
854
  body = stop_words.nil? || stop_words.is_a?(Array) ? stop_words : [stop_words]
459
855
  response = http_put "/indexes/#{@uid}/settings/stop-words", body
@@ -461,6 +857,10 @@ module Meilisearch
461
857
  end
462
858
  alias stop_words= update_stop_words
463
859
 
860
+ # Reset stop-words setting to its default.
861
+ #
862
+ # @see #stop_words
863
+ # @return [Models::Task] The async update task that does the reset.
464
864
  def reset_stop_words
465
865
  response = http_delete "/indexes/#{@uid}/settings/stop-words"
466
866
  Models::Task.new(response, task_endpoint)
@@ -468,17 +868,32 @@ module Meilisearch
468
868
 
469
869
  ### SETTINGS - DISTINCT ATTRIBUTE
470
870
 
871
+ # Get the index's distinct attribute.
872
+ #
873
+ # The distinct attribute is a field whose value will always be unique in the returned documents.
874
+ #
875
+ # @return [String]
876
+ # @see https://www.meilisearch.com/docs/reference/api/settings#distinct-attribute Meilisearch API Reference
471
877
  def distinct_attribute
472
878
  http_get "/indexes/#{@uid}/settings/distinct-attribute"
473
879
  end
474
880
  alias get_distinct_attribute distinct_attribute
475
881
 
882
+ # Set the distinct-attribute setting.
883
+ #
884
+ # @param distinct_attribute [String]
885
+ # @return [Models::Task] The async update task.
886
+ # @see #distinct_attribute
476
887
  def update_distinct_attribute(distinct_attribute)
477
888
  response = http_put "/indexes/#{@uid}/settings/distinct-attribute", distinct_attribute
478
889
  Models::Task.new(response, task_endpoint)
479
890
  end
480
891
  alias distinct_attribute= update_distinct_attribute
481
892
 
893
+ # Reset distinct attribute setting to its default.
894
+ #
895
+ # @see #distinct_attribute
896
+ # @return [Models::Task] The async update task that does the reset.
482
897
  def reset_distinct_attribute
483
898
  response = http_delete "/indexes/#{@uid}/settings/distinct-attribute"
484
899
  Models::Task.new(response, task_endpoint)
@@ -486,17 +901,34 @@ module Meilisearch
486
901
 
487
902
  ### SETTINGS - SEARCHABLE ATTRIBUTES
488
903
 
904
+ # Get the index's searchable attributes.
905
+ #
906
+ # The values associated with attributes in the searchable_attributes list are searched for matching query words.
907
+ # The order of the list also determines the attribute ranking order.
908
+ # Defaults to +["*"]+.
909
+ #
910
+ # @return [Array<String>]
911
+ # @see https://www.meilisearch.com/docs/reference/api/settings#searchable-attributes Meilisearch API Reference
489
912
  def searchable_attributes
490
913
  http_get "/indexes/#{@uid}/settings/searchable-attributes"
491
914
  end
492
915
  alias get_searchable_attributes searchable_attributes
493
916
 
917
+ # Set the searchable attributes.
918
+ #
919
+ # @param distinct_attribute [Array<String>]
920
+ # @return [Models::Task] The async update task.
921
+ # @see #searchable_attributes
494
922
  def update_searchable_attributes(searchable_attributes)
495
923
  response = http_put "/indexes/#{@uid}/settings/searchable-attributes", searchable_attributes
496
924
  Models::Task.new(response, task_endpoint)
497
925
  end
498
926
  alias searchable_attributes= update_searchable_attributes
499
927
 
928
+ # Reset searchable attributes setting to its default.
929
+ #
930
+ # @see #searchable_attributes
931
+ # @return [Models::Task] The async update task that does the reset.
500
932
  def reset_searchable_attributes
501
933
  response = http_delete "/indexes/#{@uid}/settings/searchable-attributes"
502
934
  Models::Task.new(response, task_endpoint)
@@ -504,17 +936,33 @@ module Meilisearch
504
936
 
505
937
  ### SETTINGS - DISPLAYED ATTRIBUTES
506
938
 
939
+ # Get the index's displayed attributes.
940
+ #
941
+ # The attributes added to the displayedAttributes list appear in search results.
942
+ # Only affects the search endpoints.
943
+ #
944
+ # @return [Array<String>]
945
+ # @see https://www.meilisearch.com/docs/reference/api/settings#displayed-attributes Meilisearch API Reference
507
946
  def displayed_attributes
508
947
  http_get "/indexes/#{@uid}/settings/displayed-attributes"
509
948
  end
510
949
  alias get_displayed_attributes displayed_attributes
511
950
 
951
+ # Set the displayed attributes.
952
+ #
953
+ # @param displayed_attributes [Array<String>]
954
+ # @return [Models::Task] The async update task.
955
+ # @see #displayed_attributes
512
956
  def update_displayed_attributes(displayed_attributes)
513
957
  response = http_put "/indexes/#{@uid}/settings/displayed-attributes", displayed_attributes
514
958
  Models::Task.new(response, task_endpoint)
515
959
  end
516
960
  alias displayed_attributes= update_displayed_attributes
517
961
 
962
+ # Reset displayed attributes setting to its default.
963
+ #
964
+ # @see #displayed_attributes
965
+ # @return [Models::Task] The async update task that does the reset.
518
966
  def reset_displayed_attributes
519
967
  response = http_delete "/indexes/#{@uid}/settings/displayed-attributes"
520
968
  Models::Task.new(response, task_endpoint)
@@ -522,17 +970,32 @@ module Meilisearch
522
970
 
523
971
  ### SETTINGS - FILTERABLE ATTRIBUTES
524
972
 
973
+ # Get the index's filterable attributes.
974
+ #
975
+ # Attributes in the filterable_attributes list can be used as filters or facets.
976
+ #
977
+ # @return [Array<String>]
978
+ # @see https://www.meilisearch.com/docs/reference/api/settings#filterable-attributes Meilisearch API Reference
525
979
  def filterable_attributes
526
980
  http_get "/indexes/#{@uid}/settings/filterable-attributes"
527
981
  end
528
982
  alias get_filterable_attributes filterable_attributes
529
983
 
984
+ # Set the filterable attributes.
985
+ #
986
+ # @param filterable_attributes [Array<String>]
987
+ # @return [Models::Task] The async update task.
988
+ # @see #filterable_attributes
530
989
  def update_filterable_attributes(filterable_attributes)
531
990
  response = http_put "/indexes/#{@uid}/settings/filterable-attributes", filterable_attributes
532
991
  Models::Task.new(response, task_endpoint)
533
992
  end
534
993
  alias filterable_attributes= update_filterable_attributes
535
994
 
995
+ # Reset filterable attributes setting to its default.
996
+ #
997
+ # @see #filterable_attributes
998
+ # @return [Models::Task] The async update task that does the reset.
536
999
  def reset_filterable_attributes
537
1000
  response = http_delete "/indexes/#{@uid}/settings/filterable-attributes"
538
1001
  Models::Task.new(response, task_endpoint)
@@ -540,17 +1003,33 @@ module Meilisearch
540
1003
 
541
1004
  ### SETTINGS - SORTABLE ATTRIBUTES
542
1005
 
1006
+ # Get the index's sortable attributes.
1007
+ #
1008
+ # Attributes that can be used when sorting search results using the sort search parameter.
1009
+ #
1010
+ # @return [Array<String>]
1011
+ # @see https://www.meilisearch.com/docs/reference/api/settings#stop-words Meilisearch API Reference
1012
+ # @see https://www.meilisearch.com/docs/reference/api/search#sort +sort+ search parameter
543
1013
  def sortable_attributes
544
1014
  http_get "/indexes/#{@uid}/settings/sortable-attributes"
545
1015
  end
546
1016
  alias get_sortable_attributes sortable_attributes
547
1017
 
1018
+ # Set the sortable attributes.
1019
+ #
1020
+ # @param sortable_attributes [Array<String>]
1021
+ # @return [Models::Task] The async update task.
1022
+ # @see #sortable_attributes
548
1023
  def update_sortable_attributes(sortable_attributes)
549
1024
  response = http_put "/indexes/#{@uid}/settings/sortable-attributes", sortable_attributes
550
1025
  Models::Task.new(response, task_endpoint)
551
1026
  end
552
1027
  alias sortable_attributes= update_sortable_attributes
553
1028
 
1029
+ # Reset sortable attributes setting to its default.
1030
+ #
1031
+ # @see #sortable_attributes
1032
+ # @return [Models::Task] The async update task that does the reset.
554
1033
  def reset_sortable_attributes
555
1034
  response = http_delete "/indexes/#{@uid}/settings/sortable-attributes"
556
1035
  Models::Task.new(response, task_endpoint)
@@ -558,27 +1037,56 @@ module Meilisearch
558
1037
 
559
1038
  ### SETTINGS - PAGINATION
560
1039
 
1040
+ # Get the index's pagination options.
1041
+ #
1042
+ # To protect your database from malicious scraping, Meilisearch has a default limit of 1000 results per search.
1043
+ # This setting allows you to configure the maximum number of results returned per search.
1044
+ #
1045
+ # @return [Hash{String => Integer}]
1046
+ # @see https://www.meilisearch.com/docs/reference/api/settings#pagination Meilisearch API Reference
561
1047
  def pagination
562
1048
  http_get("/indexes/#{@uid}/settings/pagination")
563
1049
  end
564
1050
  alias get_pagination pagination
565
1051
 
1052
+ # Set the pagination options.
1053
+ #
1054
+ # @param sortable_attributes [Hash{String => Integer}]
1055
+ # @return [Models::Task] The async update task.
1056
+ # @see #pagination
566
1057
  def update_pagination(pagination)
567
1058
  response = http_patch "/indexes/#{@uid}/settings/pagination", pagination
568
1059
  Models::Task.new(response, task_endpoint)
569
1060
  end
570
1061
  alias pagination= update_sortable_attributes
571
1062
 
1063
+ # Reset pagination setting to its default.
1064
+ #
1065
+ # @see #pagination
1066
+ # @return [Models::Task] The async update task that does the reset.
572
1067
  def reset_pagination
573
1068
  response = http_delete "/indexes/#{@uid}/settings/pagination"
574
1069
  Models::Task.new(response, task_endpoint)
575
1070
  end
576
1071
 
1072
+ ### SETTINGS - TYPO TOLERANCE
1073
+
1074
+ # Get the index's typo tolerance setting.
1075
+ #
1076
+ # This setting allows you to configure the minimum word size for typos and disable typo tolerance for specific words or attributes.
1077
+ #
1078
+ # @return [Hash{String => Object}]
1079
+ # @see https://www.meilisearch.com/docs/reference/api/settings#typo-tolerance Meilisearch API Reference
577
1080
  def typo_tolerance
578
1081
  http_get("/indexes/#{@uid}/settings/typo-tolerance")
579
1082
  end
580
1083
  alias get_typo_tolerance typo_tolerance
581
1084
 
1085
+ # Set the typo tolerance setting.
1086
+ #
1087
+ # @param sortable_attributes [Hash{String => Object}]
1088
+ # @return [Models::Task] The async update task.
1089
+ # @see #typo_tolerance
582
1090
  def update_typo_tolerance(typo_tolerance_attributes)
583
1091
  attributes = Utils.transform_attributes(typo_tolerance_attributes)
584
1092
  response = http_patch("/indexes/#{@uid}/settings/typo-tolerance", attributes)
@@ -586,16 +1094,40 @@ module Meilisearch
586
1094
  end
587
1095
  alias typo_tolerance= update_typo_tolerance
588
1096
 
1097
+ # Reset typo tolerance setting to its default.
1098
+ #
1099
+ # @see #typo_tolerance
1100
+ # @return [Models::Task] The async update task that does the reset.
1101
+ # Reset typo tolerance setting to its default.
1102
+ #
1103
+ # @see #typo_tolerance
1104
+ # @return [Models::Task] The async update task that does the reset.
589
1105
  def reset_typo_tolerance
590
1106
  response = http_delete("/indexes/#{@uid}/settings/typo-tolerance")
591
1107
  Models::Task.new(response, task_endpoint)
592
1108
  end
593
1109
 
1110
+ ### SETTINGS - FACETING
1111
+
1112
+ # Get the index's faceting settings.
1113
+ #
1114
+ # With Meilisearch, you can create faceted search interfaces. This setting allows you to:
1115
+ # * Define the maximum number of values returned by the facets search parameter
1116
+ # * Sort facet values by value count or alphanumeric order
1117
+ #
1118
+ #
1119
+ # @return [Hash{String => Object}]
1120
+ # @see https://www.meilisearch.com/docs/reference/api/settings#faceting Meilisearch API Reference
594
1121
  def faceting
595
1122
  http_get("/indexes/#{@uid}/settings/faceting")
596
1123
  end
597
1124
  alias get_faceting faceting
598
1125
 
1126
+ # Set the faceting setting.
1127
+ #
1128
+ # @param faceting_attributes [Hash{String => Object}]
1129
+ # @return [Models::Task] The async update task.
1130
+ # @see #faceting
599
1131
  def update_faceting(faceting_attributes)
600
1132
  attributes = Utils.transform_attributes(faceting_attributes)
601
1133
  response = http_patch("/indexes/#{@uid}/settings/faceting", attributes)
@@ -603,6 +1135,10 @@ module Meilisearch
603
1135
  end
604
1136
  alias faceting= update_faceting
605
1137
 
1138
+ # Reset faceting setting to its default.
1139
+ #
1140
+ # @see #faceting
1141
+ # @return [Models::Task] The async update task that does the reset.
606
1142
  def reset_faceting
607
1143
  response = http_delete("/indexes/#{@uid}/settings/faceting")
608
1144
  Models::Task.new(response, task_endpoint)
@@ -610,32 +1146,64 @@ module Meilisearch
610
1146
 
611
1147
  ### SETTINGS - DICTIONARY
612
1148
 
1149
+ # Get the index's dictionary.
1150
+ #
1151
+ # Allows users to instruct Meilisearch to consider groups of strings as a single term by adding a supplementary dictionary of user-defined terms.
1152
+ #
1153
+ # @return [Array<String>]
1154
+ # @see https://www.meilisearch.com/docs/reference/api/settings#dictionary Meilisearch API Reference
613
1155
  def dictionary
614
1156
  http_get("/indexes/#{@uid}/settings/dictionary")
615
1157
  end
616
1158
 
1159
+ # Set the custom dictionary.
1160
+ #
1161
+ # @param dictionary_attributes [Array<String>]
1162
+ # @return [Models::Task] The async update task.
1163
+ # @see #dictionary
617
1164
  def update_dictionary(dictionary_attributes)
618
1165
  attributes = Utils.transform_attributes(dictionary_attributes)
619
1166
  response = http_put("/indexes/#{@uid}/settings/dictionary", attributes)
620
1167
  Models::Task.new(response, task_endpoint)
621
1168
  end
622
1169
 
1170
+ # Reset dictionary setting to its default.
1171
+ #
1172
+ # @see #dictionary
1173
+ # @return [Models::Task] The async update task that does the reset.
623
1174
  def reset_dictionary
624
1175
  response = http_delete("/indexes/#{@uid}/settings/dictionary")
625
1176
  Models::Task.new(response, task_endpoint)
626
1177
  end
627
1178
  ### SETTINGS - SEPARATOR TOKENS
628
1179
 
1180
+ # Get the index's separator-tokens list.
1181
+ #
1182
+ # Strings in the separator-tokens list indicate where a word ends and begins.
1183
+ #
1184
+ # @return [Array<String>]
1185
+ # @see #non_separator_tokens
1186
+ # @see https://www.meilisearch.com/docs/learn/engine/datatypes#string List of built-in separator tokens
1187
+ # @see https://www.meilisearch.com/docs/reference/api/settings#separator-tokens Meilisearch API Reference
629
1188
  def separator_tokens
630
1189
  http_get("/indexes/#{@uid}/settings/separator-tokens")
631
1190
  end
632
1191
 
1192
+ # Set the custom separator tokens.
1193
+ #
1194
+ # @param separator_tokens_attributes [Array<String>]
1195
+ # @return [Models::Task] The async update task.
1196
+ # @see #separator_tokens
633
1197
  def update_separator_tokens(separator_tokens_attributes)
634
1198
  attributes = Utils.transform_attributes(separator_tokens_attributes)
635
1199
  response = http_put("/indexes/#{@uid}/settings/separator-tokens", attributes)
636
1200
  Models::Task.new(response, task_endpoint)
637
1201
  end
638
1202
 
1203
+ # Reset separator tokens setting to its default.
1204
+ #
1205
+ # @see #separator_tokens
1206
+ # @return [Models::Task] The async update task that does the reset.
639
1207
  def reset_separator_tokens
640
1208
  response = http_delete("/indexes/#{@uid}/settings/separator-tokens")
641
1209
  Models::Task.new(response, task_endpoint)
@@ -643,16 +1211,32 @@ module Meilisearch
643
1211
 
644
1212
  ### SETTINGS - NON SEPARATOR TOKENS
645
1213
 
1214
+ # Get the index's non-separator-token list.
1215
+ #
1216
+ # Remove words from Meilisearch's default list of separator tokens.
1217
+ #
1218
+ # @return [Array<String>]
1219
+ # @see https://www.meilisearch.com/docs/learn/engine/datatypes#string List of built-in separator tokens
1220
+ # @see https://www.meilisearch.com/docs/reference/api/settings#non-separator-tokens Meilisearch API Reference
646
1221
  def non_separator_tokens
647
1222
  http_get("/indexes/#{@uid}/settings/non-separator-tokens")
648
1223
  end
649
1224
 
1225
+ # Set the custom non separator tokens.
1226
+ #
1227
+ # @param non_separator_tokens_attributes [Array<String>]
1228
+ # @return [Models::Task] The async update task.
1229
+ # @see #non_separator_tokens
650
1230
  def update_non_separator_tokens(non_separator_tokens_attributes)
651
1231
  attributes = Utils.transform_attributes(non_separator_tokens_attributes)
652
1232
  response = http_put("/indexes/#{@uid}/settings/non-separator-tokens", attributes)
653
1233
  Models::Task.new(response, task_endpoint)
654
1234
  end
655
1235
 
1236
+ # Reset non separator tokens setting to its default.
1237
+ #
1238
+ # @see #non_separator_tokens
1239
+ # @return [Models::Task] The async update task that does the reset.
656
1240
  def reset_non_separator_tokens
657
1241
  response = http_delete("/indexes/#{@uid}/settings/non-separator-tokens")
658
1242
  Models::Task.new(response, task_endpoint)
@@ -660,16 +1244,31 @@ module Meilisearch
660
1244
 
661
1245
  ### SETTINGS - PROXIMITY PRECISION
662
1246
 
1247
+ # Get the index's proximity-precision setting.
1248
+ #
1249
+ # Choose the precision of the distance calculation.
1250
+ #
1251
+ # @return ["byWord", "byAttribute"]
1252
+ # @see https://www.meilisearch.com/docs/reference/api/settings#proximity-precision Meilisearch API Reference
663
1253
  def proximity_precision
664
1254
  http_get("/indexes/#{@uid}/settings/proximity-precision")
665
1255
  end
666
1256
 
1257
+ # Set the proximity precision.
1258
+ #
1259
+ # @param proximity_precision_attribute ["byWord", "byAttribute"]
1260
+ # @return [Models::Task] The async update task.
1261
+ # @see #proximity_precision
667
1262
  def update_proximity_precision(proximity_precision_attribute)
668
1263
  response = http_put("/indexes/#{@uid}/settings/proximity-precision", proximity_precision_attribute)
669
1264
 
670
1265
  Models::Task.new(response, task_endpoint)
671
1266
  end
672
1267
 
1268
+ # Reset proximity precision setting to its default.
1269
+ #
1270
+ # @see #proximity_precision
1271
+ # @return [Models::Task] The async update task that does the reset.
673
1272
  def reset_proximity_precision
674
1273
  response = http_delete("/indexes/#{@uid}/settings/proximity-precision")
675
1274
 
@@ -678,16 +1277,31 @@ module Meilisearch
678
1277
 
679
1278
  ### SETTINGS - SEARCH CUTOFF MS
680
1279
 
1280
+ # Get the index's maximum duration for a search query, in milliseconds.
1281
+ #
1282
+ # Defaults to 1500ms.
1283
+ #
1284
+ # @return [Integer]
1285
+ # @see https://www.meilisearch.com/docs/reference/api/settings#search-cuttoff Meilisearch API Reference
681
1286
  def search_cutoff_ms
682
1287
  http_get("/indexes/#{@uid}/settings/search-cutoff-ms")
683
1288
  end
684
1289
 
1290
+ # Set the search timeout value (in milliseconds).
1291
+ #
1292
+ # @param search_cutoff_ms_attribute [Integer]
1293
+ # @return [Models::Task] The async update task.
1294
+ # @see #search_cutoff_ms
685
1295
  def update_search_cutoff_ms(search_cutoff_ms_attribute)
686
1296
  response = http_put("/indexes/#{@uid}/settings/search-cutoff-ms", search_cutoff_ms_attribute)
687
1297
 
688
1298
  Models::Task.new(response, task_endpoint)
689
1299
  end
690
1300
 
1301
+ # Reset search cutoff ms setting to its default.
1302
+ #
1303
+ # @see #search_cutoff_ms
1304
+ # @return [Models::Task] The async update task that does the reset.
691
1305
  def reset_search_cutoff_ms
692
1306
  response = http_delete("/indexes/#{@uid}/settings/search-cutoff-ms")
693
1307
 
@@ -696,10 +1310,22 @@ module Meilisearch
696
1310
 
697
1311
  ### SETTINGS - LOCALIZED ATTRIBUTES
698
1312
 
1313
+ # Get the index's localized-attributes.
1314
+ #
1315
+ # By default, Meilisearch auto-detects the languages used in your documents.
1316
+ # This setting allows you to explicitly define which languages are present in a dataset, and in which fields.
1317
+ #
1318
+ # @return [Hash{String => Array<String>}]
1319
+ # @see https://www.meilisearch.com/docs/reference/api/settings#localized-attributes Meilisearch API Reference
699
1320
  def localized_attributes
700
1321
  http_get("/indexes/#{@uid}/settings/localized-attributes")
701
1322
  end
702
1323
 
1324
+ # Set the search timeout value (in milliseconds).
1325
+ #
1326
+ # @param search_cutoff_ms_attribute [Integer]
1327
+ # @return [Models::Task] The async update task.
1328
+ # @see #search_cutoff_ms
703
1329
  def update_localized_attributes(new_localized_attributes)
704
1330
  new_localized_attributes = Utils.transform_attributes(new_localized_attributes)
705
1331
 
@@ -708,6 +1334,10 @@ module Meilisearch
708
1334
  Models::Task.new(response, task_endpoint)
709
1335
  end
710
1336
 
1337
+ # Reset localized attributes setting to its default.
1338
+ #
1339
+ # @see #localized_attributes
1340
+ # @return [Models::Task] The async update task that does the reset.
711
1341
  def reset_localized_attributes
712
1342
  response = http_delete("/indexes/#{@uid}/settings/localized-attributes")
713
1343
 
@@ -716,16 +1346,32 @@ module Meilisearch
716
1346
 
717
1347
  ### SETTINGS - FACET SEARCH
718
1348
 
1349
+ # Get the index's facet-search setting.
1350
+ #
1351
+ # Processing filterable attributes for facet search is a resource-intensive operation.
1352
+ # This feature is enabled by default, but disabling it may speed up indexing.
1353
+ #
1354
+ # @return [Boolean]
1355
+ # @see https://www.meilisearch.com/docs/reference/api/settings#facet-search Meilisearch API Reference
719
1356
  def facet_search_setting
720
1357
  http_get("/indexes/#{@uid}/settings/facet-search")
721
1358
  end
722
1359
 
1360
+ # Set the facet search setting.
1361
+ #
1362
+ # @param new_facet_search_setting [Boolean]
1363
+ # @return [Models::Task] The async update task.
1364
+ # @see #facet_search_setting
723
1365
  def update_facet_search_setting(new_facet_search_setting)
724
1366
  response = http_put("/indexes/#{@uid}/settings/facet-search", new_facet_search_setting)
725
1367
 
726
1368
  Models::Task.new(response, task_endpoint)
727
1369
  end
728
1370
 
1371
+ # Reset facet search setting setting to its default.
1372
+ #
1373
+ # @see #facet_search_setting
1374
+ # @return [Models::Task] The async update task that does the reset.
729
1375
  def reset_facet_search_setting
730
1376
  response = http_delete("/indexes/#{@uid}/settings/facet-search")
731
1377
 
@@ -734,16 +1380,32 @@ module Meilisearch
734
1380
 
735
1381
  ### SETTINGS - PREFIX SEARCH
736
1382
 
1383
+ # Get the index's prefix-search setting.
1384
+ #
1385
+ # Prefix search is the process through which Meilisearch matches documents that begin with a specific query term, instead of only exact matches.
1386
+ # This is a resource-intensive operation that happens during indexing by default.
1387
+ #
1388
+ # @return ["indexingTime", "disabled"]
1389
+ # @see https://www.meilisearch.com/docs/reference/api/settings#prefix-search Meilisearch API Reference
737
1390
  def prefix_search
738
1391
  http_get("/indexes/#{@uid}/settings/prefix-search")
739
1392
  end
740
1393
 
1394
+ # Set the prefix search switch.
1395
+ #
1396
+ # @param new_prefix_search_setting ["indexingTime", "disabled"]
1397
+ # @return [Models::Task] The async update task.
1398
+ # @see #prefix_search
741
1399
  def update_prefix_search(new_prefix_search_setting)
742
1400
  response = http_put("/indexes/#{@uid}/settings/prefix-search", new_prefix_search_setting)
743
1401
 
744
1402
  Models::Task.new(response, task_endpoint)
745
1403
  end
746
1404
 
1405
+ # Reset prefix search setting to its default.
1406
+ #
1407
+ # @see #prefix_search
1408
+ # @return [Models::Task] The async update task that does the reset.
747
1409
  def reset_prefix_search
748
1410
  response = http_delete("/indexes/#{@uid}/settings/prefix-search")
749
1411
 
@@ -752,10 +1414,22 @@ module Meilisearch
752
1414
 
753
1415
  ### SETTINGS - EMBEDDERS
754
1416
 
1417
+ # Get the index's embedders setting.
1418
+ #
1419
+ # Embedders translate documents and queries into vector embeddings.
1420
+ # You must configure at least one embedder to use AI-powered search.
1421
+ #
1422
+ # @return [Hash{String => Hash{String => String}}]
1423
+ # @see https://www.meilisearch.com/docs/reference/api/settings#embedders Meilisearch API Reference
755
1424
  def embedders
756
1425
  http_get("/indexes/#{@uid}/settings/embedders")
757
1426
  end
758
1427
 
1428
+ # Set the embedders on the index.
1429
+ #
1430
+ # @param new_embedders [Hash{String => Hash{String => String}}]
1431
+ # @return [Models::Task] The async update task.
1432
+ # @see #embedders
759
1433
  def update_embedders(new_embedders)
760
1434
  new_embedders = Utils.transform_attributes(new_embedders)
761
1435
 
@@ -764,6 +1438,10 @@ module Meilisearch
764
1438
  Models::Task.new(response, task_endpoint)
765
1439
  end
766
1440
 
1441
+ # Reset embedders setting to its default.
1442
+ #
1443
+ # @see #embedders
1444
+ # @return [Models::Task] The async update task that does the reset.
767
1445
  def reset_embedders
768
1446
  response = http_delete("/indexes/#{@uid}/settings/embedders")
769
1447