-
Notifications
You must be signed in to change notification settings - Fork 370
Expand file tree
/
Copy pathgenerate.ts
More file actions
56 lines (44 loc) · 1.61 KB
/
Copy pathgenerate.ts
File metadata and controls
56 lines (44 loc) · 1.61 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
import type { OramaDocument } from "./types.ts";
import { FileSelector } from "./identification/FileSelector.ts";
import { MarkdownIndexer } from "./indexing/MarkdownIndexer.ts";
import { NullIndexer } from "./indexing/NullIndexer.ts";
import { IndexCollection } from "./indexing/IndexCollection.ts";
import { OramaJsonOutput } from "./outputs/OramaJsonOutput.ts";
import { MinimalIndexJsonOutput } from "./outputs/MinimalIndexJsonOutput.ts";
const args = Deno.args;
const outputDir = args.length > 0 ? args[0] : undefined;
const inputs = [
new FileSelector(),
];
const indexers = [
new MarkdownIndexer(),
new NullIndexer(),
];
const outputs = [
new OramaJsonOutput(outputDir),
new MinimalIndexJsonOutput(outputDir),
];
const index = new IndexCollection();
for (const input of inputs) {
const filePromises: Promise<OramaDocument | null>[] = [];
for await (const file of input.selectInputFiles("./")) {
const match = indexers.find((i) => i.isValidIndexer(file));
const indexer = match || new NullIndexer();
filePromises.push(indexer.tryIndex(file));
}
const documents = await Promise.all(filePromises);
for (const document of documents) {
index.addDocument(document);
}
}
console.log(index.stats);
for (const output of outputs) {
await output.write(index);
}
console.log("\nNext steps:");
console.log("1. Upload the orama-index.json file to your Orama Cloud index");
console.log("2. Or use the Orama REST API to bulk insert the documents");
console.log(
"3. Configure your search client with the proper endpoint and API key",
);
console.log("\nDone!");