fix: search params

This commit is contained in:
Yanlong Wang 2025-01-26 21:21:48 +08:00
parent 234f61d066
commit cc6d2f3e29
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37
2 changed files with 23 additions and 5 deletions

View File

@ -82,7 +82,7 @@ export class SearcherHost extends RPCHost {
res: Response,
},
auth: JinaEmbeddingsAuthDTO,
@Param('count', { default: 5, validate: (v) => v >= 3 && v <= 10 })
@Param('count', { default: 5, validate: (v) => v >= 0 && v <= 10 })
count: number,
crawlerOptions: CrawlerOptions,
braveSearchExplicitOperators: BraveSearchExplicitOperatorsDto,
@ -144,7 +144,7 @@ export class SearcherHost extends RPCHost {
const searchQuery = braveSearchExplicitOperators.addTo(q || noSlashPath);
const r = await this.cachedWebSearch({
q: searchQuery,
count: Math.floor(count + 2)
count: count ? Math.floor(count + 2) : 20
}, crawlerOptions.noCache);
if (!r.web?.results.length) {
@ -300,6 +300,26 @@ export class SearcherHost extends RPCHost {
if (!searchResults) {
return;
}
if (count === 0) {
const resultArray = searchResults.map((upstreamSearchResult, i) => ({
url: upstreamSearchResult.url,
title: upstreamSearchResult.title,
description: upstreamSearchResult.description,
content: ['html', 'text', 'screenshot'].includes(mode) ? undefined : '',
toString() {
return `[${i + 1}] Title: ${this.title}
[${i + 1}] URL Source: ${this.url}
[${i + 1}] Description: ${this.description}
`;
}
})) as FormattedPage[];
resultArray.toString = function () {
return this.map((x, i) => x ? x.toString() : '').join('\n\n').trimEnd() + '\n';
};
yield resultArray;
return;
}
const urls = searchResults.map((x) => new URL(x.url));
const snapshotMap = new WeakMap();
for await (const scrapped of this.crawler.scrapMany(urls, options, crawlerOptions)) {

View File

@ -300,9 +300,7 @@ export class CrawlerOptions extends AutoCastable {
@Prop()
userAgent?: string;
@Prop({
type: ENGINE_TYPE,
})
@Prop()
engine?: string;
@Prop({