{"record":{"id":"6d240d502341f962","repo":"OrchardCMS/OrchardCore","slug":"invalid-wildcard-query","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/Filters/MatchPhraseFilterProvider.cs","lineNumber":49,"sourceCode":"                value = first.Value;\n                break;\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        booleanQuery.Add(phraseQuery, Occur.MUST);\n        var queryFilter = new QueryWrapperFilter(phraseQuery);\n\n        return new FilteredQuery(booleanQuery, queryFilter);\n    }\n}\n","sourceCodeStart":31,"sourceCodeEnd":63,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/Filters/MatchPhraseFilterProvider.cs#L31-L63","documentation":"Despite its message, this throw is MatchPhraseFilterProvider's default switch branch: the match_phrase filter's value was neither a JSON object nor the accepted scalar form. The provider only supports Object (with \"value\"/\"slop\") and the other handled case; anything else hits default and throws ArgumentException(\"Invalid wildcard query\").","triggerScenarios":"Passing a match_phrase filter whose value is a JSON number, boolean, null, or nested array-of-objects — e.g. {\"match_phrase\": {\"Content\": 42}} or {\"match_phrase\": {\"Content\": [{\"a\":1}]}} — so the value kind falls through to the switch default.","commonSituations":"Malformed query JSON pasted from another search engine's DSL; a numeric value intended as slop placed where the phrase belongs; automated query generation emitting the wrong JSON type; copy-paste errors mixing up match_phrase with wildcard filter syntax.","solutions":["Provide the phrase text as a string or as an object with a \"value\" string: {\"match_phrase\": {\"Content\": {\"value\": \"phrase text\"}}}.","Move the slop option into the object form ({\"value\": ..., \"slop\": N}) instead of supplying a bare number.","Validate the value's JsonValueKind (String or Object) before calling CreateFilteredQuery.","If a wildcard query was actually intended, use the correct filter type (wildcard/match filter) rather than match_phrase."],"exampleFix":"// before\n{\"match_phrase\": {\"Content\": 42}}\n// after\n{\"match_phrase\": {\"Content\": {\"value\": \"42\", \"slop\": 0}}}","handlingStrategy":"validation","validationCode":"if (filter.TryGetPropertyValue(field, out var v) &&\n    v.ValueKind is not (JsonValueKind.String or JsonValueKind.Object))\n{\n    throw new InvalidOperationException(\n        $\"match_phrase value for '{field}' must be a string or object, got {v.ValueKind}.\");\n}","typeGuard":"static bool IsValidMatchPhraseValue(JsonElement v) =>\n    v.ValueKind is JsonValueKind.String or JsonValueKind.Object;","tryCatchPattern":"try\n{\n    var query = provider.CreateFilteredQuery(context);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Invalid wildcard\"))\n{\n    _logger.LogError(ex, \"Unsupported match_phrase value kind: {Json}\", filterJson);\n    throw new QueryValidationException(\"match_phrase accepts only string or object values.\", ex);\n}","preventionTips":["Never pass numbers, booleans, or null as a match_phrase value.","Put slop inside the object form, not as the value itself.","Distinguish wildcard queries from match_phrase at query-authoring time."],"tags":["lucene","query-filter","invalid-argument","json"],"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"}