{"record":{"id":"2d20ca7e8f4edc61","repo":"krisk/Fuse","slug":"fuse-match-does-not-support-usetokensearch-token","errorCode":null,"errorMessage":"Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.","messagePattern":"Fuse\\.match does not support useTokenSearch: token search requires corpus-level statistics \\(df, fieldCount\\) that a one-off string comparison does not have\\. Use new Fuse\\(\\.\\.\\.\\)\\.search\\(\\.\\.\\.\\) instead\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/entry.ts","lineNumber":26,"sourceCode":"import register, {\n  createSearcher,\n  registerObjectCompiler\n} from './core/register'\nimport * as ErrorMsg from './core/errorMessages'\n\nFuse.version = __VERSION__\nFuse.createIndex = createIndex\nFuse.parseIndex = parseIndex\nFuse.config = Config\n\nFuse.match = function (pattern: string, text: string, options?: any) {\n  // Token search needs corpus statistics (df, fieldCount) that a one-off\n  // string comparison can't provide. Reject it here so the contract is the\n  // same in the full and basic builds — without this guard, the full build\n  // crashes with an opaque TypeError and the basic build silently falls back\n  // to fuzzy matching.\n  if (options && options.useTokenSearch) {\n    throw new Error(ErrorMsg.FUSE_MATCH_TOKEN_SEARCH_UNSUPPORTED)\n  }\n  const searcher = createSearcher(pattern, { ...Config, ...options })\n  return searcher.searchIn(text)\n}\n\nif (process.env.NODE_ENV === 'development') {\n  Fuse.parseQuery = parse\n}\n\nif (process.env.EXTENDED_SEARCH_ENABLED) {\n  register(ExtendedSearch)\n  registerObjectCompiler(compileObjectLeaf)\n}\n\nif (process.env.TOKEN_SEARCH_ENABLED) {\n  register(TokenSearch)\n}\n","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/krisk/Fuse/blob/edf2fb608eca0461508d1d71317e6e58309ffada/src/entry.ts#L8-L44","documentation":"Fuse.match is a stateless one-off pattern-vs-string comparison helper. Token search requires corpus-level statistics (df, fieldCount) that a single string comparison cannot provide, so Fuse.match explicitly rejects options containing useTokenSearch. Without this guard the full build would crash with an opaque TypeError and the basic build would silently fall back to fuzzy matching; the supported path for token search is new Fuse(...).search(...).","triggerScenarios":"Calling Fuse.match(pattern, text, options) where options.useTokenSearch is truthy — typically a shared config object that enables token search for the main Fuse instance being reused here.","commonSituations":"Passing shared options/config objects into Fuse.match; switching from instance search to the static helper while unknowingly carrying the flag; legacy code relying on the old silent fuzzy fallback.","solutions":["Remove useTokenSearch from the options passed to Fuse.match (strip the flag from shared configs).","Use new Fuse([{ text }], { keys: ['text'], useTokenSearch: true }).search(pattern) when token search is genuinely needed.","Keep token-search flags only on the instance config and pass a sanitized object to Fuse.match."],"exampleFix":"// before\nFuse.match('world', text, options) // options.useTokenSearch === true\n// after\nconst { useTokenSearch, ...safeOptions } = options\nFuse.match('world', text, safeOptions)\n// or, for token search:\nnew Fuse([{ text }], { keys: ['text'], useTokenSearch: true }).search('world')","handlingStrategy":"validation","validationCode":"if (options && options.useTokenSearch) {\n  throw new Error('useTokenSearch is unsupported in Fuse.match; use new Fuse(...).search(...)')\n}\nFuse.match(pattern, text, options)","typeGuard":"const isMatchSafeOptions = (o) => !o || o.useTokenSearch !== true","tryCatchPattern":"try {\n  return Fuse.match(pattern, text, options)\n} catch (e) {\n  if (e.message.includes('useTokenSearch')) {\n    const { useTokenSearch, ...safe } = options || {}\n    return Fuse.match(pattern, text, safe)\n  }\n  throw e\n}","preventionTips":["Strip feature flags from shared options before passing them to static helpers.","Reserve useTokenSearch for instance-based search only.","Document which options apply to static helpers vs instances."],"tags":["api-misuse","token-search","unsupported-option"],"backgroundTag":"unsupported-option-combination","analyzedSha":"edf2fb608eca0461508d1d71317e6e58309ffada","analyzedAt":"2026-09-02T02:46:54.623Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}