diff --git a/.gitignore b/.gitignore index 9d6c0e7..a86888c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ dist dist-mirror cache +.env \ No newline at end of file diff --git a/Makefile b/Makefile index c05311e..4d27bfd 100644 --- a/Makefile +++ b/Makefile @@ -23,3 +23,6 @@ build-mirror: event-sync: deno run --unstable --allow-read --allow-write --allow-net utils/eventSync.js $(event) + +search: + deno run --unstable --allow-read --allow-write --allow-net utils/meilisearch.js \ No newline at end of file diff --git a/utils/.env.example b/utils/.env.example new file mode 100644 index 0000000..51fee03 --- /dev/null +++ b/utils/.env.example @@ -0,0 +1 @@ +SEARCH_API_KEY=myapikey \ No newline at end of file diff --git a/utils/config.js b/utils/config.js new file mode 100644 index 0000000..4324c1f --- /dev/null +++ b/utils/config.js @@ -0,0 +1,15 @@ +import { config as dotenv } from "https://deno.land/x/dotenv/mod.ts"; + +export const config = { + colMapper: { + places: "place", + events: "event", + "media-partners": "media-partner", + benefits: "benefit", + unions: "union", + chains: "chain", + "other-events": "event", + }, + searchHost: "https://ms-6adb282327d4-1786.fra.meilisearch.io/", + env: dotenv() +} \ No newline at end of file diff --git a/utils/engine.js b/utils/engine.js index dfdbee5..050308f 100644 --- a/utils/engine.js +++ b/utils/engine.js @@ -10,6 +10,7 @@ import { posix } from "https://deno.land/std@0.173.0/path/mod.ts"; import * as syncTools from "./syncTools.js"; import format from "https://deno.land/x/date_fns@v2.22.1/format/index.js"; import addDays from "https://deno.land/x/date_fns@v2.22.1/addDays/index.ts"; +import { config } from "./config.js"; let _silentMode = false; @@ -103,15 +104,7 @@ class DeConf_Package { this.id = id; this.data = null; this.engine = engine; - this.colMapper = { - places: "place", - events: "event", - "media-partners": "media-partner", - benefits: "benefit", - unions: "union", - chains: "chain", - "other-events": "event", - }; + this.colMapper = config.colMapper; this.collections = Object.keys(this.colMapper); } diff --git a/utils/meilisearch.js b/utils/meilisearch.js new file mode 100644 index 0000000..85caed3 --- /dev/null +++ b/utils/meilisearch.js @@ -0,0 +1,35 @@ +import { MeiliSearch } from 'npm:meilisearch'; +import data from '../dist/23/index.json' assert { type: "json" }; +import { config } from "./config.js"; + +const client = new MeiliSearch({ host: config.searchHost, apiKey: config.env.SEARCH_API_KEY }) + +function addItem (col, arr, x) { + arr.push({ + id: `${col}__${x.id}`, + ident: `${col}__${x.id}`, + name: x.name, + description: x.description || x.desc, + img: x.logo || x.photoUrl || x.photo, + data: x + }) + return arr +} + +const arr = [] +for (const col in config.colMapper) { + console.log(`${col} ..`) + for (const x of data[col]) { + addItem(col, arr, x) + + if (x.speakers) { + for (const speaker of x.speakers) { + addItem("speakers", arr, speaker) + } + } + } +} +console.log(arr) +await client.index("pbw23").deleteAllDocuments() +await client.index("pbw23").addDocuments(arr) +console.log('Done!') \ No newline at end of file