Skip to content

feat: add /fields route#756

Open
aznszn wants to merge 3 commits into
meilisearch:mainfrom
aznszn:main
Open

feat: add /fields route#756
aznszn wants to merge 3 commits into
meilisearch:mainfrom
aznszn:main

Conversation

@aznszn
Copy link
Copy Markdown
Contributor

@aznszn aznszn commented Jan 28, 2026

Pull Request

Related issue

Closes #755

What does this PR do?

  • Added the /fields route
  • Created a new top-level module fields
  • Added new methods get_fields and get_fields_with to Index
  • Added FieldsQuery struct to represent a /fields query
  • Added FieldsQueryFilter struct to represent the filter key in the body of a /fields request
  • Added FieldInfo struct to represent the response of a /fields request

I was not sure if a top-level module should be dedicated to this or should I put it inside the indexes module. I went with a top level module and copied the pattern used in IndexQuery.

PR checklist

Please check if your PR fulfills the following requirements:

  • Did you use any AI tool while implementing this PR (code, tests, docs, etc.)? If yes, disclose it in the PR description and describe what it was used for. AI usage is allowed when it is disclosed.

I did not use AI

  • 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?

Summary by CodeRabbit

  • New Features

    • Field querying for index metadata: pagination (offset, limit) and rich filters (attribute patterns, displayed, searchable, sortable, distinct, ranking rule, filterable).
    • Public API to retrieve field metadata.
  • Tests

    • Added tests for field retrieval, filtered queries, and pagination.
  • Documentation

    • Added module-level documentation linking related field query guidance.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 28, 2026

📝 Walkthrough

Walkthrough

Adds a new public fields module with types and builders to query index field metadata (FieldResult, FieldsResult, FieldsQuery, FieldsQueryFilter), exposes Index::get_fields and Index::get_fields_with, and includes async tests; pub mod fields; added to src/lib.rs. Duplicate method/test insertions present in src/indexes.rs.

Changes

Cohort / File(s) Summary
Field querying module
src/fields.rs
New module implementing FieldResult, FieldsResult, FieldsQuery<'a, Http> (new, with_offset, with_limit, with_filter, execute), and FieldsQueryFilter builder (with_attribute_patterns, with_displayed, with_searchable, with_sortable, with_distinct, with_ranking_rule, with_filterable), plus serde support, docs/examples, and unit tests.
Index API extensions
src/indexes.rs
Adds get_fields(&self) -> Result<FieldsResult, Error> and get_fields_with(&self, body: &FieldsQuery<'_, Http>) -> Result<FieldsResult, Error> and imports from crate::fields; includes async tests. Note: the same methods and tests are inserted twice in the same impl block (duplicate entries).
Module exposure
src/lib.rs
Adds pub mod fields; with documentation link to upstream PR; placed between features and indexes.

Sequence Diagram

sequenceDiagram
    participant User as User
    participant FQ as FieldsQuery
    participant IDX as Index
    participant HTTP as HttpClient
    participant MS as MeiliSearch

    User->>FQ: new(index) / with_* builders
    User->>FQ: execute()
    FQ->>IDX: get_fields_with(self)
    IDX->>HTTP: send request GET /indexes/{uid}/fields (params/body)
    HTTP->>MS: HTTP request
    MS->>HTTP: JSON response (fields metadata)
    HTTP->>IDX: parsed FieldsResult
    IDX->>FQ: return FieldsResult
    FQ->>User: Result<FieldsResult>
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

enhancement

Poem

🐇 I hop through indexes where field-info grows,
Builders on my back, with filters in rows.
Offset and limits, I bound and I play,
Returning the names that brighten the day. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Changes include code duplication in src/indexes.rs where get_fields and get_fields_with methods plus tests are inserted twice in the same impl block, which appears unintentional and out-of-scope. Remove the duplicate get_fields, get_fields_with methods and test_get_fields_with test from src/indexes.rs to eliminate code duplication within the same impl block.
✅ 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 'feat: add /fields route' accurately and clearly summarizes the primary change of implementing the /fields API endpoint in the Rust SDK.
Linked Issues check ✅ Passed The PR implements all coding requirements from issue #755: adds FieldsQuery/FieldsQueryFilter types, Index::get_fields/get_fields_with methods, FieldResult/FieldsResult types, and filter support.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

🤖 Fix all issues with AI agents
In `@src/fields.rs`:
- Around line 49-71: The FieldsQuery struct currently serializes filter: None as
"filter": null; update the filter field in struct FieldsQuery<'a, Http:
HttpClient> to add #[serde(skip_serializing_if = "Option::is_none")] so it is
omitted when None (matching offset and limit), and update its doc comment to
read "All fields returned must match **all** of the filter criteria" and format
FieldsQueryFilter with backticks (`FieldsQueryFilter`) in the docstring.
🧹 Nitpick comments (1)
src/fields.rs (1)

244-249: Typo in parameter name (distint).
Consider renaming to distinct to keep rustdoc output clean.

✏️ Suggested tweak
-    pub fn with_distinct(mut self, distint: bool) -> Self {
-        self.distinct = Some(distint);
+    pub fn with_distinct(mut self, distinct: bool) -> Self {
+        self.distinct = Some(distinct);

Comment thread src/fields.rs
@aznszn
Copy link
Copy Markdown
Contributor Author

aznszn commented Jan 28, 2026

Hey @curquiza, let me know if you can review this PR and if not let me know who to ping

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.

Add the /fields/ api

1 participant