{"record":{"id":"2d828886ddb16a46","repo":"OrchardCMS/OrchardCore","slug":"invalid-query-matchqueryprovider","errorCode":null,"errorMessage":"Invalid query","messagePattern":"Invalid query","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/MatchQueryProvider.cs","lineNumber":65,"sourceCode":"\n                if (terms.Count == 0)\n                {\n                    if (obj.TryGetPropertyValue(\"zero_terms_query\", out var zeroTermsQuery))\n                    {\n                        if (zeroTermsQuery.ToString() == \"all\")\n                        {\n                            return new MatchAllDocsQuery();\n                        }\n                    }\n                }\n\n                foreach (var term in terms)\n                {\n                    boolQuery.Add(new TermQuery(new Term(first.Key, term)), occur);\n                }\n\n                return boolQuery;\n            default: throw new ArgumentException(\"Invalid query\");\n        }\n    }\n}\n","sourceCodeStart":47,"sourceCodeEnd":69,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/MatchQueryProvider.cs#L47-L69","documentation":"This is the fall-through case of MatchQueryProvider.CreateQuery: the field's JSON value is not one of the supported shapes (string or the recognized object/array forms), so the provider cannot build a match query and throws a generic ArgumentException('Invalid query').","triggerScenarios":"Calling CreateQuery with a match query whose value is an unsupported JSON kind — e.g. a boolean, number, or null like {\"title\": true} or {\"title\": null} instead of a string or the supported object form.","commonSituations":"Unquoted booleans/numbers in hand-written query JSON; null values from unbound template variables; client serializers emitting typed values instead of strings.","solutions":["Provide the search text as a JSON string: {\"title\": \"quick\"}.","If using the object form, ensure it matches the provider's expected keys (e.g. \"value\", \"minimum_should_match\").","Coerce non-string scalars to strings client-side before building the query."],"exampleFix":"// before\n{\"published\": true}\n// after\n{\"published\": \"true\"}","handlingStrategy":"validation","validationCode":"var k = query.Value.ValueKind;\nif (k is not (JsonValueKind.String or JsonValueKind.Object))\n    throw new ArgumentException(\"match query value must be a string or a supported object\");","typeGuard":"static bool IsMatchShape(JsonElement el) =>\n    el.ValueKind == JsonValueKind.String || el.ValueKind == JsonValueKind.Object;","tryCatchPattern":"try { var query = provider.CreateQuery(context, queryJson); }\ncatch (ArgumentException ex) when (ex.Message == \"Invalid query\")\n{ return BadRequest(\"Unsupported match query value shape; expected a string or object.\"); }","preventionTips":["Quote all scalars as strings in match query JSON.","Never serialize null/unbound template variables into query values.","Keep a schema of allowed match-query shapes and validate against it."],"tags":["lucene","match-query","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"}