1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-09-30 15:18:57 +02:00

worker index basic support export/import

This commit is contained in:
Thomas Wilkerling
2025-03-20 09:42:26 +01:00
parent b0311432fd
commit b2c79cfd0e
45 changed files with 3059 additions and 2281 deletions

View File

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