chore: support 'gl', 'hl', 'location' and 'page' when search (#1156)

This commit is contained in:
Aaron Ji 2025-03-04 17:34:49 +08:00 committed by GitHub
parent 21ae52a55a
commit a7ffb58741
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -16,8 +16,9 @@ import { SerperSearchResult } from '../db/searched';
import { CrawlerOptions } from '../dto/scrapping-options'; import { CrawlerOptions } from '../dto/scrapping-options';
import { SnapshotFormatter, FormattedPage } from '../services/snapshot-formatter'; import { SnapshotFormatter, FormattedPage } from '../services/snapshot-formatter';
import { GoogleSearchExplicitOperatorsDto, SerperSearchService } from '../services/serper-search'; import { GoogleSearchExplicitOperatorsDto, SerperSearchService } from '../services/serper-search';
import { SerperSearchQueryParams, SerperSearchResponse } from '../shared/3rd-party/serper-search'; import { SerperSearchQueryParams, SerperSearchResponse, WORLD_COUNTRIES, WORLD_LANGUAGES } from '../shared/3rd-party/serper-search';
const WORLD_COUNTRY_CODES = Object.keys(WORLD_COUNTRIES);
@singleton() @singleton()
export class SearcherHost extends RPCHost { export class SearcherHost extends RPCHost {
@ -82,10 +83,14 @@ export class SearcherHost extends RPCHost {
res: Response, res: Response,
}, },
auth: JinaEmbeddingsAuthDTO, auth: JinaEmbeddingsAuthDTO,
@Param('count', { default: 5, validate: (v) => v >= 0 && v <= 20 })
count: number,
crawlerOptions: CrawlerOptions, crawlerOptions: CrawlerOptions,
searchExplicitOperators: GoogleSearchExplicitOperatorsDto, searchExplicitOperators: GoogleSearchExplicitOperatorsDto,
@Param('count', { default: 5, validate: (v) => v >= 0 && v <= 20 })
count: 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, @Param('q') q?: string,
) { ) {
const uid = await auth.solveUID(); const uid = await auth.solveUID();
@ -149,7 +154,11 @@ export class SearcherHost extends RPCHost {
const searchQuery = searchExplicitOperators.addTo(q || noSlashPath); const searchQuery = searchExplicitOperators.addTo(q || noSlashPath);
const r = await this.cachedWebSearch({ const r = await this.cachedWebSearch({
q: searchQuery, q: searchQuery,
num: count > 10 ? 20 : 10 num: count > 10 ? 20 : 10,
gl,
hl,
location,
page,
}, crawlerOptions.noCache); }, crawlerOptions.noCache);
if (!r.organic.length) { if (!r.organic.length) {