Skip to content

Make API group, type and topic pages searchable - #5036

Closed
akira28 wants to merge 9 commits into
mainfrom
feature/searchable-api-pages
Closed

akira28 wants to merge 9 commits into
mainfrom
feature/searchable-api-pages

Conversation

@akira28

@akira28 akira28 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

API group, type, topic, authentication and Markdown pages now appear in docs search and the API search box. A search for Snapshot and restore or authentication now finds the page itself, not only its operations.

Closes elastic/docs-eng-team#1230

Affects: Search, API reference, MCP

Prompt summary: The author asks for a PR that resolves docs-eng-team#1230. The issue asks whether non-operation API pages should become normal searchable documents, and to index them that way if so.

Why

Since #4983, every non-operation API page has a document in the search index, but only so the sitemap can date it. Those documents are hidden: true and api.sitemap_only: true, and their body is empty. Search, navigation search, the change feed and the MCP tools never return them. The page that answers a reader's query stays invisible.

What

One searchable document per page

OpenApiGenerator.PageContentsAsync reads search text for every page that is not an operation, not the landing page and not excluded from indexing. The text is the rendered title, a plain-text description, the plain-text body and the section headings of the page's Markdown export. OpenApiDocumentExporter.DatedByPage turns that into a visible api.page document with API > <Product> API parents and the product. Each page still has exactly one document with the same content hash, so the sitemap's lastmod dates do not move.

Other pages stay date-only

A page without search text keeps its hidden api.sitemap_only document. That covers operations the exporter skips, such as unreleased ones or aliases of a collapsed operation, and the Servers page. The search filters for sitemap_only stay as they are, so the live index behaves correctly before and after the next indexing run.

Search and MCP

The MCP operation tools (ApiGateway.OperationFilter) exclude api.page documents, just as they exclude landing pages. ApiLookupQueryBuilder keeps these pages out unless every typed word is in their title, the rule it already applies to landing pages. Without it, a type page that lists every property would match most property queries. The indexer skips its second Markdown pass for page bodies, which are plain text already.

Search result rows

The navigation search response carries page, and a row for one of these pages reads "Go to page", not "Go to operation".

Risk: the index mapping gains the api.page field. The next indexing run writes about 570 more documents with a real body, and AI enrichment and semantic inference run on them.

Out of scope: I did not run SearchRelevanceTests against the dev index. Run them before and after to measure how group and type pages compete with operations on short queries.

Verify

./build.sh unit-test
# ExportDocuments_PagesWithoutAnOperation_AreSearchableUnlessExcluded — group, authentication and servers pages
dotnet test --project tests/Elastic.ApiExplorer.Tests --treenode-filter "/*/*/OpenApiGeneratorCatalogSplitTests/*"
mise run site:test

🤖 Generated with Claude Code

These pages had hidden, empty `sitemap_only` documents, so a search for
`Snapshot and restore` or `authentication` returned operations only. Each
page now gets one visible document with plain text, description, headings
and parents read from its Markdown export. The `api.page` flag replaces
`api.sitemap_only`, so operation listings in MCP and the API lookup still
keep these pages out unless every typed word is in their title.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@akira28
akira28 requested a review from a team as a code owner November 24, 2026 14:38
@akira28
akira28 requested a review from technige November 24, 2026 14:38
public async Task ExportDocuments_PagesWithoutAnOperation_AreSearchablePageDocuments()
{
using var versionIndexClient = MainNineAnd8Client();
var generator = MainNineAnd8Generator(versionIndexClient, TwoOperationSpecs("Ping the cluster."));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P3 (Low)

Add a type or topic with a real section heading to this export fixture. The current snapshot contains only two group pages with empty heading lists, so it would still pass if section extraction returned nothing or the exporter omitted type and topic pages entirely.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a8ef92b. The fixture now adds a security scheme (Authentication page), a server (Servers page, sitemap-only) and a group description with a ## Connecting heading. The snapshot shows the extracted heading and the excluded page. The fixture has no type page, because the test spec has no schemas the explorer turns into type pages.

@github-actions

Copy link
Copy Markdown
Contributor

A page left without an operation document can still be an operation: one the
exporter skips as unreleased, or a collapsed operation under an alias URL. The
generator now gives search text only to pages that are not operations, not the
landing page and not excluded from indexing, such as Servers. Every other page
keeps its hidden `sitemap_only` document, so the filters also hold until the
next index run.

The title comes from the rendered heading, the description is plain text
without version-specific links, and the indexer no longer parses a page body
as Markdown a second time. Navigation search now reads `api.page`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A page description can arrive as plain text, where `<ping>` is literal text,
or as Markdown with links into one version tree. Titles and descriptions now
go through a plain-text pass that does not parse HTML, so they keep the
literal text and lose the link targets. The indexer's body choice moves into
`ApplyApiBody`, so a test covers it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
var meta = ApiMarkdownFrontMatter.Collect(body, item, context, page);
var (text, headings) = ApiPagePlainText.Read(body);
// Plain text drops link targets, which point into one version tree and would keep identical trees from collapsing.
return new ApiPageSearchText(ApiPagePlainText.Line(meta.Title), ApiPagePlainText.Line(meta.Description ?? ""), text, headings);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P3 (Low)

Decoding entities in a Markdown heading can make literal placeholders disappear from the search row. A heading such as The &lt;tenant&gt; parameter becomes The <tenant> parameter, but the navigation result renders that string as HTML and strips <tenant> as a tag. Escape literal text when building the highlighted result so the row matches the page heading.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not addressed in this PR. The search highlighter has no server-side escaping, and SanitizedHtmlContent renders the title and description as HTML. So a literal <x> already disappears from operation rows whose spec summary or description contains one. That's a fix in the highlight path for every content type, not only for these pages. I'd rather track it separately than widen this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up in #5038, stacked on this PR: the search result processor now encodes the text around its <mark> tags, so <tenant> shows in the row.

Titles and section headings now come from each heading's own inline content
in the single Markdown parse, so `1. Authentication` keeps its number and a
linked heading keeps only its text. Descriptions reuse the existing SEO
helpers, which drop comments and link targets but keep literal text such as
`<ping>`. This removes the second plain-text pipeline.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
akira28 and others added 2 commits November 24, 2026 16:58
A searchable page document now starts from the sitemap-only document of the
same page and adds its search text, so the two no longer repeat the shared
members. `ApiPagePlainText.Read` returns the search text record directly,
with the fallback title and the plain-text description.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The search title now comes from a top-level H1, as the page renderer picks
it, and a heading keeps inline tags and autolinks as their visible text, so
`Access <tenant>` and `Contact <[email protected]>` index whole. The SEO
plain-text helper no longer reads an underscore inside a word as emphasis,
so `max_docs` keeps its underscore in search and meta descriptions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A heading keeps a literal placeholder such as `<tenant>` but drops comments
and formatting tags, and a page without a top-level H1 takes its nested one,
as the page renderer does. The SEO emphasis patterns treat only letters and
digits as word characters, so `___both___` loses its markers again while
`max_docs` keeps its underscore.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
var document = Markdown.Parse(markdown, Pipeline);
var headings = document.Descendants<HeadingBlock>().ToArray();
// The page renderer prefers a top-level H1 to one nested in a quote or a list, and falls back to the nested one.
var title = FirstTitle(document.OfType<HeadingBlock>()) ?? FirstTitle(headings);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P3 (Low)

The nested fallback can replace the page’s actual title with a later quote heading. For example, if the first H1 is inside a backtick-fenced MyST note and a blockquote contains a second H1, the page renderer sees both but this CommonMark parser sees only the quote’s H1. The API search box then matches against the quote instead of the page title. Use the renderer’s title metadata for authored Markdown pages.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this one. The renderer's title comes from RenderPreservingFirstHeadingWithMetadata, a full MyST parse that validates links and reports diagnostics. Calling it from the search export would re-parse every authored API page and could report the same warnings twice in one build. The case needs an H1 inside a MyST directive and a second H1 in a blockquote on an API Markdown page, which no API docset has today. If it shows up, carrying the renderer's title into ApiPageContent from the HTML render is the better fix than re-parsing here.

A generated page's title is its model's title, literal text such as
`HTTP <code> responses`; only an authored Markdown page reads its H1. A `<br>`
in a heading separates its words, and the SEO plain-text helper keeps code
spans as written while it strips the emphasis around them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment on lines +371 to +374
var text = ApiPagePlainText.Read(body, item.NavigationTitle, ApiMarkdownFrontMatter.Collect(body, item, context, page).Description);
// An authored page shows its H1, which its navigation title may not match. A generated page shows its model's title as
// literal text, which the export writes unescaped, so `HTTP <code> responses` is not read back as Markdown.
return item is SimpleMarkdownNavigationItem ? text : text with { Title = item.NavigationTitle };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P3 (Low)

This fixes only the title of a generated page. The body and headings are still read from the unescaped export through Markdown, so literal text like <code> in a generated title or section heading is still treated as HTML and dropped. The updated snapshot locks in HTTP responses (double space, word missing) as the indexed body, so body and heading matches for those words are lost. To fix this for every field, escape the literal text when the export writes it (ApiCommonMark.Heading), or derive the body from the model text, instead of overriding just Title here.

Generated by Libra. Specialist: libra-complexity. React with 👍 or 👎 to give feedback on this comment.

var text = ApiPagePlainText.Read(body, item.NavigationTitle, ApiMarkdownFrontMatter.Collect(body, item, context, page).Description);
// An authored page shows its H1, which its navigation title may not match. A generated page shows its model's title as
// literal text, which the export writes unescaped, so `HTTP <code> responses` is not read back as Markdown.
return item is SimpleMarkdownNavigationItem ? text : text with { Title = item.NavigationTitle };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P1 (High)

Passing generated titles through verbatim sends HTML that the heading parser previously stripped to the full-search result card, which inserts titles as HTML without sanitizing them. Even the fixture’s literal <code> is interpreted as markup, and spec-supplied HTML attributes can enter the result DOM. Encode title text at the rendering boundary and allow only search-generated highlights as markup.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

An escaped backtick no longer opens a code span in the SEO plain-text helper,
so emphasis between two of them is still stripped. Control characters that
match the slot markers are removed first, so a description that holds them
cannot index past the saved code spans.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

[GeneratedRegex(@"`([^`]+)`", RegexOptions.None, RegexTimeouts.MatchTimeoutMilliseconds)]
// An escaped backtick, `\``, is a literal backtick and never opens a code span.
[GeneratedRegex(@"(?<!\\)`([^`]+)`", RegexOptions.None, RegexTimeouts.MatchTimeoutMilliseconds)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P3 (Low)

The lookbehind treats every backtick preceded by a backslash as escaped. In Markdown, two backslashes escape each other, so the following backtick can still open a code span. Skipping that opener leaves raw backticks in search and SEO descriptions and can strip literal underscores from code identifiers. Check whether the preceding backslash run has odd length, and test both cases.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

@akira28

akira28 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by the stack #5042 → #5043. The review rounds here kept patching how search guessed text from an ambiguous Markdown export. #5042 makes the export unambiguous (literal names escaped, plain-text front matter), and #5043 rebuilds searchable API pages on it with no search-specific plain-text code. The highlight escaping from this thread lives on in #5038.

@akira28 akira28 closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant