{"record":{"id":"876ff3fa46f9b036","repo":"krisk/Fuse","slug":"logical-search-is-not-available","errorCode":null,"errorMessage":"Logical search is not available","messagePattern":"Logical search is not available","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/index.ts","lineNumber":361,"sourceCode":"\n          if (heap) {\n            result.score = computeScoreSingle(result.matches, {\n              ignoreFieldNorm\n            })\n            heap.insert(result)\n          } else {\n            results!.push(result)\n          }\n        }\n      }\n    })\n\n    return results\n  }\n\n  _searchLogical(query: Expression): InternalResult[] {\n    if (!process.env.LOGICAL_SEARCH_ENABLED) {\n      throw new Error(ErrorMsg.LOGICAL_SEARCH_UNAVAILABLE)\n    }\n\n    const expression = parse(query, this.options)\n\n    // Keyless leaves fan out across all keys; normalised weights keep their\n    // scores consistent with string and keyed queries.\n    const keys = this._normalizedKeys()\n\n    const evaluate = (\n      node: ParsedNode,\n      item: any,\n      idx: number\n    ): InternalResult[] => {\n      if (!('children' in node)) {\n        const { keyId, searcher } = node as ParsedLeaf\n\n        let matches: MatchScore[]\n","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/krisk/Fuse/blob/edf2fb608eca0461508d1d71317e6e58309ffada/src/core/index.ts#L343-L379","documentation":"Logical search ($and/$or object query expressions) is gated behind the LOGICAL_SEARCH_ENABLED environment variable. When Fuse.search receives an object query and the env var is unset, _searchLogical throws immediately instead of parsing the expression. This lets builds ship without the logical-parser code.","triggerScenarios":"fuse.search({ $and: [...], $or: [...] }) or any object query routed to _searchLogical while process.env.LOGICAL_SEARCH_ENABLED is unset or falsy at search time.","commonSituations":"Adopting logical queries after upgrading without knowing about the env gate; the flag set locally but missing in deployed/serverless environments.","solutions":["Set process.env.LOGICAL_SEARCH_ENABLED to a truthy value before calling search with an object query.","Rewrite the query as a plain string pattern if logical operators are not needed.","Load dotenv or platform env config early so the flag is present in all environments."],"exampleFix":"// before\nfuse.search({ $and: [{ title: 'old' }, { title: 'world' }] })\n// after\nprocess.env.LOGICAL_SEARCH_ENABLED = '1'\nfuse.search({ $and: [{ title: 'old' }, { title: 'world' }] })","handlingStrategy":"validation","validationCode":"if (typeof query === 'object' && !process.env.LOGICAL_SEARCH_ENABLED) {\n  throw new Error('Set LOGICAL_SEARCH_ENABLED to use logical (object) queries')\n}\nreturn fuse.search(query)","typeGuard":"const logicalSearchReady = () => Boolean(process.env.LOGICAL_SEARCH_ENABLED)","tryCatchPattern":"try {\n  return fuse.search(query)\n} catch (e) {\n  if (e.message === 'Logical search is not available') {\n    process.env.LOGICAL_SEARCH_ENABLED = '1'\n    return fuse.search(query)\n  }\n  throw e\n}","preventionTips":["Set LOGICAL_SEARCH_ENABLED in every environment serving search requests.","Only pass object queries once the flag is confirmed present.","Load env config before registering any search route."],"tags":["configuration","environment-variable","logical-search"],"backgroundTag":"missing-env-var","analyzedSha":"edf2fb608eca0461508d1d71317e6e58309ffada","analyzedAt":"2026-09-02T02:46:54.623Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}