From ed80c9a4a2c340fb7c874347d3f25501e42ca251 Mon Sep 17 00:00:00 2001 From: Aaron Ji <127167174+DresAaron@users.noreply.github.com> Date: Wed, 5 Mar 2025 11:20:55 +0800 Subject: [PATCH] chore: expose 'num' param for search API (#1157) * chore: expose 'num' param for search API * fix: wrong count value --- backend/functions/src/cloud-functions/searcher-serper.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/functions/src/cloud-functions/searcher-serper.ts b/backend/functions/src/cloud-functions/searcher-serper.ts index 726381d..0d145d4 100644 --- a/backend/functions/src/cloud-functions/searcher-serper.ts +++ b/backend/functions/src/cloud-functions/searcher-serper.ts @@ -85,14 +85,21 @@ export class SearcherHost extends RPCHost { auth: JinaEmbeddingsAuthDTO, crawlerOptions: CrawlerOptions, searchExplicitOperators: GoogleSearchExplicitOperatorsDto, - @Param('count', { default: 5, validate: (v) => v >= 0 && v <= 20 }) + @Param('count', { validate: (v: number) => v >= 0 && v <= 20 }) count: number, + @Param('num', { validate: (v: number) => v >= 0 && v <= 20 }) + num?: number, @Param('gl', { validate: (v: string) => WORLD_COUNTRY_CODES.includes(v) }) gl?: string, @Param('hl', { validate: (v: string) => WORLD_LANGUAGES.some(l => l.code === v) }) hl?: string, @Param('location') location?: string, @Param('page') page?: number, @Param('q') q?: string, ) { + // We want to make our search API follow SERP schema, so we need to expose 'num' parameter. + // Since we used 'count' as 'num' previously, we need to keep 'count' for old users. + // Here we combine 'count' and 'num' to 'count' for the rest of the function. + count = (num !== undefined ? num : count) ?? 5; + const uid = await auth.solveUID(); // Return content by default const respondWith = ctx.req.get('X-Respond-With') ?? 'content';