{"record":{"id":"005bb4fb28d72f68","repo":"OrchardCMS/OrchardCore","slug":"missing-value-in-fuzzy-query-fuzzyqueryprovider","errorCode":null,"errorMessage":"Missing value in fuzzy query","messagePattern":"Missing value in fuzzy query","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/FuzzyQueryProvider.cs","lineNumber":30,"sourceCode":"    {\n        if (type != \"fuzzy\")\n        {\n            return null;\n        }\n\n        var first = query.First();\n\n        switch (first.Value.GetValueKind())\n        {\n            case JsonValueKind.String:\n                return new FuzzyQuery(new Term(first.Key, first.Value.ToString()));\n\n            case JsonValueKind.Object:\n                var obj = first.Value.AsObject();\n\n                if (!obj.TryGetPropertyValue(\"value\", out var value))\n                {\n                    throw new ArgumentException(\"Missing value in fuzzy query\");\n                }\n\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","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/FuzzyQueryProvider.cs#L12-L48","documentation":"FuzzyQueryProvider.CreateQuery supports an object form for fuzzy queries that requires a \"value\" property. If the object under the field name has no \"value\" key, the provider cannot build a FuzzyQuery and throws this ArgumentException.","triggerScenarios":"Calling CreateQuery with a filter like {\"title\": {\"fuzziness\": 2}} — an object missing the required \"value\" key.","commonSituations":"Typo'd keys (\"val\", \"term\") in hand-written queries; programmatically built query objects where only tuning options (fuzziness, prefix_length) were set; mixing term and fuzzy query syntaxes.","solutions":["Add the required \"value\" string property: {\"title\": {\"value\": \"werd\", \"fuzziness\": 2}}.","Verify the key is exactly \"value\" (case-sensitive).","Validate the object contains a string \"value\" before calling CreateQuery."],"exampleFix":"// before\n{\"title\": {\"fuzziness\": 2}}\n// after\n{\"title\": {\"value\": \"werd\", \"fuzziness\": 2}}","handlingStrategy":"validation","validationCode":"if (query.Value.ValueKind == JsonValueKind.Object && !query.Value.TryGetProperty(\"value\", out _))\n    throw new ArgumentException(\"fuzzy query object requires a 'value' property\");","typeGuard":"static bool HasFuzzyValue(JsonElement el) =>\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) when (ex.Message.Contains(\"Missing value\"))\n{ return BadRequest(\"Fuzzy query requires { \\\"value\\\": \\\"term\\\" }.\"); }","preventionTips":["Always set \"value\" in object-form fuzzy queries alongside fuzziness/prefix_length.","Use typed DTOs with required members to build query JSON.","Validate required keys before calling CreateQuery."],"tags":["lucene","fuzzy","missing-field"],"backgroundTag":"missing-required-argument","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"}