From 7e6582cf0be5df74e8f239432db6309929caf1a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chalifour?= Date: Fri, 5 Jun 2020 14:44:55 +0200 Subject: [PATCH] feat(docsearch): display 5 hits per category maximum --- packages/docsearch-react/src/utils/groupBy.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/docsearch-react/src/utils/groupBy.ts b/packages/docsearch-react/src/utils/groupBy.ts index 5ea2731ef..f88374004 100644 --- a/packages/docsearch-react/src/utils/groupBy.ts +++ b/packages/docsearch-react/src/utils/groupBy.ts @@ -9,7 +9,11 @@ export function groupBy( acc[key] = []; } - acc[key].push(item); + // We limit each section to show 5 hits maximum. + // This acts as a frontend alternative to `distinct`. + if (acc[key].length < 5) { + acc[key].push(item); + } return acc; }, {});