UNPKG

fumadocs-core

Version:

The React.js library for building a documentation website

75 lines (74 loc) • 2.02 kB
import { t as removeUndefined } from "./remove-undefined-C_sjLeQT.js"; import { getByID, search } from "zbsearch"; // src/search/zbsearch/search/simple.ts async function searchSimple(db, query, params = {}, locale) { return (await search(db, { term: query, tolerance: 1, ...params, boost: { title: 2, ..."boost" in params ? params.boost : void 0 }, where: removeUndefined({ locale: locale ? { eq: locale } : void 0, ...params.where }) })).hits.map((hit) => ({ type: "page", content: hit.document.title, breadcrumbs: hit.document.breadcrumbs, id: hit.document.url, url: hit.document.url })); } // src/search/zbsearch/search/advanced.ts async function searchAdvanced(db, query, tag = [], { mode = "fulltext", limit = 60, ...override } = {}, locale) { if (typeof tag === "string") tag = [tag]; const params = { limit, mode, ...override, where: removeUndefined({ tags: tag.length > 0 ? { containsAll: tag } : void 0, locale: locale ? { eq: locale } : void 0, ...override.where }), groupBy: { properties: ["page_id"], maxResult: 8, ...override.groupBy }, properties: mode === "fulltext" ? ["content"] : ["content", "embeddings"] }; if (query.length > 0) params.term = query; const result = await search(db, params); const list = []; for (const item of result.groups ?? []) { if (list.length >= limit) break; 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, url: page.url }); for (const hit of item.result) { if (list.length >= limit) break; if (hit.document.type === "page") continue; list.push({ id: hit.document.id.toString(), content: hit.document.content, breadcrumbs: hit.document.breadcrumbs, type: hit.document.type, url: hit.document.url, table: hit.document.table }); } } return list; } export { searchSimple as n, searchAdvanced as t };