1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-09-26 05:19:00 +02:00
Files
flexsearch/dist/module-debug/worker/node.js
Thomas Wilkerling 4fe11882ca fix imports
2025-03-17 01:13:36 +01:00

41 lines
1.0 KiB
JavaScript

const { parentPort } = require("worker_threads"),
{ join } = require("path"),
{ Index } = require("../flexsearch.bundle.min.js");
// Test Path
//const { Index } = require("../../dist/flexsearch.bundle.min.js");
let index;
parentPort.on("message", async function (data) {
/** @type Index */
const args = data.args,
task = data.task,
id = data.id;
switch (task) {
case "init":
let options = data.options || {},
filepath = options.config;
// load extern field configuration
if (filepath) {
options = Object.assign({}, options, require(filepath));
delete options.worker;
}
index = new Index(options);
//index.db && await index.db;
parentPort.postMessage({ id: id });
break;
default:
const message = index[task].apply(index, args);
parentPort.postMessage("search" === task ? { id: id, msg: message } : { id: id });
}
});