Skip to content

SearchResponseRequestParams doesn't match with actual API response #321

@Raanelom

Description

@Raanelom

When performing a multiSearch (union) on two collections, I get the following response:

{
  "found": 131,
  "hits": [ ],
  "etc": { },
  "union_request_params": [
    { 
      "collection": "collection_one",
      "first_q": "test",
      "found": 30
      "per_page": 18
      "q": "test"
    },
    { 
      "collection": "collection_two",
      "first_q": "test",
      "found": 101
      "per_page": 18
      "q": "test"
    }
  ]
}

However, when looking at the SearchResponseRequestParams-type, it expects the following:

export interface SearchResponseRequestParams {
    collection_name?: string;
    q?: string;
    page?: number;
    per_page?: number;
    first_q?: string;
    voice_query?: {
        transcribed_query?: string;
    };
}

The collection_name does not match with the actual collection-property, thus my typing is now broken.

More context

Request:

const searchRequests: MultiSearchRequestsWithUnionSchema<
  Array<CollectionOneResult | CollectionTwoResult>,
  string
> = {
  union: true,
  searches: [
    {
      collection: `CollectionOne`,
      q: "test",
      query_by: "title,content,intro",
      filter_by: "_level:0",
    },
    {
      collection: `CollectionTwo`,
      q: "test",
      query_by: "title,review,description",
      filter_by: "_level:0",
    },
  ],
};

const commonParams = {
  limit: 18,
  page: 1,
};

// Perform the actual query

const results = await client.multiSearch.perform<
  Array<CollectionOneResult | CollectionTwoResult>,
  string
>(searchRequests, commonParams);

// This line breaks
const collections = results?.union_request_params?.map((req) => req.collection); // Expects collection_name

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions