RND-11356: remove redundant GBO best-section re-selection (#4375)

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Zeno Kapitein <zeno@gitbook.io>
This commit is contained in:
claude[bot]
2026-07-10 13:25:26 +02:00
committed by GitHub
parent cb92754575
commit a9a52fee72
4 changed files with 12 additions and 17 deletions
@@ -0,0 +1,5 @@
---
"gitbook": patch
---
Remove GBO's redundant re-selection of the best-scoring search section. The search API now returns a single highest-scoring section per page (and orders sections highest-score-first), so GBO no longer needs its own `getBestScoredResult` helper to pick the best section for the search and MCP previews. No user-visible change.
@@ -11,7 +11,6 @@ import { getExposableError, throwIfDataError } from '@/lib/data';
import { fromPageMarkdown, getMarkdownForPageInSpace, toPageMarkdown } from '@/lib/markdownPage';
import { resolvePagePath } from '@/lib/pages';
import { joinPathWithBaseURL } from '@/lib/paths';
import { getBestScoredResult } from '@/lib/search';
import { findSiteSpaceBy, findSiteSpaceByUrl } from '@/lib/sites';
import { trackServerInsightsEvents } from '@/lib/tracking';
import { waitUntil } from '@/lib/waitUntil';
@@ -135,8 +134,10 @@ export async function handleMcpRequest(
)
);
const body = getBestScoredResult(
(pageResult.sections ?? []).filter((section) => section.body)
// The search API returns sections ordered highest-score-first, so
// the first section with a body is the best-scoring preview.
const body = (pageResult.sections ?? []).find(
(section) => section.body
)?.body;
return {
@@ -8,7 +8,6 @@ import { throwIfDataError } from '@/lib/data';
import { toEmbeddableLinkForPublishedContent } from '@/lib/embeddable-linker';
import { getSiteURLDataFromMiddleware } from '@/lib/middleware';
import { joinPathWithBaseURL } from '@/lib/paths';
import { getBestScoredResult } from '@/lib/search';
import { getServerActionBaseContext } from '@/lib/server-actions';
import { findSiteSpaceBy, getLocalizedTitle } from '@/lib/sites';
import type {
@@ -187,8 +186,9 @@ function transformSitePageResult(args: {
};
}) ?? [];
// Find the best-scoring section to use as a body preview on the page result.
const bestSection = getBestScoredResult(pageSections);
// The search API returns each page's sections ordered highest-score-first and caps them at one
// per page, so the first section is the best-scoring one to use as a body preview.
const bestSection = pageSections[0];
if (bestSection) {
page.bestSection = {
href: bestSection.href,
-11
View File
@@ -1,11 +0,0 @@
/**
* Return the highest-scoring item in the list, or undefined when empty.
*/
export function getBestScoredResult<T extends { score: number }>(
items: readonly T[]
): T | undefined {
return items.reduce<T | undefined>(
(best, item) => (best === undefined || item.score > best.score ? item : best),
undefined
);
}