import { buildOramaIndex, queryOramaIndex, } from "../../../search/orama-index.ts"; import { buildResult, RESULT_POOL } from "./types.ts"; import type { IndexedDocument, SearchFn } from "./types.ts"; /** * Orama (default): fetch the static `blume-search.json` index, build an * in-memory full-text database in the browser, and query it. Keyless and * available in both dev and the production build. A generous match pool is * pulled so the section pills can count across the whole result set before the * active filter and display limit are applied. `locale` is the site's * `i18n.defaultLocale`, baked into the generated client so non-Latin scripts * (Japanese and Chinese, but equally Cyrillic, Greek, Hebrew, Devanagari…) * get a word-segmenting tokenizer. */ export const createSearch = async (opts: { indexUrl: string; locale?: string; }): Promise => { const response = await fetch(opts.indexUrl); // SAFETY: `blume-search.json` is generated by our own indexer // (`buildSearchDocuments`), which writes exactly this document shape. const documents = (await response.json()) as IndexedDocument[]; const db = await buildOramaIndex(documents, opts.locale); return async (query, options) => { const docs = await queryOramaIndex(db, query, RESULT_POOL, { locale: options?.locale, version: options?.version, }); return buildResult(docs, query, options?.section); }; };