From 016c96c56599e2341a47c7ada981e8fe42460b30 Mon Sep 17 00:00:00 2001 From: thzxx Date: Fri, 12 Jun 2026 12:57:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20SearXNG=20max=5Fresults=20=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E9=85=8D=E7=BD=AE=E6=9C=AA=E7=94=9F=E6=95=88=EF=BC=8C?= =?UTF-8?q?=E7=8E=B0=E8=AF=BB=E5=8F=96=E9=9D=A2=E6=9D=BF=E5=80=BC=E4=BD=9C?= =?UTF-8?q?=E4=B8=BA=E4=B8=8A=E9=99=90=EF=BC=88=E4=B8=8EAI=E4=BC=A0?= =?UTF-8?q?=E5=85=A5=E5=8F=96=E8=BE=83=E5=B0=8F=E5=80=BC=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/tool-handlers-system.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/tool-handlers-system.ts b/src/main/tool-handlers-system.ts index d5dd3d0..b5238ac 100644 --- a/src/main/tool-handlers-system.ts +++ b/src/main/tool-handlers-system.ts @@ -455,6 +455,8 @@ async function handleWebSearchSearxng( const safesearch = getSetting('searxng_safesearch', 1); const cfgTimeRange = getSetting('searxng_time_range', ''); const effectiveTimeRange = timeRange || cfgTimeRange; + const cfgMaxResults = getSetting('searxng_max_results', 20); + const effectiveMaxResults = Math.min(maxResults, cfgMaxResults); const format = getSetting('searxng_format', 'json'); const isHtml = format === 'html'; @@ -487,8 +489,8 @@ async function handleWebSearchSearxng( if (isHtml) { const html = await resp.text(); const text = htmlToText(html); - const truncated = maxResults > 0 && text.length > maxResults * 500; - const content = truncated ? text.slice(0, maxResults * 500) + '\n...(已截断)' : text; + const truncated = effectiveMaxResults > 0 && text.length > effectiveMaxResults * 500; + const content = truncated ? text.slice(0, effectiveMaxResults * 500) + '\n...(已截断)' : text; sendLog('success', `🔍 SearXNG HTML 完成`, `${text.length} 字符`); return { success: true, @@ -516,7 +518,7 @@ async function handleWebSearchSearxng( unresponsive_engines?: Array<[string, string]>; }; - const rawResults = (data.results || []).slice(0, maxResults); + const rawResults = (data.results || []).slice(0, effectiveMaxResults); if (rawResults.length === 0) { return { success: false, error: 'SearXNG 未返回任何结果,请尝试其他关键词或调整搜索引擎配置' }; } @@ -552,7 +554,7 @@ async function handleWebSearchSearxng( weight: 80, reachable: true, })), - maxResults, + effectiveMaxResults, false, engineStats );