{"record":{"id":"c4f191cf2163e905","repo":"OrchardCMS/OrchardCore","slug":"invalid-regexp-query","errorCode":null,"errorMessage":"Invalid regexp query","messagePattern":"Invalid regexp query","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/RegexpQueryProvider.cs","lineNumber":42,"sourceCode":"            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 regexp query\");\n                }\n\n                // TODO: Support flags\n\n                var regexpQuery = new RegexpQuery(new Term(first.Key, value.Value<string>()));\n\n                if (obj.TryGetPropertyValue(\"boost\", out var boost))\n                {\n                    regexpQuery.Boost = boost.Value<float>();\n                }\n\n                return regexpQuery;\n            default: throw new ArgumentException(\"Invalid regexp query\");\n        }\n    }\n}\n","sourceCodeStart":24,"sourceCodeEnd":46,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/RegexpQueryProvider.cs#L24-L46","documentation":"RegexpQueryProvider.CreateQuery dispatches on the JSON value kind; a regexp query must be a JSON object node. Any other value kind falls to the switch default and throws ArgumentException. This mirrors the other Lucene query providers' validation style.","triggerScenarios":"Passing {\"field\": \"pattern\"} or {\"field\": [\"a\", \"b\"]} where an object node with type 'regexp' is required.","commonSituations":"Query builders emitting plain values instead of the discriminated object; copy-paste between term and regexp syntax; corrupted saved queries.","solutions":["Use the object form: {\"field\": {\"type\": \"regexp\", \"value\": \"pattern\"}}.","Inspect the incoming JSON to find the malformed field node.","Fix the query-producing code to wrap regexp specs in objects."],"exampleFix":"// before\n{\"Title\": \"Orch.*\"}\n// after\n{\"Title\": {\"type\": \"regexp\", \"value\": \"Orch.*\"}}","handlingStrategy":"type-guard","validationCode":"if (node?.GetValueKind() == JsonValueKind.Object) { /* safe to call */ }","typeGuard":"static bool IsRegexpQueryObject(JsonNode node) => node is JsonObject o && o.TryGetPropertyValue(\"type\", out var t) && t.GetValueKind() == JsonValueKind.String && t.GetValue<string>() == \"regexp\";","tryCatchPattern":"try { var q = provider.CreateQuery(node); } catch (ArgumentException ex) when (ex.Message == \"Invalid regexp query\") { // inspect and log the offending node }","preventionTips":["Represent regexp queries as objects with a \"type\": \"regexp\" discriminator.","Test serialized queries round-trip through the provider.","Centralize query JSON construction in one validated helper."],"tags":["lucene","regexp-query","invalid-shape"],"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-23T08:17:48.524Z"}