{"record":{"id":"61dbe3a1697b9ca8","repo":"OrchardCMS/OrchardCore","slug":"missing-value-in-match-phrase-query-matchphrasequeryprovider","errorCode":null,"errorMessage":"Missing value in match phrase query","messagePattern":"Missing value in match phrase query","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/MatchPhraseQueryProvider.cs","lineNumber":33,"sourceCode":"        }\n\n        var first = query.First();\n\n        var phraseQuery = new PhraseQuery();\n        JsonNode value;\n\n        switch (first.Value.GetValueKind())\n        {\n            case JsonValueKind.String:\n                value = first.Value;\n                break;\n\n            case JsonValueKind.Object:\n                var obj = first.Value.AsObject();\n\n                if (!obj.TryGetPropertyValue(\"value\", out value))\n                {\n                    throw new ArgumentException(\"Missing value in match phrase query\");\n                }\n\n                // TODO: read \"analyzer\" property\n\n                if (obj.TryGetPropertyValue(\"slop\", out var slop))\n                {\n                    phraseQuery.Slop = slop.Value<int>();\n                }\n\n                break;\n            default: throw new ArgumentException(\"Invalid wildcard query\");\n        }\n\n        foreach (var term in LuceneQueryService.Tokenize(first.Key, value.Value<string>(), context.DefaultAnalyzer))\n        {\n            phraseQuery.Add(new Term(first.Key, term));\n        }\n","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/MatchPhraseQueryProvider.cs#L15-L51","documentation":"MatchPhraseQueryProvider.CreateQuery supports an object form for match_phrase queries that requires a \"value\" property. If the object under the field name lacks \"value\", no phrase can be tokenized and the provider throws this ArgumentException.","triggerScenarios":"Calling CreateQuery with a query like {\"title\": {\"slop\": 2}} — an object missing the required \"value\" key.","commonSituations":"Hand-written query JSON with typos in the value key; programmatically built queries that set only options like slop or analyzer; template rendering that dropped the value.","solutions":["Add the required \"value\" string property: {\"title\": {\"value\": \"quick fox\", \"slop\": 2}}.","Check for key typos (exactly \"value\").","Validate the object contains a non-empty string \"value\" before calling CreateQuery."],"exampleFix":"// before\n{\"title\": {\"slop\": 2}}\n// after\n{\"title\": {\"value\": \"quick brown fox\", \"slop\": 2}}","handlingStrategy":"validation","validationCode":"if (query.Value.ValueKind == JsonValueKind.Object && !query.Value.TryGetProperty(\"value\", out _))\n    throw new ArgumentException(\"match_phrase query object requires a 'value' property\");","typeGuard":"static bool HasPhraseValue(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(\"Match phrase query requires { \\\"value\\\": \\\"phrase text\\\" }.\"); }","preventionTips":["Always include \"value\" in object-form match_phrase queries.","Use constants for query keys to avoid typos like \"val\".","Validate required fields before submitting queries from client UIs."],"tags":["lucene","match-phrase","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"}