Skip to content

Optimize search results #1279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions _config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,11 @@ site.process([".html"], (pages) => {

const ORAMA_API_KEY = Deno.env.get("ORAMA_CLOUD_API_KEY");
const ORAMA_INDEX_ID = Deno.env.get("ORAMA_CLOUD_INDEX_ID");

if (ORAMA_API_KEY && ORAMA_INDEX_ID) {
site.process([".html"], async (pages) => {
let pageEntries: OramaDocument[] = [];

await oramaClear(ORAMA_API_KEY, ORAMA_INDEX_ID);

for (const page of pages) {
if (
page.document &&
Expand All @@ -228,7 +227,14 @@ if (ORAMA_API_KEY && ORAMA_INDEX_ID) {
}
}

await oramaNotify(ORAMA_API_KEY, ORAMA_INDEX_ID, pageEntries, "pages");
await oramaClear(ORAMA_API_KEY, ORAMA_INDEX_ID);

console.log('Pushing', pageEntries.length, 'pages to Orama');
const chunkSize = 100;
for (let i = 0; i < pageEntries.length; i += chunkSize) {
const chunk = pageEntries.slice(i, i + chunkSize);
await oramaNotify(ORAMA_API_KEY, ORAMA_INDEX_ID, chunk, "pages");
}

await oramaNotify(
ORAMA_API_KEY,
Expand Down
29 changes: 26 additions & 3 deletions orama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface OramaDocument {
content: string;
section: string;
category: string;
headerType: string;
}

export function generateDocumentsForPage(page: Page<Data>): OramaDocument[] {
Expand Down Expand Up @@ -45,9 +46,32 @@ export function generateDocumentsForPage(page: Page<Data>): OramaDocument[] {
category: page.data.url.startsWith("/runtime/")
? "Runtime"
: (page.data.url.startsWith("/deploy/") ? "Deploy" : "Subhosting"),
headerType: header.tagName,
});
}

const allData: OramaDocument[] = []
for (let i = 0; i < documents.length; i++) {
const parents: OramaDocument[] = []
for (let j = 0; j < i; j++) {
const possibleParent = documents[j]
if (possibleParent.headerType < documents[i].headerType) {
parents.push(possibleParent)
}
}

const doc = documents[i]

for (const parent of parents) {
doc[`parent_${parent.headerType}`] = {
section: parent.section,
content: parent.content,
}
}

allData.push(doc)
}

return documents;
}

Expand Down Expand Up @@ -84,9 +108,8 @@ export async function generateDocumentsForSymbols(): Promise<OramaDocument[]> {
.replace(/\.html$/, ""),
title: node.name,
content: node.doc,
section: `API > ${kind}${node.file !== "." ? ` > ${node.file}` : ""}${
node.category ? ` > ${node.category}` : ""
}`,
section: `API > ${kind}${node.file !== "." ? ` > ${node.file}` : ""}${node.category ? ` > ${node.category}` : ""
}`,
category: "Reference",
});
}
Expand Down
12 changes: 12 additions & 0 deletions search.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ document.addEventListener("DOMContentLoaded", () => {
"How to configure?",
"How to deploy?",
];

oramaSearchBox.searchParams = {
boost: {
"content": 100,
"section": 900,
"parent_H2.section": 700,
"title": 1_000,
"parent_H2.content": 1,
"parent_H1.content": 1,
},
properties: ["title", "section", "content", "parent_H2.section", "parent_H2.content"],
}
}

const oramaSearchButton: OramaJSX.OramaSearchButton | null = document
Expand Down