/** * @fileoverview Search result formatting utilities for Pagefind. * These functions transform raw Pagefind API responses into display-ready format. * @see https://pagefind.app/docs/api/ */ import type { PagefindSearchFragment, FormattedSearchResult } from './types.js'; /** * Formats raw Pagefind search results for display in the UI. * * This function performs four key transformations: * * 1. **Sort by `balance_score`**: Sorts weighted_locations by their `balance_score` (descending), * then by `weight` (descending), then position (ascending) as a tie-breaker. * This prioritizes matches by their scores first, then * higher-weighted sections (e.g., headings) over body text, then finally their position on the page * * 2. **Pick Top Sub-Results**: Iterates through sorted locations and finds * which sub-results (headings) contain those locations. If multiple * sub-results contain the same location, keeps the one with more context * (more locations). Stops after collecting `count` results. * * 3. **Re-sort by Document Order**: Resorts the selected sub-results by their * position in the document, so they appear in natural reading order. * * 4. **Deduplicate**: Removes duplicate titles that may arise from overlapping matches. * * @param result - Raw Pagefind result from `pagefind.search().results[i].data()` * @param count - Maximum number of sub-results to return per page (default: 1) * @returns Array of formatted results ready for display * @see https://pagefind.app/docs/api-reference * @see https://pagefind.app/docs/ranking/ * @see https://pagefind.app/docs/sub-results/ * * @example * ```typescript * const search = await pagefind.search("installation"); * const results = await Promise.all(search.results.map(r => r.data())); * const formatted = results.flatMap(r => formatPagefindResult(r, 2)); * // Returns up to 2 sub-results per page, sorted by relevance * ``` */ export declare function formatPagefindResult(result: PagefindSearchFragment, count?: number): FormattedSearchResult[]; //# sourceMappingURL=searchUtils.d.ts.map