-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexing.ts
43 lines (40 loc) · 1.06 KB
/
indexing.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { create, insert } from "@orama/orama";
import { persistToFile } from "@orama/plugin-data-persistence/server";
import { getDB } from "@/lib/db/mod.ts";
import { getListPeraturan } from "@/models/peraturan.ts";
import { readTextMd } from "@/utils/fs.ts";
try {
const index = await create({
schema: {
path: "string",
jenis: "string",
tahun: "number",
nomor: "string",
judul: "string",
tanggal: "number",
teks: "string",
} as const,
language: "indonesian",
});
const db = await getDB();
const { hasil } = getListPeraturan(db, { pageSize: 20000 });
for (const p of hasil) {
const md = await readTextMd({
jenis: p.jenis,
tahun: p.tahun,
nomor: p.nomor,
});
await insert(index, {
path: p.path,
jenis: p.namaJenisPanjang,
nomor: p.nomorPanjang,
judul: p.judul,
tahun: p.tahun,
tanggal: p.tanggal_ditetapkan.getTime(),
teks: md ?? "",
});
}
await persistToFile(index, "dpack", "data/index.dpack");
} catch (error) {
console.error(error);
}