Skip to content

Commit c8f1ab5

Browse files
refactor: migrate to new orama infra (#1371)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 95832e2 commit c8f1ab5

File tree

7 files changed

+104
-131
lines changed

7 files changed

+104
-131
lines changed

.github/workflows/orama_sync.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ jobs:
3232
run: pnpm sync:orama
3333
env:
3434
ORAMA_PRIVATE_API_KEY: ${{ secrets.ORAMA_PRIVATE_API_KEY }}
35-
ORAMA_PRIVATE_INDEX_ID: ${{ secrets.ORAMA_PRIVATE_INDEX_ID }}
35+
ORAMA_DATASOURCE_ID: ${{ secrets.ORAMA_DATASOURCE_ID }}
36+
ORAMA_PROJECT_ID: ${{ secrets.ORAMA_PROJECT_ID }}

env.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ interface ImportMeta {
1010

1111
declare namespace NodeJS {
1212
interface ProcessEnv {
13+
readonly ORAMA_PROJECT_ID: string;
14+
readonly ORAMA_DATASOURCE_ID: string;
15+
readonly ORAMA_PUBLIC_API_KEY: string;
1316
readonly ORAMA_PRIVATE_API_KEY: string;
14-
readonly ORAMA_PRIVATE_INDEX_ID: string;
1517
}
1618
}
1719

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"dependencies": {
2020
"@kobalte/core": "^0.13.11",
2121
"@kobalte/solidbase": "^0.2.20",
22-
"@oramacloud/client": "^2.1.4",
22+
"@orama/core": "^1.2.14",
2323
"@solid-primitives/event-listener": "^2.4.3",
2424
"@solid-primitives/marker": "^0.2.2",
2525
"@solid-primitives/media": "^2.3.3",
@@ -62,4 +62,4 @@
6262
"node": ">=24",
6363
"pnpm": ">=10"
6464
}
65-
}
65+
}

pnpm-lock.yaml

Lines changed: 32 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/llms.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@
128128
- [Routing](https://docs.solidjs.com/solid-start/building-your-application/routing)
129129
- [API routes](https://docs.solidjs.com/solid-start/building-your-application/api-routes)
130130
- [CSS and styling](https://docs.solidjs.com/solid-start/building-your-application/css-and-styling)
131-
- [Data loading](https://docs.solidjs.com/solid-start/building-your-application/data-loading)
131+
- [Data fetching](https://docs.solidjs.com/solid-start/building-your-application/data-fetching)
132+
- [Data mutation](https://docs.solidjs.com/solid-start/building-your-application/data-mutation)
132133
- [Head and metadata](https://docs.solidjs.com/solid-start/building-your-application/head-and-metadata)
133134
- [Route Pre-rendering](https://docs.solidjs.com/solid-start/building-your-application/route-prerendering)
134135
- [Static assets](https://docs.solidjs.com/solid-start/building-your-application/static-assets)
@@ -176,6 +177,11 @@
176177
- [Actions](https://docs.solidjs.com/solid-router/concepts/actions)
177178
- [Single page applications](https://docs.solidjs.com/solid-router/rendering-modes/spa)
178179
- [Server side rendering](https://docs.solidjs.com/solid-router/rendering-modes/ssr)
180+
- [Queries](https://docs.solidjs.com/solid-router/data-fetching/queries)
181+
- [Streaming](https://docs.solidjs.com/solid-router/data-fetching/streaming)
182+
- [Revalidation](https://docs.solidjs.com/solid-router/data-fetching/revalidation)
183+
- [Preload data](https://docs.solidjs.com/solid-router/data-fetching/how-to/preload-data)
184+
- [Handle pending and error states](https://docs.solidjs.com/solid-router/data-fetching/how-to/handle-error-and-loading-states)
179185
- [Lazy loading](https://docs.solidjs.com/solid-router/advanced-concepts/lazy-loading)
180186
- [Migration from v0.9.x](https://docs.solidjs.com/solid-router/guides/migration)
181187
- [A](https://docs.solidjs.com/solid-router/reference/components/a)
@@ -193,7 +199,7 @@
193199
- [useAction](https://docs.solidjs.com/solid-router/reference/data-apis/use-action)
194200
- [useSubmission](https://docs.solidjs.com/solid-router/reference/data-apis/use-submission)
195201
- [useSubmissions](https://docs.solidjs.com/solid-router/reference/data-apis/use-submissions)
196-
- [Preload](https://docs.solidjs.com/solid-router/reference/preload-functions/preload)
202+
- [preload](https://docs.solidjs.com/solid-router/reference/preload-functions/preload)
197203
- [useBeforeLeave](https://docs.solidjs.com/solid-router/reference/primitives/use-before-leave)
198204
- [useCurrentMatches](https://docs.solidjs.com/solid-router/reference/primitives/use-current-matches)
199205
- [useIsRouting](https://docs.solidjs.com/solid-router/reference/primitives/use-is-routing)

scripts/sync-orama.mjs

Lines changed: 32 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { readFileSync } from "node:fs";
22
import { globSync } from "glob";
3+
import { OramaCloud } from "@orama/core";
34
import { generalPurposeCrawler } from "@orama/crawly";
45
import "dotenv/config";
56

67
const ORAMA_PRIVATE_API_KEY = process.env.ORAMA_PRIVATE_API_KEY;
7-
const ORAMA_PRIVATE_INDEX_ID = process.env.ORAMA_PRIVATE_INDEX_ID;
8+
const ORAMA_DATASOURCE_ID = process.env.ORAMA_DATASOURCE_ID;
9+
const ORAMA_PROJECT_ID = process.env.ORAMA_PROJECT_ID;
810

911
const baseURL = new URL("../dist", import.meta.url).pathname;
1012
const HTMLFiles = globSync("**/*.html", { cwd: baseURL });
@@ -18,71 +20,41 @@ const pagesToIndex = HTMLFiles.flatMap((file) => {
1820

1921
const productionDocsURL = `https://docs.solidjs.com/${path}`;
2022

21-
return {
22-
...generalPurposeCrawler(productionDocsURL, pageContent, {
23-
parseCodeBlocks: false,
24-
})[0],
25-
contentWithCode: generalPurposeCrawler(productionDocsURL, pageContent)?.[0]
26-
?.content,
27-
};
28-
});
23+
const content = generalPurposeCrawler(productionDocsURL, pageContent, { parseCodeBlocks: false })[0];
24+
const contentWithCode = generalPurposeCrawler(productionDocsURL, pageContent, { parseCodeBlocks: true })[0];
2925

30-
async function emptyIndex() {
31-
await fetch(
32-
`https://api.oramasearch.com/api/v1/webhooks/${ORAMA_PRIVATE_INDEX_ID}/snapshot`,
33-
{
34-
method: "POST",
35-
headers: {
36-
"Content-Type": "application/json",
37-
authorization: `Bearer ${ORAMA_PRIVATE_API_KEY}`,
38-
},
39-
body: JSON.stringify([]),
40-
}
41-
);
42-
}
26+
const fullContent = {
27+
title: content.title,
28+
path: content.path,
29+
content: content.content,
30+
contentWithCode: contentWithCode.content,
31+
}
4332

44-
async function upsertFreshData() {
45-
const batches = [];
46-
const batchesSize = 25;
33+
if (content?.category) {
34+
fullContent.category = `enum('${content.category}')`
35+
}
4736

48-
for (let i = 0; i < pagesToIndex.length; i += batchesSize) {
49-
const batch = pagesToIndex.slice(i, i + batchesSize);
50-
batches.push(batch);
37+
if (content?.section) {
38+
fullContent.section = `enum('${content.section}')`
5139
}
5240

53-
for (let i = 0; i < batches.length; i++) {
54-
const batch = batches[i];
41+
return fullContent
42+
});
5543

56-
await fetch(
57-
`https://api.oramasearch.com/api/v1/webhooks/${ORAMA_PRIVATE_INDEX_ID}/notify`,
58-
{
59-
method: "POST",
60-
headers: {
61-
"Content-Type": "application/json",
62-
authorization: `Bearer ${ORAMA_PRIVATE_API_KEY}`,
63-
},
64-
body: JSON.stringify({
65-
upsert: batch,
66-
}),
67-
}
68-
);
69-
}
70-
}
44+
const orama = new OramaCloud({
45+
apiKey: ORAMA_PRIVATE_API_KEY,
46+
projectId: ORAMA_PROJECT_ID
47+
})
7148

72-
async function deployIndex() {
73-
await fetch(
74-
`https://api.oramasearch.com/api/v1/webhooks/${ORAMA_PRIVATE_INDEX_ID}/deploy`,
75-
{
76-
method: "POST",
77-
headers: {
78-
authorization: `Bearer ${ORAMA_PRIVATE_API_KEY}`,
79-
},
80-
}
81-
);
49+
const index = orama.index.set(ORAMA_DATASOURCE_ID)
50+
51+
console.log(`[Orama] - Indexing ${pagesToIndex.length} documents to Orama...`)
8252

83-
console.log("Index deployed");
84-
}
53+
const tempIndexId = `tempIndex-${Date.now()}`
54+
await index.createTemporaryIndex(tempIndexId)
55+
const tempIdx = orama.index.set(tempIndexId)
56+
await tempIdx.insertDocuments(pagesToIndex)
57+
await index.swapTemporaryIndex(ORAMA_DATASOURCE_ID, tempIndexId)
58+
await orama.index.delete(tempIndexId)
8559

86-
await emptyIndex();
87-
await upsertFreshData();
88-
await deployIndex();
60+
console.log(`[Orama] - Indexed ${pagesToIndex.length} documents to Orama.`)

0 commit comments

Comments
 (0)