fix: SearXNG max_results 面板配置未生效,现读取面板值作为上限(与AI传入取较小值)

This commit is contained in:
thzxx
2026-06-12 12:57:57 +08:00
parent 9a547849eb
commit 016c96c565
+6 -4
View File
@@ -455,6 +455,8 @@ async function handleWebSearchSearxng(
const safesearch = getSetting<number>('searxng_safesearch', 1); const safesearch = getSetting<number>('searxng_safesearch', 1);
const cfgTimeRange = getSetting<string>('searxng_time_range', ''); const cfgTimeRange = getSetting<string>('searxng_time_range', '');
const effectiveTimeRange = timeRange || cfgTimeRange; const effectiveTimeRange = timeRange || cfgTimeRange;
const cfgMaxResults = getSetting<number>('searxng_max_results', 20);
const effectiveMaxResults = Math.min(maxResults, cfgMaxResults);
const format = getSetting<string>('searxng_format', 'json'); const format = getSetting<string>('searxng_format', 'json');
const isHtml = format === 'html'; const isHtml = format === 'html';
@@ -487,8 +489,8 @@ async function handleWebSearchSearxng(
if (isHtml) { if (isHtml) {
const html = await resp.text(); const html = await resp.text();
const text = htmlToText(html); const text = htmlToText(html);
const truncated = maxResults > 0 && text.length > maxResults * 500; const truncated = effectiveMaxResults > 0 && text.length > effectiveMaxResults * 500;
const content = truncated ? text.slice(0, maxResults * 500) + '\n...(已截断)' : text; const content = truncated ? text.slice(0, effectiveMaxResults * 500) + '\n...(已截断)' : text;
sendLog('success', `🔍 SearXNG HTML 完成`, `${text.length} 字符`); sendLog('success', `🔍 SearXNG HTML 完成`, `${text.length} 字符`);
return { return {
success: true, success: true,
@@ -516,7 +518,7 @@ async function handleWebSearchSearxng(
unresponsive_engines?: Array<[string, string]>; unresponsive_engines?: Array<[string, string]>;
}; };
const rawResults = (data.results || []).slice(0, maxResults); const rawResults = (data.results || []).slice(0, effectiveMaxResults);
if (rawResults.length === 0) { if (rawResults.length === 0) {
return { success: false, error: 'SearXNG 未返回任何结果,请尝试其他关键词或调整搜索引擎配置' }; return { success: false, error: 'SearXNG 未返回任何结果,请尝试其他关键词或调整搜索引擎配置' };
} }
@@ -552,7 +554,7 @@ async function handleWebSearchSearxng(
weight: 80, weight: 80,
reachable: true, reachable: true,
})), })),
maxResults, effectiveMaxResults,
false, false,
engineStats engineStats
); );