chore: serp provider tweak

This commit is contained in:
Yanlong Wang 2025-05-05 22:55:28 +08:00
parent 845e441b0a
commit e9f5be541b
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37
2 changed files with 6 additions and 4 deletions

View File

@ -26,6 +26,7 @@ import { SerperBingSearchService, SerperGoogleSearchService } from '../services/
import type { JinaEmbeddingsTokenAccount } from '../shared/db/jina-embeddings-token-account'; import type { JinaEmbeddingsTokenAccount } from '../shared/db/jina-embeddings-token-account';
import { LRUCache } from 'lru-cache'; import { LRUCache } from 'lru-cache';
import { API_CALL_STATUS } from '../shared/db/api-roll'; import { API_CALL_STATUS } from '../shared/db/api-roll';
import { InternalJinaSerpService } from '../services/serp/internal';
const WORLD_COUNTRY_CODES = Object.keys(WORLD_COUNTRIES).map((x) => x.toLowerCase()); const WORLD_COUNTRY_CODES = Object.keys(WORLD_COUNTRIES).map((x) => x.toLowerCase());
@ -92,6 +93,7 @@ export class SerpHost extends RPCHost {
protected googleSerp: GoogleSERP, protected googleSerp: GoogleSERP,
protected serperGoogle: SerperGoogleSearchService, protected serperGoogle: SerperGoogleSearchService,
protected serperBing: SerperBingSearchService, protected serperBing: SerperBingSearchService,
protected jinaSerp: InternalJinaSerpService,
) { ) {
super(...arguments); super(...arguments);
@ -449,7 +451,7 @@ export class SerpHost extends RPCHost {
return result; return result;
} }
*iterProviders(preference?: string) { *iterProviders(preference?: string, variant?: string) {
if (preference === 'bing') { if (preference === 'bing') {
yield this.serperBing; yield this.serperBing;
yield this.serperGoogle; yield this.serperGoogle;
@ -466,9 +468,9 @@ export class SerpHost extends RPCHost {
return; return;
} }
yield variant === 'web' ? this.jinaSerp : this.serperGoogle;
yield this.serperGoogle; yield this.serperGoogle;
yield this.googleSerp; yield this.googleSerp;
yield this.googleSerp;
} }
async cachedSearch(variant: 'web' | 'news' | 'images', query: Record<string, any>, opts: CrawlerOptions) { async cachedSearch(variant: 'web' | 'news' | 'images', query: Record<string, any>, opts: CrawlerOptions) {
@ -501,7 +503,7 @@ export class SerpHost extends RPCHost {
let r: any[] | undefined; let r: any[] | undefined;
let lastError; let lastError;
outerLoop: outerLoop:
for (const client of this.iterProviders(provider)) { for (const client of this.iterProviders(provider, variant)) {
const t0 = Date.now(); const t0 = Date.now();
try { try {
switch (variant) { switch (variant) {

@ -1 +1 @@
Subproject commit a23636b2161908eefd897b6976c10a5924e2cd57 Subproject commit 69808307131d4fbd8ef0026f5d2dcb90ebdfad8c