Spaces:
Build error
Build error
Aaron Ji commited on
chore: support 'gl', 'hl', 'location' and 'page' when search (#1156)
Browse files
backend/functions/src/cloud-functions/searcher-serper.ts
CHANGED
|
@@ -16,8 +16,9 @@ import { SerperSearchResult } from '../db/searched';
|
|
| 16 |
import { CrawlerOptions } from '../dto/scrapping-options';
|
| 17 |
import { SnapshotFormatter, FormattedPage } from '../services/snapshot-formatter';
|
| 18 |
import { GoogleSearchExplicitOperatorsDto, SerperSearchService } from '../services/serper-search';
|
| 19 |
-
import { SerperSearchQueryParams, SerperSearchResponse } from '../shared/3rd-party/serper-search';
|
| 20 |
|
|
|
|
| 21 |
|
| 22 |
@singleton()
|
| 23 |
export class SearcherHost extends RPCHost {
|
|
@@ -82,10 +83,14 @@ export class SearcherHost extends RPCHost {
|
|
| 82 |
res: Response,
|
| 83 |
},
|
| 84 |
auth: JinaEmbeddingsAuthDTO,
|
| 85 |
-
@Param('count', { default: 5, validate: (v) => v >= 0 && v <= 20 })
|
| 86 |
-
count: number,
|
| 87 |
crawlerOptions: CrawlerOptions,
|
| 88 |
searchExplicitOperators: GoogleSearchExplicitOperatorsDto,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
@Param('q') q?: string,
|
| 90 |
) {
|
| 91 |
const uid = await auth.solveUID();
|
|
@@ -149,7 +154,11 @@ export class SearcherHost extends RPCHost {
|
|
| 149 |
const searchQuery = searchExplicitOperators.addTo(q || noSlashPath);
|
| 150 |
const r = await this.cachedWebSearch({
|
| 151 |
q: searchQuery,
|
| 152 |
-
num: count > 10 ? 20 : 10
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
}, crawlerOptions.noCache);
|
| 154 |
|
| 155 |
if (!r.organic.length) {
|
|
|
|
| 16 |
import { CrawlerOptions } from '../dto/scrapping-options';
|
| 17 |
import { SnapshotFormatter, FormattedPage } from '../services/snapshot-formatter';
|
| 18 |
import { GoogleSearchExplicitOperatorsDto, SerperSearchService } from '../services/serper-search';
|
| 19 |
+
import { SerperSearchQueryParams, SerperSearchResponse, WORLD_COUNTRIES, WORLD_LANGUAGES } from '../shared/3rd-party/serper-search';
|
| 20 |
|
| 21 |
+
const WORLD_COUNTRY_CODES = Object.keys(WORLD_COUNTRIES);
|
| 22 |
|
| 23 |
@singleton()
|
| 24 |
export class SearcherHost extends RPCHost {
|
|
|
|
| 83 |
res: Response,
|
| 84 |
},
|
| 85 |
auth: JinaEmbeddingsAuthDTO,
|
|
|
|
|
|
|
| 86 |
crawlerOptions: CrawlerOptions,
|
| 87 |
searchExplicitOperators: GoogleSearchExplicitOperatorsDto,
|
| 88 |
+
@Param('count', { default: 5, validate: (v) => v >= 0 && v <= 20 })
|
| 89 |
+
count: number,
|
| 90 |
+
@Param('gl', { validate: (v: string) => WORLD_COUNTRY_CODES.includes(v) }) gl?: string,
|
| 91 |
+
@Param('hl', { validate: (v: string) => WORLD_LANGUAGES.some(l => l.code === v) }) hl?: string,
|
| 92 |
+
@Param('location') location?: string,
|
| 93 |
+
@Param('page') page?: number,
|
| 94 |
@Param('q') q?: string,
|
| 95 |
) {
|
| 96 |
const uid = await auth.solveUID();
|
|
|
|
| 154 |
const searchQuery = searchExplicitOperators.addTo(q || noSlashPath);
|
| 155 |
const r = await this.cachedWebSearch({
|
| 156 |
q: searchQuery,
|
| 157 |
+
num: count > 10 ? 20 : 10,
|
| 158 |
+
gl,
|
| 159 |
+
hl,
|
| 160 |
+
location,
|
| 161 |
+
page,
|
| 162 |
}, crawlerOptions.noCache);
|
| 163 |
|
| 164 |
if (!r.organic.length) {
|