Skip to content
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

Add new search param showRankingScoreDetails #528

Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ search_parameter_guide_show_ranking_score_1: |-
resp, err := client.Index("movies").Search("dragon", &meilisearch.SearchRequest{
showRankingScore: true,
})
search_parameter_guide_show_ranking_score_details_1: |-
resp, err := client.Index("movies").Search("dragon", &meilisearch.SearchRequest{
showRankingScoreDetails: true,
})
search_parameter_guide_matching_strategy_1: |-
resp, err := client.Index("movies").Search("big fat liar", &meilisearch.SearchRequest{
MatchingStrategy: "last",
Expand Down
5 changes: 3 additions & 2 deletions index_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ func searchPostRequestParams(query string, request *SearchRequest) map[string]in
if request.ShowRankingScore {
params["showRankingScore"] = request.ShowRankingScore
}
if request.ShowRankingScoreDetails {
params["showRankingScoreDetails"] = request.ShowRankingScoreDetails
}
if request.Filter != nil {
params["filter"] = request.Filter
}
Expand Down Expand Up @@ -141,11 +144,9 @@ func searchPostRequestParams(query string, request *SearchRequest) map[string]in
if len(request.Sort) != 0 {
params["sort"] = request.Sort
}

if request.Vector != nil && len(request.Vector) > 0 {
params["vector"] = request.Vector
}

if request.Hybrid != nil {
hybrid := make(map[string]interface{}, 2)
hybrid["embedder"] = request.Hybrid.Embedder
Expand Down
26 changes: 26 additions & 0 deletions index_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,32 @@ func TestIndex_SearchWithShowRankingScore(t *testing.T) {
require.NotNil(t, got.Hits[0].(map[string]interface{})["_rankingScore"])
}

func TestIndex_SearchWithShowRankingScoreDetails(t *testing.T) {
type args struct {
UID string
PrimaryKey string
client *Client
query string
request SearchRequest
}
testArg := args{
UID: "indexUID",
client: defaultClient,
query: "and",
request: SearchRequest{
ShowRankingScoreDetails: true,
},
}
SetUpIndexForFaceting()
c := testArg.client
i := c.Index(testArg.UID)
t.Cleanup(cleanup(c))

got, err := i.Search(testArg.query, &testArg.request)
require.NoError(t, err)
require.NotNil(t, got.Hits[0].(map[string]interface{})["_rankingScoreDetails"])
}

func TestIndex_SearchWithVectorStore(t *testing.T) {
type args struct {
UID string
Expand Down
47 changes: 24 additions & 23 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,29 +337,30 @@ type CreateIndexRequest struct {
//
// Documentation: https://www.meilisearch.com/docs/reference/api/search#search-parameters
type SearchRequest struct {
Offset int64
Limit int64
AttributesToRetrieve []string
AttributesToSearchOn []string
AttributesToCrop []string
CropLength int64
CropMarker string
AttributesToHighlight []string
HighlightPreTag string
HighlightPostTag string
MatchingStrategy string
Filter interface{}
ShowMatchesPosition bool
ShowRankingScore bool
Facets []string
PlaceholderSearch bool
Sort []string
Vector []float32
HitsPerPage int64
Page int64
IndexUID string
Query string
Hybrid *SearchRequestHybrid
Offset int64
Limit int64
AttributesToRetrieve []string
AttributesToSearchOn []string
AttributesToCrop []string
CropLength int64
CropMarker string
AttributesToHighlight []string
HighlightPreTag string
HighlightPostTag string
MatchingStrategy string
Filter interface{}
ShowMatchesPosition bool
ShowRankingScore bool
ShowRankingScoreDetails bool
Facets []string
PlaceholderSearch bool
Sort []string
Vector []float32
HitsPerPage int64
Page int64
IndexUID string
Query string
Hybrid *SearchRequestHybrid
}

type SearchRequestHybrid struct {
Expand Down
7 changes: 7 additions & 0 deletions types_easyjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading