1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-09-25 12:58:59 +02:00
Files
flexsearch/dist/module-debug/worker/node.js
2025-03-17 01:12:58 +01:00

49 lines
1.9 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", 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 && "/" !== filepath[0] && "\\" !== filepath[0]) {
// current working directory
const dir = process.cwd();
filepath = join(dir, filepath);
}
if (filepath) {
options = require(filepath);
}
// deprecated:
// const encode = options["encode"];
// if(encode && (encode.indexOf("function") === 0)){
// options["encode"] = new Function("return " + encode)();
// }
index = new Index(options);
break;
default:
const message = index[task].apply(index, args);
parentPort.postMessage("search" === task ? { id: id, msg: message } : { id: id });
}
});