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

44 lines
1.1 KiB
JavaScript

const { parentPort } = require("worker_threads");
const { join } = require("path");
// Test Path
//const { Index } = require("../../dist/flexsearch.bundle.min.js");
const { Index } = require("../flexsearch.bundle.min.js");
let index;
parentPort.on("message", async function(data){
/** @type Index */
const args = data["args"];
const task = data["task"];
const id = data["id"];
switch(task){
case "init":
let options = data["options"] || {};
// load extern field configuration
let filepath = options["config"];
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(
task === "search"
? { "id": id, "msg": message }
: { "id": id }
);
}
});