{"record":{"id":"bf0d287d9c28114a","repo":"OrchardCMS/OrchardCore","slug":"invalid-wildcard-query-matchphrasequeryprovider","errorCode":null,"errorMessage":"Invalid wildcard query","messagePattern":"Invalid wildcard query","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/MatchPhraseQueryProvider.cs","lineNumber":44,"sourceCode":"                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\n        return phraseQuery;\n    }\n}\n","sourceCodeStart":26,"sourceCodeEnd":55,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/MatchPhraseQueryProvider.cs#L26-L55","documentation":"This is the fall-through case of MatchPhraseQueryProvider.CreateQuery. The default branch throws an ArgumentException whose message misleadingly says 'Invalid wildcard query' (a copy-paste from the wildcard provider), but it fires for match_phrase queries whose JSON value is neither a string nor the supported object form.","triggerScenarios":"Calling CreateQuery with a match_phrase query like {\"title\": [\"quick fox\"]} or {\"title\": 42} — any value type other than string or object with \"value\".","commonSituations":"Arrays of phrases supplied as a list; numeric or boolean values unquoted; confusion between the string and object query forms; the wrong error text also misleads debugging.","solutions":["Provide the phrase as a JSON string: {\"title\": \"quick brown fox\"}.","Or use the object form: {\"title\": {\"value\": \"quick brown fox\", \"slop\": 1}}.","Ignore the 'wildcard' wording in the message; fix the match_phrase value shape instead."],"exampleFix":"// before\n{\"title\": [\"quick brown fox\"]}\n// after\n{\"title\": \"quick brown fox\"}","handlingStrategy":"validation","validationCode":"var k = query.Value.ValueKind;\nif (k is not (JsonValueKind.String or JsonValueKind.Object))\n    throw new ArgumentException(\"match_phrase query value must be a string or an object with 'value'\");","typeGuard":"static bool IsMatchPhraseShape(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 match_phrase query: {ex.Message}\"); }","preventionTips":["Note the misleading 'wildcard' message text — it still means a malformed match_phrase value.","Pass phrases as strings; use object form only for slop/analyzer options.","Sanitize client-supplied query JSON before provider dispatch."],"tags":["lucene","match-phrase","misleading-message"],"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"}