Skip to content

Conversation

@ElyarSadig
Copy link
Collaborator

@ElyarSadig ElyarSadig commented Dec 31, 2025

Pull Request

Related issue

Fixes #738

What does this PR do?

  • Add SkipCreation parameter to adding/replacing documents.
  • Add units tests for the new SkipCreation parameter.
  • Add new integration test cases for SkipCreation.
  • Update code samples.

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

Summary by CodeRabbit

  • New Features
    • Added SkipCreation option to document operations, enabling users to enqueue document additions and updates without immediately creating documents in the index.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 31, 2025

📝 Walkthrough

Walkthrough

This PR adds support for the skipCreation parameter introduced in Meilisearch v1.31, enabling document operations to skip index creation. A new SkipCreation boolean field is added to DocumentOptions and CsvDocumentsQuery types. Helper functions serialize this field, and tests validate the new functionality across document addition and update operations.

Changes

Cohort / File(s) Summary
Type Definitions
types.go
Added SkipCreation boolean field to DocumentOptions and CsvDocumentsQuery structs with skipCreation JSON tags.
Helper Functions
helper.go
Updated transformDocumentOptionsToMap and transformCsvDocumentsQueryToMap to serialize the SkipCreation field when set.
Helper Tests
helper_test.go
Added test cases for SkipCreation field serialization in both transform functions, covering true/false states and integration with existing fields.
Code Samples
.code-samples.meilisearch.yaml
Updated examples to instantiate DocumentOptions with SkipCreation instead of passing nil to AddDocuments and UpdateDocuments.
Integration Tests
integration/index_document_test.go
Added test cases TestIndexAddDocumentsWithSkipCreation and TestIndexBasicAddDocumentsCsvWithSkipCreation, updated existing tests to propagate options and validate empty results when skipping creation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • ja7ad
  • curquiza

Poem

🐰 A hop, a skip, and documents too,
No creation needed—just what's new!
With options in hand and tests so true,
Meilisearch v1.31 shines through! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main feature being added: support for the skipCreation parameter in document operations.
Linked Issues check ✅ Passed The PR successfully implements all coding objectives from issue #738: adds skipCreation parameter to document methods, includes comprehensive test coverage, and updates code samples.
Out of Scope Changes check ✅ Passed All changes directly relate to implementing the skipCreation parameter feature as specified in issue #738; no unrelated modifications detected.
✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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 (4)
.code-samples.meilisearch.yaml (1)

70-71: Consider omitting the explicit false value for SkipCreation.

Setting SkipCreation: false is redundant since false is the zero value for booleans in Go. For code samples demonstrating best practices, consider either:

  • Passing nil when using default behavior, or
  • Omitting the SkipCreation field entirely from the struct
📝 Suggested alternatives

Option 1: Pass nil for default behavior

-  options := &meilisearch.DocumentOptions{SkipCreation: false}
-  client.Index("movies").AddDocuments(documents, options)
+  client.Index("movies").AddDocuments(documents, nil)

Option 2: Omit the field

-  options := &meilisearch.DocumentOptions{SkipCreation: false}
+  options := &meilisearch.DocumentOptions{}
   client.Index("movies").AddDocuments(documents, options)
types.go (2)

680-681: Add documentation for the SkipCreation field.

The SkipCreation field lacks a comment explaining its purpose. Adding documentation would help users understand when and why to use this option.

📝 Suggested documentation
 type DocumentOptions struct {
 	PrimaryKey   *string `json:"primaryKey,omitempty"`
+	// SkipCreation when set to true, prevents creating the index if it doesn't exist.
+	// Documents will only be added/updated if the index already exists.
 	SkipCreation bool    `json:"skipCreation,omitempty"`
 	// TaskCustomMetadata is the custom metadata to add to the task.

691-691: Add documentation for the SkipCreation field.

The SkipCreation field lacks a comment explaining its purpose. Adding documentation would help users understand when and why to use this option.

📝 Suggested documentation
 type CsvDocumentsQuery struct {
 	PrimaryKey   string `json:"primaryKey,omitempty"`
 	CsvDelimiter string `json:"csvDelimiter,omitempty"`
+	// SkipCreation when set to true, prevents creating the index if it doesn't exist.
+	// Documents will only be added/updated if the index already exists.
 	SkipCreation bool   `json:"skipCreation,omitempty"`
 	// TaskCustomMetadata is the custom metadata to add to the task.
integration/index_document_test.go (1)

1114-1117: Consider adding a nil check for defensive coding.

While currently safe (all test cases provide non-nil options), accessing tt.args.options.SkipCreation directly could cause a nil pointer dereference if a future test case passes nil options.

📝 Suggested defensive check
-		var wantDocs []map[string]interface{}
-		if !tt.args.options.SkipCreation {
-			wantDocs = testParseCsvDocuments(t, bytes.NewReader(tt.args.documents))
-		}
+		var wantDocs []map[string]interface{}
+		if tt.args.options == nil || !tt.args.options.SkipCreation {
+			wantDocs = testParseCsvDocuments(t, bytes.NewReader(tt.args.documents))
+		}
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce6536d and 6a26a9b.

📒 Files selected for processing (5)
  • .code-samples.meilisearch.yaml
  • helper.go
  • helper_test.go
  • integration/index_document_test.go
  • types.go
🧰 Additional context used
🧬 Code graph analysis (1)
helper_test.go (1)
types.go (2)
  • DocumentOptions (679-686)
  • CsvDocumentsQuery (688-696)
⏰ 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). (2)
  • GitHub Check: integration-tests (go current version)
  • GitHub Check: integration-tests (go latest version)
🔇 Additional comments (7)
helper.go (2)

116-119: LGTM! Correct handling of SkipCreation for CSV queries.

The implementation correctly serializes the SkipCreation field only when true, avoiding unnecessary skipCreation=false in query parameters. This follows the established pattern for optional boolean flags.


186-189: LGTM! Correct handling of SkipCreation for document options.

The implementation correctly serializes the SkipCreation field only when true, which is the appropriate behavior for query parameters.

.code-samples.meilisearch.yaml (1)

80-81: LGTM! Good demonstration of SkipCreation usage.

The code sample clearly demonstrates how to use SkipCreation: true with document updates.

helper_test.go (2)

194-221: LGTM! Comprehensive test coverage for DocumentOptions.SkipCreation.

The test cases properly cover:

  • SkipCreation: true adds the field to the output map
  • SkipCreation: false results in an empty map (field omitted)
  • Integration with PrimaryKey and TaskCustomMetadata fields

275-305: LGTM! Comprehensive test coverage for CsvDocumentsQuery.SkipCreation.

The test cases properly cover:

  • SkipCreation: true adds the field to the output map
  • SkipCreation: false results in an empty map (field omitted)
  • Integration with other CSV-specific fields
integration/index_document_test.go (2)

408-434: LGTM! Good test coverage for SkipCreation functionality.

The test properly verifies that when SkipCreation: true is set, no documents are returned (empty results), which aligns with the expected behavior when the index doesn't exist or documents should not be created.


1078-1093: LGTM! Good test coverage for CSV with SkipCreation.

The test case appropriately covers the SkipCreation flag for CSV document operations.

@codecov
Copy link

codecov bot commented Dec 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.53%. Comparing base (ce6536d) to head (6a26a9b).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #739      +/-   ##
==========================================
+ Coverage   88.52%   88.53%   +0.01%     
==========================================
  Files          22       22              
  Lines        3258     3262       +4     
==========================================
+ Hits         2884     2888       +4     
  Misses        216      216              
  Partials      158      158              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ElyarSadig ElyarSadig requested a review from ja7ad December 31, 2025 18:14
@ja7ad ja7ad added the enhancement New feature or request label Dec 31, 2025
@ja7ad ja7ad added this pull request to the merge queue Dec 31, 2025
Merged via the queue into meilisearch:main with commit d4c5cfd Dec 31, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Meilisearch v1.31] Allow skipCreation when adding/replacing documents

2 participants