Skip to content

Commit ff6dd19

Browse files
authored
Merge branch 'main' into bump-meilisearch-v1.12.0
2 parents 0dc026a + 9106f5d commit ff6dd19

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

.rubocop_todo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Metrics/BlockLength:
1515
# Offense count: 4
1616
# Configuration parameters: CountComments, CountAsOne.
1717
Metrics/ClassLength:
18-
Max: 441
18+
Max: 442
1919

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

lib/meilisearch/index.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ def update_documents_in_batches!(documents, batch_size = 1000, primary_key = nil
185185
update_documents_in_batches(documents, batch_size, primary_key).each(&:await)
186186
end
187187

188+
# Update documents by function
189+
#
190+
# options - A Hash containing the function string and related options
191+
# context:
192+
# filter:
193+
# function:
194+
def update_documents_by_function(options)
195+
response = http_post "/indexes/#{@uid}/documents/edit", options
196+
197+
Models::Task.new(response, task_endpoint)
198+
end
199+
188200
# Public: Delete documents from an index
189201
#
190202
# options: A Hash or an Array containing documents_ids or a hash with filter:.

spec/meilisearch/index/documents_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,30 @@
390390
end
391391
end
392392

393+
describe '#update_documents_by_function' do
394+
before do
395+
index.add_documents(documents).await
396+
index.update_filterable_attributes(['objectId']).await
397+
end
398+
399+
it 'updates documents by function' do
400+
enable_edit_documents_by_function(true)
401+
expect(index.document(1344)).to include('title' => 'The Hobbit')
402+
expect(index.document(456)).to include('title' => 'Le Petit Prince')
403+
404+
index.update_documents_by_function(
405+
{
406+
filter: 'objectId = 1344',
407+
context: { extra: 'extended' },
408+
function: 'doc.title = `${doc.title.to_upper()} - ${context.extra}`'
409+
}
410+
).await
411+
412+
expect(index.document(1344)).to include('title' => 'THE HOBBIT - extended')
413+
expect(index.document(456)).to include('title' => 'Le Petit Prince')
414+
end
415+
end
416+
393417
describe '#delete_document' do
394418
before { index.add_documents(documents).await }
395419

spec/support/experimental_feature_helpers.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ def enable_vector_store(toggle)
88
configure_feature('vectorStore', toggle)
99
end
1010

11+
def enable_edit_documents_by_function(toggle)
12+
configure_feature('editDocumentsByFunction', toggle)
13+
end
14+
1115
private
1216

1317
# @param [String] attribute_to_toggle

0 commit comments

Comments
 (0)