-
Notifications
You must be signed in to change notification settings - Fork 0
/
indexing.ts
96 lines (84 loc) · 2.18 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { MeiliSearch } from "https://esm.sh/meilisearch@0.34.1";
import {
type Event,
type Filter,
Kind,
SimplePool,
} from "npm:nostr-tools@^1.14.0";
import stopwords from "./stopwords-all.json" assert { type: "json" };
import { load } from "std/dotenv/mod.ts";
import { printContents, unindexable } from "./util.ts";
console.log("indexing worker started");
const NOSTR_EVENTS_INDEX = "nostr-events";
const env = await load();
const MEILI_HOST_URL = env["MEILI_HOST_URL"];
const MEILI_ADMIN_API_KEY = env["MEILI_ADMIN_API_KEY"];
const client = new MeiliSearch({
host: MEILI_HOST_URL,
apiKey: MEILI_ADMIN_API_KEY,
});
let stopwordsArr: string[] = [];
for (const [_, value] of Object.entries(stopwords)) {
stopwordsArr = [...stopwordsArr, ...value];
}
const indexes = await client.getIndexes({ limit: 3 });
if (indexes.results.length == 0) {
client.createIndex(NOSTR_EVENTS_INDEX, { primaryKey: "id" });
}
client.index(NOSTR_EVENTS_INDEX).updateSettings({
searchableAttributes: [
"content",
],
displayedAttributes: [
"content",
"created_at",
"id",
"kind",
"pubkey",
"sig",
"tags",
],
filterableAttributes: [
"kind",
],
sortableAttributes: [
"created_at",
],
stopWords: stopwordsArr,
typoTolerance: {
minWordSizeForTypos: {
oneTypo: 5,
twoTypos: 10,
},
},
});
const nostrRelays = [
"wss://nos.lol",
"wss://nostr.mom",
"wss://nostr.wine",
"wss://relay.nostr.com.au",
"wss://relay.shitforce.one/",
"wss://nostr.inosta.cc",
"wss://relay.primal.net",
"wss://relay.damus.io",
"wss://relay.nostr.band",
"wss://eden.nostr.land",
"wss://nostr.milou.lol",
"wss://relay.mostr.pub",
"wss://nostr-pub.wellorder.net",
"wss://atlas.nostr.land",
"wss://relay.snort.social",
];
const filter: Filter = {
// seems the onlyone making sense is kind 0 and 1?
kinds: [0, 1],
// memory usage keeps going larger if a limit is not set, but why??
limit: 200,
};
while (true) {
const pool = new SimplePool();
const evs = await pool.list(nostrRelays, [filter]);
const indexables = evs.filter((ev) => !unindexable(ev));
client.index(NOSTR_EVENTS_INDEX).addDocuments(indexables);
pool.close(nostrRelays);
}