Skip to content
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: 2 additions & 2 deletions src/Typesense/MultiSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ export default class MultiSearch {
);
}

private isStreamingRequest(commonParams: { streamConfig?: unknown }) {
return commonParams.streamConfig !== undefined;
private isStreamingRequest(commonParams: { conversation_stream?: boolean }) {
return commonParams.conversation_stream === true;
}

private hasAnySearchObjectPagination(searchRequests: MultiSearchRequestsSchema<DocumentSchema, string>) {
Expand Down
51 changes: 51 additions & 0 deletions test/streaming.node.mock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,57 @@ describe("Streaming responses with axios-mock-adapter", () => {
expect(response.results[0].hits?.length).toBeGreaterThan(0);
});

it("should not treat multisearch as streaming when streamConfig is set but conversation_stream is not", async () => {
const onChunk = vi.fn();
const onComplete = vi.fn();
const onError = vi.fn();

const streamConfig: MultiSearchResultsStreamConfig<[Essay]> = {
onChunk,
onComplete,
onError,
};

let capturedResponseType: string | undefined;

const jsonResponse = {
results: [
{
found: 0,
hits: [],
},
],
};

mock.onAny().reply((config) => {
capturedResponseType = config.responseType;
return [200, jsonResponse, { "content-type": "application/json" }];
});

const response = await client.multiSearch.perform<[Essay]>(
{
searches: [
{
collection: "test-collection",
query_by: "title",
},
],
},
{
q: "*",
streamConfig,
},
);

expect(capturedResponseType).not.toBe("stream");
expect(onChunk).not.toHaveBeenCalled();
expect(onComplete).not.toHaveBeenCalled();
expect(onError).not.toHaveBeenCalled();
expect(response).toEqual(jsonResponse);
expect(response).not.toHaveProperty("conversation_id");
expect(response).not.toHaveProperty("message");
});

it("should invoke onError callback when an error occurs during stream processing", async () => {
const onChunk = vi.fn();
const onComplete = vi.fn();
Expand Down
Loading