UNPKG

fumadocs-core

Version:

The React.js library for building a documentation website

51 lines (49 loc) 1.47 kB
import { n as searchSimple, t as searchAdvanced } from "./advanced-BRT5Ij43.js"; import { create, load } from "@orama/orama"; //#region src/search/client/static.ts const cache = /* @__PURE__ */ new Map(); async function loadDB({ from = "/api/search", initOrama = (locale) => create({ schema: { _: "string" }, language: locale }) }) { const cacheKey = from; const cached = cache.get(cacheKey); if (cached) return cached; async function init() { const res = await fetch(from); if (!res.ok) throw new Error(`failed to fetch exported search indexes from ${from}, make sure the search database is exported and available for client.`); const data = await res.json(); const dbs = /* @__PURE__ */ new Map(); if (data.type === "i18n") { await Promise.all(Object.entries(data.data).map(async ([k, v]) => { const db$1 = await initOrama(k); load(db$1, v); dbs.set(k, { type: v.type, db: db$1 }); })); return dbs; } const db = await initOrama(); load(db, data); dbs.set("", { type: data.type, db }); return dbs; } const result = init(); cache.set(cacheKey, result); return result; } async function search(query, options) { const { tag, locale } = options; const db = (await loadDB(options)).get(locale ?? ""); if (!db) return []; if (db.type === "simple") return searchSimple(db, query); return searchAdvanced(db.db, query, tag); } //#endregion export { search }; //# sourceMappingURL=static-Dq8pA8Ay.js.map