diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 8c05c952..165607ba 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -515,3 +515,5 @@ distinct_attribute_guide_distinct_parameter_1: |- client.index('products').search('white shirt', { distinct: 'sku' }) +get_task_documents_1: |- + client.task_documents(1) diff --git a/lib/meilisearch/client.rb b/lib/meilisearch/client.rb index 72da699b..094b2781 100644 --- a/lib/meilisearch/client.rb +++ b/lib/meilisearch/client.rb @@ -430,6 +430,16 @@ def task(task_uid) task_endpoint.task(task_uid) end + # Get task's document payload + # + # Retrieve the document payload that was sent with this task. Only available for document-related tasks that are enqueued or processing. + # + # @param task_uid [String] uid of the requested task + # @return [String] The content of the task update + def task_documents(task_uid) + task_endpoint.task_documents(task_uid) + end + # Wait for a task in a busy loop. # # Try to avoid using it. Wrapper around {Task#wait_for_task}. diff --git a/lib/meilisearch/task.rb b/lib/meilisearch/task.rb index b9ec9892..3d6c3bc0 100644 --- a/lib/meilisearch/task.rb +++ b/lib/meilisearch/task.rb @@ -19,13 +19,14 @@ def task_list(options = {}) def task(task_uid) http_get "/tasks/#{task_uid}" end + alias index_task task - def index_tasks(index_uid) - http_get '/tasks', { indexUids: [index_uid].flatten.join(',') } + def task_documents(task_uid) + http_get "/tasks/#{task_uid}/documents" end - def index_task(task_uid) - http_get "/tasks/#{task_uid}" + def index_tasks(index_uid) + http_get '/tasks', { indexUids: [index_uid].flatten.join(',') } end def cancel_tasks(options) diff --git a/spec/meilisearch/client/tasks_spec.rb b/spec/meilisearch/client/tasks_spec.rb index a7153809..0a516325 100644 --- a/spec/meilisearch/client/tasks_spec.rb +++ b/spec/meilisearch/client/tasks_spec.rb @@ -91,6 +91,20 @@ ) end + it 'gets all the documents from a task' do + client.update_experimental_features(getTaskDocumentsRoute: true) + + document_to_insert = { objectId: 123, title: 'Pride and Prejudice', comment: 'A great book' } + + task = index.add_documents(document_to_insert) + documents = client.task_documents(task.metadata['uid']) + + expect(documents).to be_a(String) + expect(documents).to eq('{"objectId":123,"title":"Pride and Prejudice","comment":"A great book"}') + + client.update_experimental_features(getTaskDocumentsRoute: false) + end + describe '#index.wait_for_task' do it 'waits for task with default values' do task = index.add_documents(documents)