FEAT: Implemented working search bar using FTS and Ranking

This commit is contained in:
white
2025-02-11 16:38:46 +00:00
parent 905e879c60
commit 1a572cc172
5 changed files with 53 additions and 26 deletions

View File

@@ -18,17 +18,28 @@ const SearchBar: React.FC = () => {
// Perform search when debounced query changes
useEffect(() => {
if (debouncedQuery.trim()) {
fetch(`/api/search/${debouncedQuery}`)
.then((response) => response.json())
.then((data) => {
const fetchSearchResults = async () => {
try {
const response = await fetch("/api/search", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ query: debouncedQuery }), // <-- Fixed payload
});
const data = await response.json();
console.log("Search results:", data);
// Handle the search results here
})
.catch((error) => {
} catch (error) {
console.error("Error performing search:", error);
});
}
};
fetchSearchResults(); // Call the async function
}
}, [debouncedQuery]);
const handleSearchChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setSearchQuery(e.target.value);