-
Notifications
You must be signed in to change notification settings - Fork 103
feat: add custom metadata support for document tasks #736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe PR adds custom metadata support to document operations across the Meilisearch SDK, aligning with v1.26 API capabilities. Document operation methods now accept an optional Changes
Sequence DiagramsequenceDiagram
participant App
participant Index
participant DocumentTaskQuery
participant HTTP
participant TaskInfo
App->>Index: add_documents(docs, pk, Some("batch-1"))
Index->>DocumentTaskQuery: new(pk, Some("batch-1"))
Index->>HTTP: POST /documents with DocumentTaskQuery payload
HTTP->>TaskInfo: response with customMetadata
TaskInfo->>App: TaskInfo { custom_metadata: Some("batch-1"), ... }
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Areas requiring attention:
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/tasks.rs (1)
154-175: Exposecustom_metadataon task variants in a backward-compatible wayAdding
pub custom_metadata: Option<String>toSucceededTask,EnqueuedTask, andProcessingTaskunder#[serde(rename_all = "camelCase")]correctly maps the server’scustomMetadatafield and remains backward-compatible for deserialization (field is optional and existing JSON still matches via..patterns in tests). Consider adding a brief doc comment on this field to make its relation to Meilisearch’s “tasks custom metadata” feature explicit for SDK users.Also applies to: 183-196, 204-219
src/documents.rs (1)
415-427: DocumentDeletionQuery metadata extension looks correct and keeps API stable
executedelegating toexecute_with_custom_metadatawithNonepreserves the old API while adding the new capability. Lifetimes oncustom_metadata: Option<&'a str>are consistent with the struct’s lifetime, and the call intoIndex::delete_documents_withmatches the new signature.One minor nit: the generic
T: DeserializeOwned + 'staticon both methods is now unused; if you ever do a breaking release, consider simplifying these to non‑generic fns or adding aPhantomData<T>to avoid the unused type parameter warning. For now, this is harmless and keeps source compatibility.src/indexes.rs (1)
592-666: Write/update document routes correctly propagatecustom_metadataFor
add_or_replace,add_documents,add_or_update, and their*_unchecked_payload/ NDJSON / CSV variants, the extracustom_metadata: Option<&str>is consistently threaded into aDocumentTaskQuery::new(primary_key, custom_metadata)used as the request’s query payload. This keeps existing primary key behavior intact while adding metadata support on all the expected code paths, including streaming ones.Given the repeated pattern (build URL, construct
DocumentTaskQuery, then callrequestorstream_request), you might later consider a small private helper to reduce duplication, but it’s not necessary for clarity or correctness right now.Also applies to: 706-739, 779-846, 884-940, 942-1013, 1055-1078
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
examples/cli-app-with-awc/src/main.rs(1 hunks)examples/cli-app/src/main.rs(1 hunks)examples/web_app_graphql/src/graphql_schema/users/query/search.rs(2 hunks)src/client.rs(6 hunks)src/documents.rs(5 hunks)src/indexes.rs(51 hunks)src/lib.rs(2 hunks)src/search.rs(3 hunks)src/task_info.rs(5 hunks)src/tasks.rs(5 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-12T13:28:23.700Z
Learnt from: LukasKalbertodt
Repo: meilisearch/meilisearch-rust PR: 625
File: src/search.rs:368-370
Timestamp: 2025-06-12T13:28:23.700Z
Learning: In the Meilisearch Rust client, `SearchQuery` serializes its per-query federation settings under the key `federationOptions`; only the top-level multi-search parameter is named `federation`.
Applied to files:
src/client.rs
🧬 Code graph analysis (7)
src/tasks.rs (1)
src/client.rs (2)
None(1532-1532)None(1613-1613)
src/task_info.rs (1)
src/client.rs (2)
None(1532-1532)None(1613-1613)
examples/cli-app-with-awc/src/main.rs (1)
src/client.rs (2)
None(1532-1532)None(1613-1613)
src/search.rs (1)
src/client.rs (2)
None(1532-1532)None(1613-1613)
examples/cli-app/src/main.rs (1)
src/client.rs (2)
None(1532-1532)None(1613-1613)
src/client.rs (2)
src/reqwest.rs (1)
qualified_version(131-135)src/batches.rs (3)
None(141-141)None(169-169)None(193-193)
src/indexes.rs (2)
src/documents.rs (7)
new(89-94)new(218-228)new(400-405)index(62-64)index(161-161)index(383-383)index(544-544)src/request.rs (1)
query(39-47)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: integration-tests
🔇 Additional comments (16)
examples/cli-app-with-awc/src/main.rs (1)
186-194: Example call correctly updated for newadd_or_updatesignatureAdding the trailing
Nonekeeps this example in sync with the newadd_or_updateAPI while preserving existing behavior (no custom metadata sent).src/lib.rs (2)
29-38: Top-level “Add Documents” doctest matches extendedadd_documentsAPIThe extra
Noneparameter correctly accounts for the new optional metadata argument without changing the example’s behavior.
182-190: Filterable attributes doctest updated consistently for metadata argumentThis doctest’s
add_documentscall now matches the three-argument signature and keeps the example behavior intact by passingNonemetadata.examples/web_app_graphql/src/graphql_schema/users/query/search.rs (1)
24-38: GraphQL example updated correctly foradd_documentsmetadata parameterBoth
add_documentscalls now include the new optional metadata argument asNone, keeping control flow and behavior identical while aligning with the updated API.examples/cli-app/src/main.rs (1)
110-118: CLI example synchronized with newadd_or_updatesignatureThe additional
Noneargument for metadata is correct and keeps this example compiling and behaving as before.src/tasks.rs (1)
290-299: Docs and tests now use three-argumentadd_documentsconsistentlyThe Task docs example and all affected tests now call
add_documentswith(…, primary_key_opt, None)which matches the extended API and keeps the existing semantics (no metadata) while exercising the new parameter.Also applies to: 935-961, 1225-1238, 1258-1289
src/task_info.rs (1)
9-18:TaskInfonow surfacescustom_metadatawith solid deserialization coverageExposing
pub custom_metadata: Option<String>onTaskInfo(camelCase serde) matches the server field, and the updatedtest_deserialize_task_infoverifies correct mapping from"customMetadata". The updatedadd_documents(&[..], None, None)usage in the async test keeps behavior unchanged while aligning with the new API.Also applies to: 114-141, 145-176
src/search.rs (1)
972-985: Search examples/tests correctly updated for metadata-aware document APIsThe facet-search documentation now calls
add_or_replacewith the extra metadata argument asNone, and bothsetup_test_indexhelpers use the three-argumentadd_documentssignature. All of these keep test and example behavior intact while matching the new API.Also applies to: 1225-1238, 1258-1289
src/client.rs (2)
167-191: Client documentation kept in sync with extended document/task APIsThe multi-search,
wait_for_task, andget_taskexamples now useadd_or_replace,add_documents, anddelete_all_documentswith their updated signatures (extra metadata or options argument), consistently passingNonewhere no metadata is desired. This maintains example behavior while matching the new public API surface.Also applies to: 889-919, 956-968
1548-1549: Tests correctly importqualified_versionand use newadd_documentssignatureBringing
reqwest::qualified_versioninto scope matches its use intest_methods_has_qualified_version_as_header, and the twoadd_documentscalls intest_swapping_two_indexesnow include the trailingNonemetadata argument, keeping the test logic unchanged but compatible with the updated API.Also applies to: 1560-1580
src/documents.rs (1)
144-144: Updated call sites for extracustom_metadataparameter are consistentThe additional
Nonearguments wired intoadd_or_replacein the doctest,setup_test_index, and the twodelete_documents_withtest calls align with the new API and keep existing behavior (no metadata) unchanged.Also applies to: 488-488, 540-541, 569-570
src/indexes.rs (5)
80-103:DocumentTaskQuerydesign matches Meilisearch query conventionsThe internal
DocumentTaskQuery<'a>cleanly encapsulatesprimary_keyandcustom_metadatawith#[serde(rename_all = "camelCase")]andskip_serializing_if = "Option::is_none", which should serialize to the expectedprimaryKey/customMetadataquery parameters only when present. Using separate constructors (newandwith_metadata) keeps call sites clear between routes that also set a primary key and those that only tag tasks.No issues from a correctness perspective.
1080-1131: Delete document APIs now support per-task metadata without changing semantics
delete_all_documents,delete_document,delete_documents, anddelete_documents_withnow all acceptcustom_metadata: Option<&str>and wrap it viaDocumentTaskQuery::with_metadata(custom_metadata)passed as the query component of the HTTP method. Bodies (when present) remain unchanged, so server-side behavior for filters and ID lists is preserved; only the optional metadata is new.The use of
Method::<_, ()>::Delete { query }for DELETE routes is type-correct with the genericMethod<Q, B>definition, and lifetimes on the borrowed&strmetadata are no stricter than existing borrowed query structs elsewhere in this module.Also applies to: 1133-1185, 1187-1242, 1285-1302
1673-1687: Batch helpers correctly fan outcustom_metadataper produced task
add_documents_in_batchesandupdate_documents_in_batchesnow acceptcustom_metadata: Option<&str>and forward it unchanged into each inneradd_documents/add_or_updatecall. This matches the doc comments that every task produced by the batch is tagged with the same metadata.Capacity reservation is still based on the document count (existing behavior); no new performance or correctness concerns introduced here.
Also applies to: 1770-1785
2232-2242: Helper and CSV/NDJSON tests give solid coverage of metadata propagationThe
expect_task_metadatahelper centralizes the assertion onTask::Succeeded { content }.custom_metadata, making the new tests concise and less error-prone.The
test_add_documents_ndjson,test_update_documents_ndjson,test_add_documents_csv, andtest_update_documents_csvtests validate that:
TaskInfo.custom_metadatareflects the provided metadata, and- The final
Taskretrieved viawait_for_completionpreserves the same metadata.This is exactly what we need to guard the new behavior on the streaming code paths.
Also applies to: 2413-2514
2579-2692:test_document_tasks_custom_metadatathoroughly exercises all main document task variantsThis test is a nice end-to-end check that
custom_metadataflows correctly through:
add_documentsdelete_documentadd_or_updatedelete_documentsdelete_documents_with(viaDocumentDeletionQuery)delete_all_documentsAsserting both
TaskInfo.custom_metadataand theTask’scontent.custom_metadataviaexpect_task_metadatagives good confidence that the SDK is correctly wiring the metadata end-to-end for the primary document operations.
Pull Request
Related issue
Fixes #733
What does this PR do?
PR checklist
Please check if your PR fulfills the following requirements:
Thank you so much for contributing to Meilisearch!
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.