{"record":{"id":"74963c1213abb67a","repo":"OrchardCMS/OrchardCore","slug":"invalid-prefix-query","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/Filters/PrefixFilterProvider.cs","lineNumber":55,"sourceCode":"                {\n                    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                break;\n            default: throw new ArgumentException(\"Invalid prefix query\");\n        }\n\n        booleanQuery.Add(prefixQuery, Occur.MUST);\n        var queryFilter = new QueryWrapperFilter(prefixQuery);\n\n        return new FilteredQuery(booleanQuery, queryFilter);\n    }\n}\n","sourceCodeStart":37,"sourceCodeEnd":64,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/Filters/PrefixFilterProvider.cs#L37-L64","documentation":"This is PrefixFilterProvider.CreateFilteredQuery's default switch branch. The prefix filter's value was neither an object (with a \"prefix\" property) nor the other handled value kind, so no PrefixQuery could be built and the provider throws ArgumentException(\"Invalid prefix query\").","triggerScenarios":"Passing {\"prefix\": {\"Title\": 123}} or {\"prefix\": {\"Title\": true}} or {\"prefix\": {\"Title\": null}} — a scalar/null value where an object (or the accepted simple form) is expected, causing the value-kind switch to fall to default.","commonSituations":"Query JSON generated by code that serializes numbers/booleans as-is; copying a wildcard-style filter definition into a prefix filter; a saved query written against an older syntax that no longer parses in the current Orchard Core version.","solutions":["Wrap the prefix in an object: {\"prefix\": {\"Title\": {\"prefix\": \"Orch\"}}}.","Ensure the value's JSON kind is one the provider handles (object with \"prefix\", or string) before calling CreateFilteredQuery.","Search saved queries/recipes for prefix filters with non-object values and fix them.","Log the raw filter JSON in a try/catch around CreateFilteredQuery to find the malformed node."],"exampleFix":"// before\n{\"prefix\": {\"Title\": 123}}\n// after\n{\"prefix\": {\"Title\": {\"prefix\": \"123\"}}}","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        $\"prefix value for '{field}' must be a string or object, got {v.ValueKind}.\");\n}","typeGuard":"static bool IsValidPrefixValue(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 prefix\"))\n{\n    _logger.LogError(ex, \"Unsupported prefix value kind: {Json}\", filterJson);\n    throw new QueryValidationException(\"prefix filters require string or object values.\", ex);\n}","preventionTips":["Pass the prefix as an object {\"prefix\": ...} or a plain string, never a number/bool/null.","Audit saved queries for prefix filters with scalar values after version upgrades.","Build filter JSON through typed helpers instead of string concatenation."],"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"}