Tune what the search box returns
When /search-index-{locale}.json is already live but results contain nav or footer noise, a page appears that should be hidden, or relative document weight needs adjusting, the options below tune the index without touching the search client.
Assumptions
- A working Pennington site where
/search-index-en.json(or the default locale code) already returns a JSON array - Pages using
DocSiteFrontMatteror anotherIFrontMatterimplementation (which carries theSearchdefault member) - The default locale code (from
LocalizationOptions) — it is the suffix in the index filename
The DocSiteKitchenSinkExample ships with the DocSite-pinned #main-content selector and a Content/main/hidden.md fixture demonstrating search: false.
Options
Exclude a markdown page with search: false
Add search: false to the page's front matter. The value flows through IFrontMatter.Search into ContentTocItem.ExcludeFromSearch; the index builder skips the page entirely while it continues to render at its URL and appear in the sidebar.
---
title: Internal draft
search: false
---
---
title: Not in search
description: This page is intentionally excluded from the search index.
sectionLabel: authoring
order: 220
search: false
uid: kitchen-sink.main.hidden
---
# Not in search
This page carries `search: false` in its front matter. It still renders
at its URL and still appears in the sidebar, but the search index
JSON does **not** contain it. Open `/search-index-en.json` to verify
— this title and body are absent from the `documents` array.
Pair this with `llms: false` on a separate page to carve the opposite
hole in `/llms.txt`.
Exclude a Razor @page with a metadata sidecar
Razor components do not carry YAML front matter, so RazorPageContentService loads a sibling Foo.razor.metadata.yml file. Place the sidecar next to the component; search: false there has the same effect as in a markdown page's front matter.
title: Internal Tools
search: false
/// <summary>True when the page should be included in the search index.</summary>
bool Search => true;
Set the default document priority
SearchIndexOptions.DefaultPriority (default 5) is the baseline weight assigned to every document whose content service does not override IContentService.SearchPriority. Raise it for sources that should outrank neighbours; lower it for auxiliary content. Per-source priority takes precedence: MarkdownContentServiceOptions.SearchPriority defaults to 10, RazorPageContentService is 5, and the llms.txt/SPA/redirect services report 0 so their artifacts never appear in results.
/// <summary>Default priority assigned to indexed documents. Default: 5.</summary>
public int DefaultPriority { get; set; } = 5;
Under AddDocSite this property is reachable via the ConfigurePennington escape hatch (opts.SearchIndex.DefaultPriority = …), so this adjustment does not require dropping down to bare AddPennington.
Override the content selector on DocSite
The selector scopes which HTML element's text becomes the search body. DocSiteOptions.SearchIndexContentSelector defaults to #main-content to match the stock MainLayout.razor; set it after replacing the layout or to widen the indexed region to a different element. See When is DocSite the right starting point? for the cases that require dropping to bare AddPennington.
/// <summary>
/// Override the CSS selector used to scope the search index to a page region.
/// Default is <c>#main-content</c> — the element wrapping the article in the
/// stock DocSite layout. Set to an empty string to index the whole page
/// body, or to a custom selector when you've replaced the layout.
/// </summary>
public string? SearchIndexContentSelector { get; init; }
services.AddDocSite(opts =>
{
opts.SearchIndexContentSelector = "article.prose";
});
Result
/search-index-{locale}.json returns one JSON object per indexed page. A typical entry, after the knobs above are applied:
{
"url": "/how-to/configuration/search/",
"title": "Tune what the search box returns",
"section": "Configuration",
"body": "When /search-index-{locale}.json is already live but results contain nav or footer noise...",
"priority": 10
}
Pages with search: false are absent from the array; per-source SearchPriority values populate the priority field.
Verify
- Run
dotnet runand fetch/search-index-{locale}.json. The excluded page'stitleandurlare absent from thedocumentsarray - Add a second locale and observe one JSON file per locale (
/search-index-en.json,/search-index-fr.json). Registered-but-empty locales return[]instead of 404 - Inspect one
documents[]entry and confirm thebodyfield contains only the scoped element's text (no header / sidebar / footer noise)
Related
- Reference: Front matter key reference
- Reference:
SearchIndexOptions— the knobs this how-to touches; see alsoHighlightingOptions,IslandsOptions,LlmsTxtOptions, andOutputOptions - Background: When is DocSite the right starting point?
- How-to: Make the site discoverable to LLM crawlers