open-webui/backend/open_webui/apps/rag/search/main.py

23 lines
596 B
Python
Raw Normal View History

from typing import Optional
from urllib.parse import urlparse
2024-08-27 22:10:27 +00:00
from pydantic import BaseModel
def get_filtered_results(results, filter_list):
if not filter_list:
return results
filtered_results = []
for result in results:
url = result.get("url") or result.get("link", "")
domain = urlparse(url).netloc
if any(domain.endswith(filtered_domain) for filtered_domain in filter_list):
filtered_results.append(result)
return filtered_results
2024-06-17 21:32:23 +00:00
class SearchResult(BaseModel):
link: str
title: Optional[str]
snippet: Optional[str]