Skip to content

Commit

Permalink
Add multi-search federation
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfloyd committed Aug 28, 2024
1 parent 345439c commit 97600c4
Show file tree
Hide file tree
Showing 3 changed files with 726 additions and 418 deletions.
6 changes: 3 additions & 3 deletions meilisearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ func TestClient_MultiSearch(t *testing.T) {
args: args{
client: sv,
queries: &MultiSearchRequest{
[]*SearchRequest{
Queries: []*SearchRequest{
{
IndexUID: "TestClientMultiSearchOneIndex",
Query: "wonder",
Expand Down Expand Up @@ -2017,7 +2017,7 @@ func TestClient_MultiSearch(t *testing.T) {
args: args{
client: sv,
queries: &MultiSearchRequest{
[]*SearchRequest{
Queries: []*SearchRequest{
{
IndexUID: "TestClientMultiSearchOnTwoIndexes1",
Query: "wonder",
Expand Down Expand Up @@ -2070,7 +2070,7 @@ func TestClient_MultiSearch(t *testing.T) {
args: args{
client: sv,
queries: &MultiSearchRequest{
[]*SearchRequest{
Queries: []*SearchRequest{
{
Query: "",
},
Expand Down
76 changes: 45 additions & 31 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,32 +378,37 @@ type CreateIndexRequest struct {
//
// Documentation: https://www.meilisearch.com/docs/reference/api/search#search-parameters
type SearchRequest struct {
Offset int64 `json:"offset,omitempty"`
Limit int64 `json:"limit,omitempty"`
AttributesToRetrieve []string `json:"attributesToRetrieve,omitempty"`
AttributesToSearchOn []string `json:"attributesToSearchOn,omitempty"`
AttributesToCrop []string `json:"attributesToCrop,omitempty"`
CropLength int64 `json:"cropLength,omitempty"`
CropMarker string `json:"cropMarker,omitempty"`
AttributesToHighlight []string `json:"attributesToHighlight,omitempty"`
HighlightPreTag string `json:"highlightPreTag,omitempty"`
HighlightPostTag string `json:"highlightPostTag,omitempty"`
MatchingStrategy MatchingStrategy `json:"matchingStrategy,omitempty"`
Filter interface{} `json:"filter,omitempty"`
ShowMatchesPosition bool `json:"showMatchesPosition,omitempty"`
ShowRankingScore bool `json:"showRankingScore,omitempty"`
ShowRankingScoreDetails bool `json:"showRankingScoreDetails,omitempty"`
Facets []string `json:"facets,omitempty"`
Sort []string `json:"sort,omitempty"`
Vector []float32 `json:"vector,omitempty"`
HitsPerPage int64 `json:"hitsPerPage,omitempty"`
Page int64 `json:"page,omitempty"`
IndexUID string `json:"indexUid,omitempty"`
Query string `json:"q"`
Distinct string `json:"distinct,omitempty"`
Hybrid *SearchRequestHybrid `json:"hybrid,omitempty"`
RetrieveVectors bool `json:"retrieveVectors,omitempty"`
RankingScoreThreshold float64 `json:"rankingScoreThreshold,omitempty"`
Offset int64 `json:"offset,omitempty"`
Limit int64 `json:"limit,omitempty"`
AttributesToRetrieve []string `json:"attributesToRetrieve,omitempty"`
AttributesToSearchOn []string `json:"attributesToSearchOn,omitempty"`
AttributesToCrop []string `json:"attributesToCrop,omitempty"`
CropLength int64 `json:"cropLength,omitempty"`
CropMarker string `json:"cropMarker,omitempty"`
AttributesToHighlight []string `json:"attributesToHighlight,omitempty"`
HighlightPreTag string `json:"highlightPreTag,omitempty"`
HighlightPostTag string `json:"highlightPostTag,omitempty"`
MatchingStrategy MatchingStrategy `json:"matchingStrategy,omitempty"`
Filter interface{} `json:"filter,omitempty"`
ShowMatchesPosition bool `json:"showMatchesPosition,omitempty"`
ShowRankingScore bool `json:"showRankingScore,omitempty"`
ShowRankingScoreDetails bool `json:"showRankingScoreDetails,omitempty"`
Facets []string `json:"facets,omitempty"`
Sort []string `json:"sort,omitempty"`
Vector []float32 `json:"vector,omitempty"`
HitsPerPage int64 `json:"hitsPerPage,omitempty"`
Page int64 `json:"page,omitempty"`
IndexUID string `json:"indexUid,omitempty"`
Query string `json:"q"`
Distinct string `json:"distinct,omitempty"`
Hybrid *SearchRequestHybrid `json:"hybrid,omitempty"`
RetrieveVectors bool `json:"retrieveVectors,omitempty"`
RankingScoreThreshold float64 `json:"rankingScoreThreshold,omitempty"`
FederationOptions *SearchFederationOptions `json:"federationOptions,omitempty"`
}

type SearchFederationOptions struct {
Weight float64 `json:"weight"`
}

type SearchRequestHybrid struct {
Expand All @@ -412,7 +417,13 @@ type SearchRequestHybrid struct {
}

type MultiSearchRequest struct {
Queries []*SearchRequest `json:"queries"`
Federation *MultiSearchFederation `json:"federation,omitempty"`
Queries []*SearchRequest `json:"queries"`
}

type MultiSearchFederation struct {
Offset int64 `json:"offset,omitempty"`
Limit int64 `json:"limit,omitempty"`
}

// SearchResponse is the response body for search method
Expand All @@ -433,7 +444,13 @@ type SearchResponse struct {
}

type MultiSearchResponse struct {
Results []SearchResponse `json:"results"`
Results []SearchResponse `json:"results,omitempty"`
Hits []interface{} `json:"hits,omitempty"`
ProcessingTimeMs int64 `json:"processingTimeMs,omitempty"`
Offset int64 `json:"offset,omitempty"`
Limit int64 `json:"limit,omitempty"`
EstimatedTotalHits int64 `json:"estimatedTotalHits,omitempty"`
SemanticHitCount int64 `json:"semanticHitCount,omitempty"`
}

type FacetSearchRequest struct {
Expand Down Expand Up @@ -531,9 +548,6 @@ func (b RawType) MarshalJSON() ([]byte, error) {
}

func (s *SearchRequest) validate() {
if s.Limit == 0 {
s.Limit = DefaultLimit
}
if s.Hybrid != nil && s.Hybrid.Embedder == "" {
s.Hybrid.Embedder = "default"
}
Expand Down
Loading

0 comments on commit 97600c4

Please sign in to comment.