Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions integration/index_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,26 @@ func TestIndex_FacetSearch(t *testing.T) {
},
wantErr: false,
},
{
name: "TestIndexFacetSearchWithFilterArray",
args: args{
UID: "indexUID",
client: sv,
request: &meilisearch.FacetSearchRequest{
FacetName: "tag",
FacetQuery: "Novel",
Filter: []string{"tag = Novel"},
},
filterableAttributes: []interface{}{"tag"},
},
want: &meilisearch.FacetSearchResponse{
FacetHits: meilisearch.Hits{
{"value": toRawMessage("Novel"), "count": toRawMessage(5)},
},
FacetQuery: "Novel",
},
wantErr: false,
},
}

for _, tt := range tests {
Expand Down
22 changes: 22 additions & 0 deletions issue_body.md
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.

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.
5 changes: 4 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ type SearchRequest struct {
ShowMatchesPosition bool `json:"showMatchesPosition,omitempty"`
ShowRankingScore bool `json:"showRankingScore,omitempty"`
ShowRankingScoreDetails bool `json:"showRankingScoreDetails,omitempty"`
ShowPerformanceDetails bool `json:"showPerformanceDetails,omitempty"`
Facets []string `json:"facets,omitempty"`
Sort []string `json:"sort,omitempty"`
Vector []float32 `json:"vector,omitempty"`
Expand Down Expand Up @@ -596,6 +597,7 @@ type SearchResponse struct {
FacetStats json.RawMessage `json:"facetStats,omitempty"`
IndexUID string `json:"indexUid,omitempty"`
QueryVector *[]float32 `json:"queryVector,omitempty"`
PerformanceDetails json.RawMessage `json:"performanceDetails,omitempty"`
}

type MultiSearchResponse struct {
Expand All @@ -622,7 +624,7 @@ type FacetSearchRequest struct {
FacetName string `json:"facetName,omitempty"`
FacetQuery string `json:"facetQuery,omitempty"`
Q string `json:"q,omitempty"`
Filter string `json:"filter,omitempty"`
Filter interface{} `json:"filter,omitempty"`
MatchingStrategy string `json:"matchingStrategy,omitempty"`
AttributesToSearchOn []string `json:"attributesToSearchOn,omitempty"`
ExhaustiveFacetCount bool `json:"exhaustiveFacetCount,omitempty"`
Expand Down Expand Up @@ -661,6 +663,7 @@ type SimilarDocumentQuery struct {
Filter string `json:"filter,omitempty"`
ShowRankingScore bool `json:"showRankingScore,omitempty"`
ShowRankingScoreDetails bool `json:"showRankingScoreDetails,omitempty"`
ShowPerformanceDetails bool `json:"showPerformanceDetails,omitempty"`
RankingScoreThreshold float64 `json:"rankingScoreThreshold,omitempty"`
RetrieveVectors bool `json:"retrieveVectors,omitempty"`
}
Expand Down
138 changes: 138 additions & 0 deletions types_performance_details_test.go
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.

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))
})
}
}