Skip to content

Conversation

@awais786
Copy link
Contributor

@awais786 awais786 commented Nov 11, 2025

#1135

feat: Add support for sorting on the documents API.

Summary by CodeRabbit

  • Bug Fixes

    • Accept comma-separated sort strings and automatically convert them to multi-field sort lists so sorting works reliably with either format.
  • Tests

    • Added end-to-end tests validating multi-field sorting (mixed ascending/descending) and that both list and comma-separated sort formats produce correct results.
  • Documentation

    • Updated example payloads to illustrate both list and comma-separated sort formats.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 11, 2025

Walkthrough

get_documents now accepts a string sort and normalizes it at runtime into a list (splitting on commas and trimming) before issuing the HTTP request; documentation and code samples updated. Two tests were added to verify multi-field sorting and that list vs comma-separated string formats yield identical ordering.

Changes

Cohort / File(s) Summary
Sort parameter normalization
meilisearch/index.py
Docstring updated to state sort is a list. Added runtime normalization: if parameters["sort"] is a string, split on commas and trim whitespace to produce a list before sending the HTTP request.
Sort tests (fields & formats)
tests/index/test_index_document_meilisearch.py
Added test_get_documents_sort_fields to verify multi-field sorting (["rating:desc","release_date:asc"]) and test_get_documents_sort_formats (parameterized) to assert identical ordering when sort is passed as a list or as a comma-separated string.
Code samples / examples
.code-samples.meilisearch.yaml
Added/modified examples for get_documents payloads to include sort in both list and comma-separated string formats.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant get_documents
    participant HTTP
    participant Meilisearch

    Client->>get_documents: call get_documents(uid, parameters)
    rect rgb(245,250,255)
      get_documents->>get_documents: if parameters["sort"] is string\nsplit on ',' and trim -> list
    end
    get_documents->>HTTP: send request with normalized parameters
    HTTP->>Meilisearch: HTTP request
    Meilisearch-->>HTTP: documents response
    HTTP-->>get_documents: response
    get_documents-->>Client: return documents
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify trimming and handling of empty segments when splitting sort.
  • Confirm docstring, examples, and tests accurately reflect runtime behavior and waiting for update completion in tests.

Poem

🐇 I split the commas, tidy and neat,
Ratings fall, dates step to beat,
Fields line up in ordered fun,
Documents leap—sorting done,
Hooray, the sorted harvest's complete.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding support for sorting on the documents API, which matches the implementation across index.py, tests, and code samples.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 28b9fd1 and 979ac38.

📒 Files selected for processing (1)
  • .code-samples.meilisearch.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .code-samples.meilisearch.yaml

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.

@awais786 awais786 marked this pull request as ready for review November 11, 2025 18:52
Copy link
Contributor

@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: 2

🧹 Nitpick comments (1)
meilisearch/index.py (1)

406-406: Improve the docstring phrasing.

The phrase "A list of attributes written as an array or as a comma-separated string" is somewhat awkward. Consider rephrasing for clarity.

Apply this diff:

-            - sort:  A list of attributes written as an array or as a comma-separated string
+            - sort: List of sort attributes. Can be provided as a list or comma-separated string (e.g., ["rating:desc", "date:asc"] or "rating:desc, date:asc")
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a54e3c2 and 9fc5fde.

📒 Files selected for processing (2)
  • meilisearch/index.py (2 hunks)
  • tests/index/test_index_document_meilisearch.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/index/test_index_document_meilisearch.py (2)
tests/conftest.py (1)
  • index_with_documents (121-128)
meilisearch/index.py (4)
  • update_sortable_attributes (1510-1531)
  • wait_for_task (233-260)
  • add_documents (451-483)
  • get_documents (387-425)
meilisearch/index.py (1)
meilisearch/_httprequests.py (1)
  • get (95-96)
🪛 GitHub Actions: Tests
tests/index/test_index_document_meilisearch.py

[error] Black formatting check failed: 1 file would be reformatted. Run 'pipenv run black' to format the code.

🔇 Additional comments (1)
meilisearch/index.py (1)

415-419: LGTM! Clean string-to-list conversion.

The implementation correctly handles comma-separated sort strings, properly strips whitespace, and filters empty values. The type check ensures lists are passed through unchanged.

@awais786 awais786 closed this Nov 11, 2025
@awais786 awais786 reopened this Nov 11, 2025
Copy link
Contributor

@Strift Strift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution 🙌

@Strift Strift added the enhancement New feature or request label Nov 17, 2025
@Strift Strift linked an issue Nov 17, 2025 that may be closed by this pull request
2 tasks
@Strift Strift added this pull request to the merge queue Nov 17, 2025
Merged via the queue into meilisearch:main with commit fd4fff6 Nov 17, 2025
11 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.

[v1.16.0] Add support for sorting on the documents API

3 participants