From 7fdc751391ba371eb103be473e37f863629f2e8f Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 19 Aug 2026 21:38:16 -0600 Subject: [PATCH 1/2] docs: scope site search to the reader's language Every record in the DocSearch index already carries a lang facet and every built page already emits , but the search box never filtered on it, so one query searched all languages at once. The effect is worst on common terms. Searching "jira" returned the same page in Japanese, French, Spanish, German and English as the top five results, so five of the first six slots were copies of one page in languages the reader cannot read. Adding a language filter at query time gives the reader results in the language they are already browsing. Co-Authored-By: Claude Opus 5 --- docs/assets/js/docsearch.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/assets/js/docsearch.js b/docs/assets/js/docsearch.js index d5d5363a9d7..66f01253b97 100644 --- a/docs/assets/js/docsearch.js +++ b/docs/assets/js/docsearch.js @@ -1,10 +1,17 @@ import docsearch from "@docsearch/js"; +// Scope results to the language of the page the reader is on. Every record in +// the index carries a `lang` facet and every page emits , so without +// this filter an English reader gets German, Spanish, French and Japanese hits +// mixed into every search. docsearch({ container: '#docsearch', appId: '1JP5JYFGFC', indexName: 'DefectDojo Docs', - apiKey: '213cc809a92717cffe6ffbe804d13fd1' + apiKey: '213cc809a92717cffe6ffbe804d13fd1', + searchParameters: { + facetFilters: ['lang:' + (document.documentElement.lang || 'en')] + } }); const onClick = function () { From bf05cd04b01fd624c4e813677d5c8f0c0f0949ca Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Wed, 19 Aug 2026 21:43:35 -0600 Subject: [PATCH 2/2] docs: stop one page from filling the search results DocSearch groups results by section rather than by page, so a single long page could occupy every slot. Searching "reimport" returned five results that were all subsections of the Reimport page, so the reader saw one page's table of contents instead of the five best pages. Cap the hits from any one page at two, which keeps the useful "page plus best matching section" pair and frees the remaining slots for other pages. Co-Authored-By: Claude Opus 5 --- docs/assets/js/docsearch.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/assets/js/docsearch.js b/docs/assets/js/docsearch.js index 66f01253b97..f13e09d0929 100644 --- a/docs/assets/js/docsearch.js +++ b/docs/assets/js/docsearch.js @@ -1,5 +1,21 @@ import docsearch from "@docsearch/js"; +// Keep at most two hits from any one page. DocSearch groups results by section +// rather than by page, so a single long page can fill every slot: searching +// "reimport" returned five hits that were all subsections of the Reimport page, +// crowding out every other page in the docs. +const MAX_HITS_PER_PAGE = 2; + +function limitHitsPerPage(items) { + const seen = new Map(); + return items.filter(function (item) { + const page = item.url_without_anchor || item.url; + const n = (seen.get(page) || 0) + 1; + seen.set(page, n); + return n <= MAX_HITS_PER_PAGE; + }); +} + // Scope results to the language of the page the reader is on. Every record in // the index carries a `lang` facet and every page emits , so without // this filter an English reader gets German, Spanish, French and Japanese hits @@ -11,7 +27,8 @@ docsearch({ apiKey: '213cc809a92717cffe6ffbe804d13fd1', searchParameters: { facetFilters: ['lang:' + (document.documentElement.lang || 'en')] - } + }, + transformItems: limitHitsPerPage }); const onClick = function () {