Skip to content

Commit f1d3f60

Browse files
authored
Merge pull request #254 from tharropoulos/union-pagination
fix: add missing page parameter for union search pagination
2 parents f3674e5 + 052783c commit f1d3f60

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/SearchRequestAdapter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ export class SearchRequestAdapter {
491491
// Add union parameter if configured
492492
if (this.configuration.union) {
493493
searchRequest.union = this.configuration.union;
494+
commonParams.page = searches[0].page;
494495
}
495496

496497
return this.typesenseClient.multiSearch.perform(searchRequest, commonParams);

test/SearchRequestAdpater.test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ describe("SearchRequestAdapter", () => {
332332
},
333333
],
334334
},
335-
{},
335+
{
336+
page: 1,
337+
},
336338
);
337339
});
338340

@@ -466,6 +468,7 @@ describe("SearchRequestAdapter", () => {
466468
conversation: true,
467469
conversation_id: "conv_123",
468470
conversation_model_id: "model_456",
471+
page: 1,
469472
},
470473
);
471474
});
@@ -507,7 +510,9 @@ describe("SearchRequestAdapter", () => {
507510
},
508511
],
509512
},
510-
{},
513+
{
514+
page: 1,
515+
},
511516
);
512517
});
513518
});

test/unionSearch.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,37 @@ describe("Union Search", () => {
5858
});
5959
});
6060
});
61+
62+
describe("pagination with union search", () => {
63+
beforeEach(async () => {
64+
return expect(page).toFill("#searchbox input[type=search]", "phone");
65+
});
66+
67+
it("renders pagination controls for merged results from multiple indices", async () => {
68+
await page.waitForSelector("#pagination a.ais-Pagination-link");
69+
70+
const paginationLinks = await page.$$("#pagination a.ais-Pagination-link");
71+
expect(paginationLinks.length).toBeGreaterThan(0);
72+
73+
await expect(page).toMatchElement("#hits .ais-Hits-item:nth-of-type(1)");
74+
});
75+
76+
it("shows different merged results when navigating to the second page", async () => {
77+
await page.waitForSelector("#pagination a.ais-Pagination-link");
78+
79+
const firstPageFirstResult = await page.$eval("#hits .ais-Hits-item:nth-of-type(1)", (el) => el.textContent);
80+
81+
await expect(page).toClick("#pagination a", { text: "2" });
82+
83+
await page.waitForSelector("#hits .ais-Hits-item:nth-of-type(1)");
84+
85+
const secondPageFirstResult = await page.$eval("#hits .ais-Hits-item:nth-of-type(1)", (el) => el.textContent);
86+
87+
expect(firstPageFirstResult).not.toBe(secondPageFirstResult);
88+
89+
await expect(page).toMatchElement("#hits");
90+
await expect(page).not.toMatchElement("#product-hits", { timeout: 1000 });
91+
await expect(page).not.toMatchElement("#brand-hits", { timeout: 1000 });
92+
});
93+
});
6194
});

0 commit comments

Comments
 (0)