Loading

Getting started

dotnet add package Pagefind.Net
dotnet add package Pagefind.Net.Frontend
		
Install-Package Pagefind.Net
Install-Package Pagefind.Net.Frontend
		
  • Pagefind.Net provides the indexer.
  • Pagefind.Net.Frontend ships the browser query runtime and extracts it automatically on build.

Create a PagefindIndex, add records, and write the output:

using Pagefind.Net;

var index = new PagefindIndex(new PagefindIndexOptions { Language = "en" });

index.AddRecord(new PagefindRecord
{
    Url = "/hello/",
    Title = "Hello World",
    Content = "This is a searchable page about greeting the world.",
    WeightedSegments =
    [
        new WeightedSegment("Hello World", Weight: 7),
        new WeightedSegment("This is a searchable page about greeting the world.", Weight: 1),
    ],
    Meta = new Dictionary<string, string> { ["title"] = "Hello World" },
});

await index.WriteAsync("wwwroot");
		

This writes the following files into wwwroot/pagefind/:

File pattern Purpose
pagefind-entry.json Entry point loaded by pagefind.js
pagefind.{hash}.pf_meta Page metadata (titles, word counts)
index/{hash}.pf_index Inverted index chunks
fragment/{hash}.pf_fragment Content fragments for result excerpts

Weighted segments control how different parts of a document affect search ranking. Higher weights boost terms in headings or keywords.

WeightedSegments =
[
    new WeightedSegment(h1Text, Weight: 7),
    new WeightedSegment(h2Text, Weight: 4),
    new WeightedSegment(bodyText, Weight: 1),
],
		
  1. page title
  2. section headings
  3. body content
Important

Always include a weight-1 segment covering the full body text.

Anchors let search results link directly to a section within a page:

Anchors =
[
    new PagefindAnchor(ElementId: "setup", Text: "Setup", ByteLocation: 0),
    new PagefindAnchor(ElementId: "config", Text: "Configuration", ByteLocation: 142),
],
		
Note

The ByteLocation is the byte offset of the anchor text within Content (UTF-8 encoded).