Skip to content

Commit

Permalink
Merge branch 'main' into bump-meilisearch-v1.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
curquiza authored Dec 23, 2024
2 parents 0dc026a + 9106f5d commit ff6dd19
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Metrics/BlockLength:
# Offense count: 4
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 441
Max: 442

# Offense count: 1
# Configuration parameters: Max, CountKeywordArgs.
Expand Down
12 changes: 12 additions & 0 deletions lib/meilisearch/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ def update_documents_in_batches!(documents, batch_size = 1000, primary_key = nil
update_documents_in_batches(documents, batch_size, primary_key).each(&:await)
end

# Update documents by function
#
# options - A Hash containing the function string and related options
# context:
# filter:
# function:
def update_documents_by_function(options)
response = http_post "/indexes/#{@uid}/documents/edit", options

Models::Task.new(response, task_endpoint)
end

# Public: Delete documents from an index
#
# options: A Hash or an Array containing documents_ids or a hash with filter:.
Expand Down
24 changes: 24 additions & 0 deletions spec/meilisearch/index/documents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,30 @@
end
end

describe '#update_documents_by_function' do
before do
index.add_documents(documents).await
index.update_filterable_attributes(['objectId']).await
end

it 'updates documents by function' do
enable_edit_documents_by_function(true)
expect(index.document(1344)).to include('title' => 'The Hobbit')
expect(index.document(456)).to include('title' => 'Le Petit Prince')

index.update_documents_by_function(
{
filter: 'objectId = 1344',
context: { extra: 'extended' },
function: 'doc.title = `${doc.title.to_upper()} - ${context.extra}`'
}
).await

expect(index.document(1344)).to include('title' => 'THE HOBBIT - extended')
expect(index.document(456)).to include('title' => 'Le Petit Prince')
end
end

describe '#delete_document' do
before { index.add_documents(documents).await }

Expand Down
4 changes: 4 additions & 0 deletions spec/support/experimental_feature_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def enable_vector_store(toggle)
configure_feature('vectorStore', toggle)
end

def enable_edit_documents_by_function(toggle)
configure_feature('editDocumentsByFunction', toggle)
end

private

# @param [String] attribute_to_toggle
Expand Down

0 comments on commit ff6dd19

Please sign in to comment.