fumadocs-core
Version:
The React.js library for building a documentation website
84 lines (82 loc) • 2.14 kB
JavaScript
import { t as createContentHighlighter } from "./search-D6ChCLhY.js";
import { t as removeUndefined } from "./remove-undefined-Cfs4o_mM.js";
//#region src/search/client/orama-cloud.ts
async function searchDocs(query, options) {
const highlighter = createContentHighlighter(query);
const list = [];
const { index = "default", client, params: extraParams, tag } = options;
if (index === "crawler") {
const result$1 = await client.search({
datasources: [],
...extraParams,
term: query,
where: {
category: tag ? { eq: tag.slice(0, 1).toUpperCase() + tag.slice(1) } : void 0,
...extraParams?.where
},
limit: 10
});
if (!result$1) return list;
for (const hit of result$1.hits) {
const doc = hit.document;
list.push({
id: hit.id,
type: "page",
content: doc.title,
contentWithHighlights: highlighter.highlight(doc.title),
url: doc.path
}, {
id: "page" + hit.id,
type: "text",
content: doc.content,
contentWithHighlights: highlighter.highlight(doc.content),
url: doc.path
});
}
return list;
}
const params = {
datasources: [],
...extraParams,
term: query,
where: removeUndefined({
tag,
...extraParams?.where
}),
groupBy: {
properties: ["page_id"],
max_results: 7,
...extraParams?.groupBy
}
};
const result = await client.search(params);
if (!result || !result.groups) return list;
for (const item of result.groups) {
let addedHead = false;
for (const hit of item.result) {
const doc = hit.document;
if (!addedHead) {
list.push({
id: doc.page_id,
type: "page",
content: doc.title,
breadcrumbs: doc.breadcrumbs,
contentWithHighlights: highlighter.highlight(doc.title),
url: doc.url
});
addedHead = true;
}
list.push({
id: doc.id,
content: doc.content,
contentWithHighlights: highlighter.highlight(doc.content),
type: doc.content === doc.section ? "heading" : "text",
url: doc.section_id ? `${doc.url}#${doc.section_id}` : doc.url
});
}
}
return list;
}
//#endregion
export { searchDocs };
//# sourceMappingURL=orama-cloud-DH3g37zc.js.map