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

55 lines
1.4 KiB
JavaScript

import Index from "../index.js";
import { IndexOptions } from "../type.js";
export default (async function (data) {
data = data.data;
/** @type Index */
const index = self._index,
args = data.args,
task = data.task;
switch (task) {
case "init":
/** @type IndexOptions */
let options = data.options || {},
filepath = options.config;
if (filepath) {
options = filepath;
// will be replaced after build with the line below because
// there is an issue with closure compiler dynamic import
//options = await import(filepath);
}
const factory = data.factory;
if (factory) {
// export the FlexSearch global payload to "self"
Function("return " + factory)()(self);
/** @type Index */
self._index = new self.FlexSearch.Index(options);
// destroy the exported payload
delete self.FlexSearch;
} else {
self._index = new Index(options);
}
postMessage({ id: data.id });
break;
default:
const id = data.id,
message = index[task].apply(index, args);
postMessage("search" === task ? { id: id, msg: message } : { id: id });
}
});