From 4336bc20e00088f9fcaa4d06ec0653cb6364b939 Mon Sep 17 00:00:00 2001 From: Scott Cazan Date: Tue, 3 Sep 2024 14:49:35 +0200 Subject: [PATCH] Filter out short searches less then 2 chars, bigger debounce (#2440) --- packages/gitbook/src/components/Search/SearchResults.tsx | 2 +- packages/gitbook/src/components/Search/server-actions.tsx | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/gitbook/src/components/Search/SearchResults.tsx b/packages/gitbook/src/components/Search/SearchResults.tsx index 4f6b8b440..4f8b2ffb8 100644 --- a/packages/gitbook/src/components/Search/SearchResults.tsx +++ b/packages/gitbook/src/components/Search/SearchResults.tsx @@ -98,7 +98,7 @@ export const SearchResults = React.forwardRef(function SearchResults( : searchSpaceContent(spaceId, revisionId, query)); setResults(withAsk ? withQuestionResult(fetchedResults, query) : fetchedResults); - }, 250); + }, 350); return () => { if (debounceTimeout.current) { diff --git a/packages/gitbook/src/components/Search/server-actions.tsx b/packages/gitbook/src/components/Search/server-actions.tsx index c692cf92f..dfde57992 100644 --- a/packages/gitbook/src/components/Search/server-actions.tsx +++ b/packages/gitbook/src/components/Search/server-actions.tsx @@ -60,6 +60,10 @@ export async function searchSiteContent(args: { const { siteSpaceIds, query, cacheBust } = args; const pointer = getContentPointer(); + if (query.length <= 1) { + return []; + } + if (siteSpaceIds?.length === 0) { // if we have no siteSpaces to search in then we won't find anything. skip the call. return [];