-
Notifications
You must be signed in to change notification settings - Fork 114
fix(types): allow interface{} for FacetSearchRequest Filter (fixes #752) #753
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
ElyarSadig
merged 5 commits into
meilisearch:main
from
kyyril:fix/issue-752-facet-search-filter-type
Feb 4, 2026
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ebfef38
Add showPerformanceDetails option to search endpoints
kyyril 67c492f
fix(types): allow interface{} for FacetSearchRequest Filter
kyyril 41907d8
Merge branch 'main' into fix/issue-752-facet-search-filter-type
kyyril e54fe62
refactor: replace unit tests with integration tests for FacetSearchRe…
kyyril ff45c46
refactor: replace unit tests with integration tests for FacetSearchRe…
kyyril File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| ## Problem | ||
| Currently, the `FacetSearchRequest` struct defines the `Filter` field as a `string`. | ||
|
|
||
| ```go | ||
| type FacetSearchRequest struct { | ||
| // ... | ||
| Filter string `json:"filter,omitempty"` | ||
| } | ||
| ``` | ||
|
|
||
| However, the Meilisearch API documentation (and behavior) allows `filter` to be either a **string** or an **array of strings** (allowing for complex AND/OR logic). | ||
|
|
||
| The `SearchRequest` struct already correctly handles this by using `interface{}`: | ||
| ```go | ||
| type SearchRequest struct { | ||
| // ... | ||
| Filter interface{} `json:"filter,omitempty"` | ||
| } | ||
| ``` | ||
|
|
||
| ## Solution | ||
| Change `FacetSearchRequest.Filter` type from `string` to `interface{}` to match `SearchRequest` and support slice input. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kyyril |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| package meilisearch | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestSearchRequest_ShowPerformanceDetails(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| request SearchRequest | ||
| expected string | ||
| }{ | ||
| { | ||
| name: "ShowPerformanceDetails is true", | ||
| request: SearchRequest{ | ||
| Query: "test", | ||
| ShowPerformanceDetails: true, | ||
| }, | ||
| expected: `{"showPerformanceDetails":true,"q":"test","hybrid":null}`, | ||
| }, | ||
| { | ||
| name: "ShowPerformanceDetails is false (omitted)", | ||
| request: SearchRequest{ | ||
| Query: "test", | ||
| }, | ||
| expected: `{"q":"test","hybrid":null}`, | ||
| }, | ||
| { | ||
| name: "ShowPerformanceDetails with other show options", | ||
| request: SearchRequest{ | ||
| Query: "test", | ||
| ShowPerformanceDetails: true, | ||
| ShowRankingScore: true, | ||
| ShowRankingScoreDetails: true, | ||
| }, | ||
| expected: `{"showRankingScore":true,"showRankingScoreDetails":true,"showPerformanceDetails":true,"q":"test","hybrid":null}`, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| data, err := json.Marshal(tt.request) | ||
| require.NoError(t, err) | ||
| require.JSONEq(t, tt.expected, string(data)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestSearchResponse_PerformanceDetails(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| jsonResponse string | ||
| expectedHasKey bool | ||
| }{ | ||
| { | ||
| name: "Response with performanceDetails", | ||
| jsonResponse: `{ | ||
| "hits": [], | ||
| "processingTimeMs": 10, | ||
| "query": "test", | ||
| "performanceDetails": {"step1": {"time": 5}, "step2": {"time": 3}} | ||
| }`, | ||
| expectedHasKey: true, | ||
| }, | ||
| { | ||
| name: "Response without performanceDetails", | ||
| jsonResponse: `{ | ||
| "hits": [], | ||
| "processingTimeMs": 10, | ||
| "query": "test" | ||
| }`, | ||
| expectedHasKey: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| var resp SearchResponse | ||
| err := json.Unmarshal([]byte(tt.jsonResponse), &resp) | ||
| require.NoError(t, err) | ||
|
|
||
| if tt.expectedHasKey { | ||
| require.NotNil(t, resp.PerformanceDetails) | ||
| require.NotEmpty(t, resp.PerformanceDetails) | ||
| } else { | ||
| require.Nil(t, resp.PerformanceDetails) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestSimilarDocumentQuery_ShowPerformanceDetails(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| query SimilarDocumentQuery | ||
| expected string | ||
| }{ | ||
| { | ||
| name: "ShowPerformanceDetails is true", | ||
| query: SimilarDocumentQuery{ | ||
| Id: "1", | ||
| Embedder: "default", | ||
| ShowPerformanceDetails: true, | ||
| }, | ||
| expected: `{"id":"1","embedder":"default","showPerformanceDetails":true}`, | ||
| }, | ||
| { | ||
| name: "ShowPerformanceDetails is false (omitted)", | ||
| query: SimilarDocumentQuery{ | ||
| Id: "1", | ||
| Embedder: "default", | ||
| }, | ||
| expected: `{"id":"1","embedder":"default"}`, | ||
| }, | ||
| { | ||
| name: "ShowPerformanceDetails with other show options", | ||
| query: SimilarDocumentQuery{ | ||
| Id: "1", | ||
| Embedder: "default", | ||
| ShowPerformanceDetails: true, | ||
| ShowRankingScore: true, | ||
| ShowRankingScoreDetails: true, | ||
| }, | ||
| expected: `{"id":"1","embedder":"default","showRankingScore":true,"showRankingScoreDetails":true,"showPerformanceDetails":true}`, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| data, err := json.Marshal(tt.query) | ||
| require.NoError(t, err) | ||
| require.JSONEq(t, tt.expected, string(data)) | ||
| }) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.