UNPKG

fumadocs-core

Version:

The React.js library for building a documentation website

80 lines (77 loc) 2.23 kB
import { t as createContentHighlighter } from "./search-D6ChCLhY.js"; import { t as removeUndefined } from "./remove-undefined-Cfs4o_mM.js"; import { getByID, search } from "@orama/orama"; //#region src/search/orama/search/simple.ts async function searchSimple(db, query, params = {}) { const highlighter = createContentHighlighter(query); return (await search(db, { term: query, tolerance: 1, ...params, boost: { title: 2, ..."boost" in params ? params.boost : void 0 } })).hits.map((hit) => ({ type: "page", content: hit.document.title, breadcrumbs: hit.document.breadcrumbs, contentWithHighlights: highlighter.highlight(hit.document.title), id: hit.document.url, url: hit.document.url })); } //#endregion //#region src/search/orama/search/advanced.ts async function searchAdvanced(db, query, tag = [], { mode = "fulltext", ...override } = {}) { if (typeof tag === "string") tag = [tag]; let params = { ...override, mode, where: removeUndefined({ tags: tag.length > 0 ? { containsAll: tag } : void 0, ...override.where }), groupBy: { properties: ["page_id"], maxResult: 8, ...override.groupBy } }; if (query.length > 0) params = { ...params, term: query, properties: mode === "fulltext" ? ["content"] : ["content", "embeddings"] }; const highlighter = createContentHighlighter(query); const result = await search(db, params); const list = []; for (const item of result.groups ?? []) { const pageId = item.values[0]; const page = getByID(db, pageId); if (!page) continue; list.push({ id: pageId, type: "page", content: page.content, breadcrumbs: page.breadcrumbs, contentWithHighlights: highlighter.highlight(page.content), url: page.url }); for (const hit of item.result) { if (hit.document.type === "page") continue; list.push({ id: hit.document.id.toString(), content: hit.document.content, breadcrumbs: hit.document.breadcrumbs, contentWithHighlights: highlighter.highlight(hit.document.content), type: hit.document.type, url: hit.document.url }); } } return list; } //#endregion export { searchSimple as n, searchAdvanced as t }; //# sourceMappingURL=advanced-BRT5Ij43.js.map