feat: support explicit q passing in search

This commit is contained in:
Yanlong Wang 2024-09-08 10:38:35 +08:00
parent 607407f740
commit e324c4667f
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37

View File

@ -86,11 +86,12 @@ export class SearcherHost extends RPCHost {
count: number,
crawlerOptions: CrawlerOptions,
braveSearchExplicitOperators: BraveSearchExplicitOperatorsDto,
@Param('q') q?: string,
) {
const uid = await auth.solveUID();
let chargeAmount = 0;
const noSlashPath = ctx.req.url.slice(1);
if (!noSlashPath) {
if (!noSlashPath && !q) {
const latestUser = uid ? await auth.assertUser() : undefined;
if (!ctx.req.accepts('text/plain') && (ctx.req.accepts('text/json') || ctx.req.accepts('application/json'))) {
@ -151,7 +152,7 @@ export class SearcherHost extends RPCHost {
delete crawlerOptions.html;
const crawlOpts = this.crawler.configure(crawlerOptions);
const searchQuery = braveSearchExplicitOperators.addTo(ctx.req.path.slice(1));
const searchQuery = braveSearchExplicitOperators.addTo(q || ctx.req.path.slice(1));
const r = await this.cachedWebSearch({
q: searchQuery,
count: Math.floor(count + 2)