{"record":{"id":"de5ebbc7a5f76332","repo":"krisk/Fuse","slug":"fuseworker-does-not-support-usetokensearch-token","errorCode":null,"errorMessage":"FuseWorker does not support useTokenSearch: token search depends on corpus-level statistics (df, fieldCount) that are computed per shard, so per-shard scores would diverge from single-thread Fuse. Use Fuse on the main thread for token search.","messagePattern":"FuseWorker does not support useTokenSearch: token search depends on corpus-level statistics \\(df, fieldCount\\) that are computed per shard, so per-shard scores would diverge from single-thread Fuse\\. Use Fuse on the main thread for token search\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/workers/FuseWorker.ts","lineNumber":109,"sourceCode":"  private _nextId = 0\n  private _workerUrl: string | URL\n\n  constructor(\n    docs: ReadonlyArray<T>,\n    options?: IFuseOptions<T>,\n    workerOptions?: FuseWorkerOptions\n  ) {\n    this._docs = docs.slice()\n    this._options = options || ({} as IFuseOptions<T>)\n    this._workerOptions = workerOptions || {}\n    // Reject function-valued options eagerly. Without this check, postMessage\n    // throws DataCloneError on first search() rather than at construction.\n    FuseWorker._assertNoFunctionOptions(this._options)\n    // Token search needs global corpus statistics, but each shard would build\n    // its own — scores would diverge from single-thread Fuse. Refuse upfront\n    // rather than silently returning ordering that doesn't match.\n    if (this._options.useTokenSearch) {\n      throw new Error(ErrorMsg.FUSE_WORKER_TOKEN_SEARCH_UNSUPPORTED)\n    }\n    this._workerUrl = this._workerOptions.workerUrl || resolveDefaultWorkerUrl()\n  }\n\n  private static _assertNoFunctionOptions<U>(options: IFuseOptions<U>): void {\n    if (typeof (options as { sortFn?: unknown }).sortFn === 'function') {\n      throw new Error(ErrorMsg.FUSE_WORKER_UNSUPPORTED_FN_OPTION('sortFn'))\n    }\n    if (typeof (options as { getFn?: unknown }).getFn === 'function') {\n      throw new Error(ErrorMsg.FUSE_WORKER_UNSUPPORTED_FN_OPTION('getFn'))\n    }\n    if (typeof (options as { tokenize?: unknown }).tokenize === 'function') {\n      throw new Error(ErrorMsg.FUSE_WORKER_UNSUPPORTED_FN_OPTION('tokenize'))\n    }\n    const keys = options.keys\n    if (Array.isArray(keys)) {\n      for (let i = 0, len = keys.length; i < len; i += 1) {\n        const key = keys[i] as FuseOptionKey<U>","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/krisk/Fuse/blob/edf2fb608eca0461508d1d71317e6e58309ffada/src/workers/FuseWorker.ts#L91-L127","documentation":"Error \"FuseWorker does not support useTokenSearch: token search depends on corpus-level statistics (df, fieldCount) that are computed per shard, so per-shard scores would diverge from single-thread Fuse. Use Fuse on the main thread for token search.\" thrown in krisk/Fuse.","triggerScenarios":"Thrown at src/workers/FuseWorker.ts:109 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not pass useTokenSearch: true when using FuseWorker — omit the option to use the default matched-substring strategy","Run Fuse on the main thread instead of FuseWorker if token search is required for your scoring needs","Split your corpus so token-search queries are handled by a single-threaded Fuse instance while FuseWorker serves the rest"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"edf2fb608eca0461508d1d71317e6e58309ffada","analyzedAt":"2026-09-02T02:46:54.623Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}