{"record":{"id":"af624100ecd09183","repo":"OrchardCMS/OrchardCore","slug":"invalid-prefix-query-prefixqueryprovider","errorCode":null,"errorMessage":"Invalid prefix query","messagePattern":"Invalid prefix query","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/PrefixQueryProvider.cs","lineNumber":50,"sourceCode":"                    prefixQuery = new PrefixQuery(new Term(first.Key, value.Value<string>()));\n                }\n                else if (obj.TryGetPropertyValue(\"prefix\", out var prefix))\n                {\n                    prefixQuery = new PrefixQuery(new Term(first.Key, prefix.Value<string>()));\n                }\n                else\n                {\n                    throw new ArgumentException(\"Prefix query misses prefix value\");\n                }\n\n                if (obj.TryGetPropertyValue(\"boost\", out var boost))\n                {\n                    prefixQuery.Boost = boost.Value<float>();\n                }\n\n                return prefixQuery;\n\n            default: throw new ArgumentException(\"Invalid prefix query\");\n        }\n    }\n}\n","sourceCodeStart":32,"sourceCodeEnd":54,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/PrefixQueryProvider.cs#L32-L54","documentation":"PrefixQueryProvider.CreateQuery dispatches on the JSON value kind of the query node. A prefix query must be expressed as a JSON object; any other kind (string, number, array, etc.) reaches the switch's default case and throws ArgumentException. This guards against malformed query documents.","triggerScenarios":"Passing a query node whose value kind is not JsonValueKind.Object, e.g. {\"field\": \"abc\"} or {\"field\": [\"a\"]} where a prefix-query object is expected.","commonSituations":"Queries built programmatically with the wrong shape; JSON where the type discriminator object was accidentally flattened to a plain value; copy-paste errors in recipe files.","solutions":["Wrap the query spec in a JSON object: {\"field\": {\"type\": \"prefix\", \"prefix\": \"value\"}}.","Check the code path producing the query JSON and ensure it emits an object for prefix queries.","Log/inspect the incoming query JSON to find which field node has the wrong shape."],"exampleFix":"// before\n{\"Title\": \"Orch\"}\n// after\n{\"Title\": {\"type\": \"prefix\", \"prefix\": \"Orch\"}}","handlingStrategy":"type-guard","validationCode":"if (node?.GetValueKind() == JsonValueKind.Object) { /* safe to call */ }","typeGuard":"static bool IsPrefixQueryObject(JsonNode node) => node is JsonObject o && o.TryGetPropertyValue(\"type\", out var t) && t.GetValueKind() == JsonValueKind.String && t.GetValue<string>() == \"prefix\";","tryCatchPattern":"try { var q = provider.CreateQuery(node); } catch (ArgumentException ex) when (ex.Message == \"Invalid prefix query\") { // log the raw node JSON for diagnosis }","preventionTips":["Wrap every query spec in an object with a \"type\" discriminator.","Never flatten query specs to plain JSON values.","Round-trip test generated query JSON through the provider in unit tests."],"tags":["lucene","query-validation","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-16T04:17:20.429Z"}