Skip to content

fix(types): allow interface{} for FacetSearchRequest Filter (fixes #752)#753

Merged
ElyarSadig merged 5 commits into
meilisearch:mainfrom
kyyril:fix/issue-752-facet-search-filter-type
Feb 4, 2026
Merged

fix(types): allow interface{} for FacetSearchRequest Filter (fixes #752)#753
ElyarSadig merged 5 commits into
meilisearch:mainfrom
kyyril:fix/issue-752-facet-search-filter-type

Conversation

@kyyril
Copy link
Copy Markdown
Contributor

@kyyril kyyril commented Feb 3, 2026

Summary

This PR fixes #752.

Problem: FacetSearchRequest.Filter was defined as string, preventing users from directly passing array/slice filters (e.g. []string{"cat", "dog"}), which are supported by Meilisearch API for AND/OR logic.

Solution: Changed FacetSearchRequest.Filter type to interface{} to match SearchRequest.Filter, allowing both string and slice inputs.


Technical Details

Attribute Value
Language Go
Affected Files types.go, types_facet_search_test.go
Type Bug Fix / Enhancement

Changes Made

  • Changed Filter field in FacetSearchRequest struct from string to interface{}.
  • Added types_facet_search_test.go to verify correct marshaling of both string and slice filters.

Verification

go test -v -race -run "FacetSearchRequest" .

Test Results

  • ✅ Test passes for slice input ([]string).
  • ✅ Test passes for string input (string).
  • ✅ All existing unit tests pass.

Quality Checklist

  • I have read the CONTRIBUTING.md file
  • I have followed the project's code style
  • I have added/updated tests for my changes
  • All new and existing tests pass locally

Summary by CodeRabbit

  • New Features

    • Added ability to request performance details in search and similar document queries via a new flag; performance metrics are now returned in responses when requested.
    • Enhanced filter support to accept more flexible input formats, enabling complex filtering logic.
  • Tests

    • Added comprehensive test coverage for performance details serialization and new filter format handling.

Adds support for Meilisearch v1.35.0 showPerformanceDetails option:
- Add ShowPerformanceDetails field to SearchRequest struct
- Add ShowPerformanceDetails field to SimilarDocumentQuery struct
- Add PerformanceDetails field to SearchResponse as json.RawMessage
- Add unit tests for JSON marshaling/unmarshaling

The performanceDetails response field is returned as raw JSON data
as specified in the issue requirements, since the object fields
are subject to change in future Meilisearch versions.

Fixes meilisearch#749
Fixes meilisearch#752

Change Filter type in FacetSearchRequest from string to interface{} to allow passing slice of strings for complex filter queries, consistent with SearchRequest.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

This PR adds support for array-based filters in FacetSearchRequest by changing the Filter field type from string to interface{}, aligning with SearchRequest. Additionally, it introduces optional performance metrics tracking via new ShowPerformanceDetails fields in SearchRequest and SimilarDocumentQuery, and a corresponding PerformanceDetails field in SearchResponse.

Changes

Cohort / File(s) Summary
Type Definitions
types.go
Changed FacetSearchRequest.Filter from string to interface{} to support both string and array filters. Added ShowPerformanceDetails bool to SearchRequest and SimilarDocumentQuery. Added PerformanceDetails json.RawMessage to SearchResponse.
Performance Details Tests
types_performance_details_test.go
New test file with comprehensive unit tests for JSON serialization/deserialization of ShowPerformanceDetails in SearchRequest and SimilarDocumentQuery, and deserialization of PerformanceDetails in SearchResponse, including field omission and ordering validation.
Integration Tests
integration/index_search_test.go
Added TestIndexFacetSearchWithFilterArray to validate facet search functionality with array-based filters, ensuring correct facet results when using Filter as a string array.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

enhancement

Suggested reviewers

  • curquiza
  • ja7ad

Poem

🐰 A filter now dances as array or string,
Performance details make metrics to sing,
The tests multiply, coverage runs deep,
Type safety awakes from its sleep!

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Changes to SearchRequest and SimilarDocumentQuery with ShowPerformanceDetails appear to be out of scope relative to the stated objective of fixing FacetSearchRequest.Filter type. Remove the ShowPerformanceDetails additions to SearchRequest, SearchResponse, and SimilarDocumentQuery, as these are not mentioned in issue #752 and constitute unrelated enhancements.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and specifically describes the main change: allowing interface{} for FacetSearchRequest Filter and references the issue it fixes.
Linked Issues check ✅ Passed All coding objectives from issue #752 are met: FacetSearchRequest.Filter changed from string to interface{}, supporting both string and array inputs with correct JSON marshaling and test coverage.

✏️ 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.

@ja7ad ja7ad requested a review from ElyarSadig February 3, 2026 17:48
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 11.32%. Comparing base (32f492b) to head (ff45c46).
⚠️ Report is 13 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (32f492b) and HEAD (ff45c46). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (32f492b) HEAD (ff45c46)
4 2
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #753       +/-   ##
===========================================
- Coverage   88.53%   11.32%   -77.21%     
===========================================
  Files          22       40       +18     
  Lines        3262    25498    +22236     
===========================================
  Hits         2888     2888               
- Misses        216    22452    +22236     
  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
Copy link
Copy Markdown
Collaborator

@kyyril
Thank you for opening the issue. Please remove the existing unit tests and replace them with integration tests. Include cases that use []string typed inputs to validate behavior.

…quest Filter

- Remove types_facet_search_test.go
- Add integration test case for []string filter in TestIndex_FacetSearch
Comment thread issue_body.md Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@kyyril
Please remove this file.

Comment thread types_performance_details_test.go Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@kyyril
These unit tests do not add value to our coverage please remove them.

Copy link
Copy Markdown
Collaborator

@ElyarSadig ElyarSadig left a comment

Choose a reason for hiding this comment

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

Please apply the changes reuquested.

@kyyril kyyril requested a review from ElyarSadig February 4, 2026 11:33
@ElyarSadig ElyarSadig added this pull request to the merge queue Feb 4, 2026
Merged via the queue into meilisearch:main with commit d2256a8 Feb 4, 2026
5 of 6 checks passed
@ja7ad ja7ad added enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FacetSearchRequest Filter should support array (interface{})

3 participants