mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-26 09:21:23 -04:00
fix: surface searchapi errors, news results and redirect links (#30308)
Web search via searchapi.io could come back empty or near-empty with no hint of why: an invalid or expired API key turned into an empty result set instead of an error, the google_news engine splits its results between organic_results and top_stories and only the first block was read, and google links came back as google.com/goto redirects the web loader cannot fetch, so citations pointed at a redirect blob. The search now reads both result blocks, asks google engines for resolved destination links, raises on HTTP errors, carries a 30s request timeout, skips result rows without a link, and logs the response body at debug instead of dumping every search at info. Fixes #30305
This commit is contained in:
@@ -26,19 +26,26 @@ def search_searchapi(
|
||||
engine = engine or 'google'
|
||||
|
||||
payload = {'engine': engine, 'q': query, 'api_key': api_key}
|
||||
if engine.startswith('google'):
|
||||
payload['link'] = 'resolved'
|
||||
|
||||
url = f'{url}?{urlencode(payload)}'
|
||||
response = requests.request('GET', url)
|
||||
response = requests.request('GET', url, timeout=30)
|
||||
response.raise_for_status()
|
||||
|
||||
json_response = response.json()
|
||||
log.info('results from searchapi search: %s', json_response)
|
||||
log.debug('results from searchapi search: %s', json_response)
|
||||
|
||||
results = sorted(json_response.get('organic_results', []), key=lambda x: x.get('position', 0))
|
||||
# top_stories entries carry no position, so the merged list keeps API order
|
||||
results = [
|
||||
*json_response.get('organic_results', []),
|
||||
*json_response.get('top_stories', []),
|
||||
]
|
||||
if filter_list:
|
||||
results = get_filtered_results(results, filter_list)
|
||||
return [
|
||||
SearchResult(
|
||||
link=result['link'],
|
||||
link=result.get('link', ''),
|
||||
title=result.get('title'),
|
||||
snippet=result.get('snippet'),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user