{"record":{"id":"6f5ae9d4382bebc9","repo":"OrchardCMS/OrchardCore","slug":"invalid-fuzzy-query-fuzzyqueryprovider","errorCode":null,"errorMessage":"Invalid fuzzy query","messagePattern":"Invalid fuzzy query","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/FuzzyQueryProvider.cs","lineNumber":50,"sourceCode":"\n                obj.TryGetPropertyValue(\"fuzziness\", out var fuzziness);\n                obj.TryGetPropertyValue(\"prefix_length\", out var prefixLength);\n                obj.TryGetPropertyValue(\"max_expansions\", out var maxExpansions);\n\n                var fuzzyQuery = new FuzzyQuery(\n                    new Term(first.Key, value.Value<string>()),\n                    fuzziness?.Value<int>() ?? LevenshteinAutomata.MAXIMUM_SUPPORTED_DISTANCE,\n                    prefixLength?.Value<int>() ?? 0,\n                    maxExpansions?.Value<int>() ?? 50,\n                    true);\n\n                if (obj.TryGetPropertyValue(\"boost\", out var boost))\n                {\n                    fuzzyQuery.Boost = boost.Value<float>();\n                }\n\n                return fuzzyQuery;\n            default: throw new ArgumentException(\"Invalid fuzzy query\");\n        }\n    }\n}\n","sourceCodeStart":32,"sourceCodeEnd":54,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/FuzzyQueryProvider.cs#L32-L54","documentation":"This is the fall-through case of FuzzyQueryProvider.CreateQuery: the field's JSON value is neither a scalar string nor the supported object form (e.g. an array, number, or null), so the provider cannot interpret it as a fuzzy query and throws.","triggerScenarios":"Calling CreateQuery with a filter like {\"title\": [\"a\", \"b\"]} or {\"title\": null} — any value shape other than string or object with \"value\".","commonSituations":"Copy-pasted terms-query JSON into a fuzzy query; null values from unbound template variables; arrays of fuzzy terms which the provider does not support.","solutions":["Provide the term as a JSON string: {\"title\": \"werd\"}.","Or use the object form: {\"title\": {\"value\": \"werd\", \"fuzziness\": 2}}.","Guard against null/undefined values reaching the query builder from templates."],"exampleFix":"// before\n{\"title\": [\"werd\"]}\n// after\n{\"title\": {\"value\": \"werd\", \"fuzziness\": 2}}","handlingStrategy":"validation","validationCode":"var k = query.Value.ValueKind;\nif (k is not (JsonValueKind.String or JsonValueKind.Object))\n    throw new ArgumentException(\"fuzzy query value must be a string or an object with 'value'\");","typeGuard":"static bool IsFuzzyShape(JsonElement el) =>\n    el.ValueKind == JsonValueKind.String ||\n    (el.ValueKind == JsonValueKind.Object && el.TryGetProperty(\"value\", out var v) && v.ValueKind == JsonValueKind.String);","tryCatchPattern":"try { var query = provider.CreateQuery(context, queryJson); }\ncatch (ArgumentException ex) { return BadRequest($\"Invalid fuzzy query: {ex.Message}\"); }","preventionTips":["Coerce template variables to strings before building fuzzy queries.","Reject null/undefined values early instead of serializing them into query JSON.","Cover all JSON value kinds in provider unit tests."],"tags":["lucene","fuzzy","query-validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}