Meilisearch integration
This commit is contained in:
rodič
0154b061ea
revize
47fd72a466
|
@ -2,3 +2,4 @@
|
|||
dist
|
||||
dist-mirror
|
||||
cache
|
||||
.env
|
3
Makefile
3
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
|
|
@ -0,0 +1 @@
|
|||
SEARCH_API_KEY=myapikey
|
|
@ -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()
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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!')
|
Načítá se…
Odkázat v novém úkolu