| 
									
										
										
										
											2025-02-04 07:37:20 +08:00
										 |  |  | import validators | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-06 12:27:46 +08:00
										 |  |  | from typing import Optional | 
					
						
							| 
									
										
										
										
											2024-06-13 08:14:48 +08:00
										 |  |  | from urllib.parse import urlparse | 
					
						
							| 
									
										
										
										
											2024-08-28 06:10:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-06 12:27:46 +08:00
										 |  |  | from pydantic import BaseModel | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-17 15:36:26 +08:00
										 |  |  | def get_filtered_results(results, filter_list): | 
					
						
							|  |  |  |     if not filter_list: | 
					
						
							| 
									
										
										
										
											2024-06-13 08:14:48 +08:00
										 |  |  |         return results | 
					
						
							|  |  |  |     filtered_results = [] | 
					
						
							|  |  |  |     for result in results: | 
					
						
							| 
									
										
										
										
											2025-08-21 16:51:41 +08:00
										 |  |  |         url = result.get("url") or result.get("link", "") or result.get("href", "") | 
					
						
							| 
									
										
										
										
											2025-02-04 07:37:20 +08:00
										 |  |  |         if not validators.url(url): | 
					
						
							|  |  |  |             continue | 
					
						
							| 
									
										
										
										
											2024-08-27 15:45:17 +08:00
										 |  |  |         domain = urlparse(url).netloc | 
					
						
							| 
									
										
										
										
											2024-06-17 15:36:26 +08:00
										 |  |  |         if any(domain.endswith(filtered_domain) for filtered_domain in filter_list): | 
					
						
							| 
									
										
										
										
											2024-06-13 08:14:48 +08:00
										 |  |  |             filtered_results.append(result) | 
					
						
							|  |  |  |     return filtered_results | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-18 05:32:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-06 12:27:46 +08:00
										 |  |  | class SearchResult(BaseModel): | 
					
						
							|  |  |  |     link: str | 
					
						
							|  |  |  |     title: Optional[str] | 
					
						
							|  |  |  |     snippet: Optional[str] |