Skip to content

Allow users to customize facet value sort behaviour #676

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

Merged
merged 15 commits into from
Jul 10, 2025
Merged

Conversation

Mubelotix
Copy link
Collaborator

@Mubelotix Mubelotix commented Jul 10, 2025

Pull Request

Rework of #514

Related issue

Fixes #502

What does this PR do?

  • Introduce FacetSortValue enum
  • Add FacetSortSetting to FacetSetting

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 support for customizing the sorting order of facet values, allowing users to specify sorting by alphabetical order or count for each facet.
    • Enhanced settings options to let users define the maximum number of values per facet and sorting preferences directly.
  • Documentation
    • Updated and expanded code samples to illustrate the new facet value sorting options in faceting settings.

Copy link

coderabbitai bot commented Jul 10, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes add support for configuring how facet values are sorted—either alphanumerically or by count—via a new FacetSortValue enum and a sort_facet_values_by field in FacetingSettings. Builder methods and tests are updated accordingly, and code samples are revised and expanded to demonstrate the new functionality.

Changes

File(s) Change Summary
src/settings.rs Added FacetSortValue enum; extended FacetingSettings with sort_facet_values_by; updated builder methods and tests for new sorting options.
.code-samples.meilisearch.yaml Updated and added code samples to demonstrate sort_facet_values_by usage in faceting settings.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SDK
    participant Settings
    participant FacetingSettings

    User->>SDK: Call updateFaceting with sortFacetValuesBy
    SDK->>Settings: with_sort_facet_values_by(BTreeMap)
    Settings->>FacetingSettings: Update sort_facet_values_by field
    FacetingSettings-->>Settings: Return updated settings
    Settings-->>SDK: Return configured settings
    SDK-->>User: Operation complete
Loading

Assessment against linked issues

Objective Addressed Explanation
Add ability to receive a new param in updateFaceting called sortFacetValuesBy (#502)
Update code samples for facet_search_2, getting_started_faceting, update_faceting_settings_1 (#502)
Add integration tests for new faceting sorting functionality (#502)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Poem

A rabbit hopped through fields of code,
Sorting facets, lightened its load.
Alpha or count, you now can choose,
With builder methods you can't lose!
Docs and tests all spruced anew—
This bunny's proud of what you do.
🐇✨


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Mubelotix
Copy link
Collaborator Author

@coderabbitai review

Copy link

coderabbitai bot commented Jul 10, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 1

🧹 Nitpick comments (3)
src/settings.rs (1)

45-47: Clarify the documentation comment for better accuracy.

The comment could be more precise about what is being sorted.

-    /// Customize facet order to sort by descending value count (count) or ascending alphanumeric order (alpha)
+    /// Customize how facet values are sorted: by descending count or ascending alphanumeric order
.code-samples.meilisearch.yaml (2)

585-591: Add the BTreeMap import for copy-paste compilability.

This snippet introduces BTreeMap but omits the corresponding use std::collections::BTreeMap;. Readers who paste the example verbatim will hit a compiler error.

+use std::collections::BTreeMap;

1273-1278: Same missing import as above.

For consistency and to avoid compilation errors, prepend the snippet with

+use std::collections::BTreeMap;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6eb41e8 and 369b6b0.

📒 Files selected for processing (2)
  • .code-samples.meilisearch.yaml (4 hunks)
  • src/settings.rs (5 hunks)
🧰 Additional context used
🧠 Learnings (2)
.code-samples.meilisearch.yaml (1)
Learnt from: LukasKalbertodt
PR: meilisearch/meilisearch-rust#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`.
src/settings.rs (1)
Learnt from: LukasKalbertodt
PR: meilisearch/meilisearch-rust#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`.
⏰ 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 (5)
src/settings.rs (4)

33-38: LGTM! Clean enum definition for facet sorting options.

The FacetSortValue enum is well-structured with appropriate derive macros and clear variant names that match the intended functionality.


2351-2478: Comprehensive test coverage for the new facet sorting functionality.

The tests properly cover:

  • Setting faceting with default sort behavior
  • Explicit sort value configuration
  • The API's behavior of returning default sort settings
  • Various builder method combinations

Well done on the thorough testing!


1432-1435: Example correctly updated to include the new field.

The example appropriately demonstrates the new sort_facet_values_by field.


292-297: Breaking change confirmed: with_faceting now takes ownership

No references to with_faceting were found in documentation (Markdown) outside of the implementation in src/settings.rs. The existing example in src/settings.rs already uses req_faceting.clone(), so no updates are required elsewhere.

.code-samples.meilisearch.yaml (1)

5-5: Reference line – nothing to change.

The added provenance comment is fine and needs no further action.

@Mubelotix Mubelotix merged commit 6de4acf into dev Jul 10, 2025
7 checks passed
@Mubelotix Mubelotix deleted the faceting2 branch July 10, 2025 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants