import React, { useState } from 'react'; import { Search as SearchIcon, ExternalLink, FileText, Loader2 } from 'lucide-react'; import api from '../services/api'; import AlgorithmCard from '../components/AlgorithmCard'; interface SearchResult { algorithm: string; name: string; category: string; description: string; count: number; sampleIds: string[]; } interface SearchResponse { problem: string; totalAlgorithms: number; results: SearchResult[]; allResults: SearchResult[]; } const Search: React.FC = () => { const [problem, setProblem] = useState(''); const [results, setResults] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const handleSearch = async (e: React.FormEvent) => { e.preventDefault(); if (!problem.trim()) return; try { setLoading(true); setError(null); const response = await api.post('/search/problem', { problem: problem.trim() }); setResults(response.data); } catch (err) { setError('Failed to search for algorithms. Please try again.'); } finally { setLoading(false); } }; const handleSeeMorePapers = async (algorithm: string) => { try { const response = await api.get('/search/pubmed-link', { params: { problem, algorithm } }); window.open(response.data.url, '_blank'); } catch (err) { console.error('Failed to generate PubMed link:', err); } }; return (

Algorithm Search

Search for AI algorithms used in specific medical problems

setProblem(e.target.value)} placeholder="e.g., breast cancer detection, diabetes prediction, alzheimer's disease" className="w-full px-4 py-3 pl-10 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500" disabled={loading} />
{error && (

{error}

)} {results && (

Results for "{results.problem}"

Found {results.results.length} algorithms with published research

{results.results.length > 0 ? (
{results.results.map((result) => ( ))}
) : (

No Results Found

No algorithms found for this medical problem. Try searching with different terms.

)} {results.allResults.some(r => r.count === 0) && (

Algorithms with No Results

{results.allResults .filter(r => r.count === 0) .map(result => ( {result.name} ))}
)}
)}
); }; export default Search;