Add keyword length limit to search function to prevent search overload
This commit is contained in:
@@ -11,6 +11,10 @@ export default function handler(req: NextApiRequest, res: NextApiResponse<Respon
|
||||
res.status(200).json([]);
|
||||
return;
|
||||
}
|
||||
if (searchText.length < 10) {
|
||||
res.status(200).json([]);
|
||||
return;
|
||||
}
|
||||
const result: TSearchResultItem[] = SearchIndex.search(searchText).map((item) => ({
|
||||
id: item.id,
|
||||
title: item.title,
|
||||
|
||||
@@ -52,6 +52,10 @@ export default function SearchPage() {
|
||||
toast({ title: "Enter a Keyword", description: "Please enter one keyword at least." });
|
||||
return;
|
||||
}
|
||||
if (searchText.length < 10) {
|
||||
toast({ title: "Keywords too short", description: "Keyword length must be at least 10." });
|
||||
return;
|
||||
}
|
||||
querySearch.refetch();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user