Open vincesp opened 1 year ago
const indexWorker = new Worker({ tokenize: 'full', worker: '/flexsearch/worker/worker.js', encode: (str) => str.toLowerCase().split(/[\p{Z}\p{S}\p{P}\p{C}]+/u), })
I am using flexsearch in the browser. With above configuration, I get an error:
TypeError: this.encode is not a function at Index.add
encode is converted to a string to post it to the worker. But in the worker, it is not converted back properly.
encode
https://github.com/nextapps-de/flexsearch/blob/master/src/worker/index.js#L25 https://github.com/nextapps-de/flexsearch/blob/master/src/worker/handler.js#L22
This code also would not work:
const indexWorker = new Worker({ tokenize: 'full', worker: '/flexsearch/worker/worker.js', encode(str) { return str.toLowerCase().split(/[\p{Z}\p{S}\p{P}\p{C}]+/u) }, })
To make the code work, it has to be changed to:
const indexWorker = new Worker({ tokenize: 'full', worker: '/flexsearch/worker/worker.js', encode: function (str) { return str.toLowerCase().split(/[\p{Z}\p{S}\p{P}\p{C}]+/u) }, })
Proposal: make the code in worker/handler.js more robust so that it can handle any kind of function passed into encode.
I am using flexsearch in the browser. With above configuration, I get an error:
encode
is converted to a string to post it to the worker. But in the worker, it is not converted back properly.https://github.com/nextapps-de/flexsearch/blob/master/src/worker/index.js#L25 https://github.com/nextapps-de/flexsearch/blob/master/src/worker/handler.js#L22
This code also would not work:
To make the code work, it has to be changed to:
Proposal: make the code in worker/handler.js more robust so that it can handle any kind of function passed into
encode
.