{"record":{"id":"95c2d2061614ef61","repo":"OrchardCMS/OrchardCore","slug":"prefix-query-misses-prefix-value","errorCode":null,"errorMessage":"Prefix query misses prefix value","messagePattern":"Prefix query misses prefix value","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/Filters/PrefixFilterProvider.cs","lineNumber":46,"sourceCode":"        switch (first.Value.GetValueKind())\n        {\n            case JsonValueKind.String:\n                prefixQuery = new PrefixQuery(new Term(first.Key, first.Value.ToString()));\n                break;\n            case JsonValueKind.Object:\n                var obj = first.Value.AsObject();\n\n                if (obj.TryGetPropertyValue(\"value\", out var value))\n                {\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":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/Filters/PrefixFilterProvider.cs#L28-L64","documentation":"PrefixFilterProvider.CreateFilteredQuery, when given a prefix filter with an object value, looks for a \"prefix\" property to build the Lucene PrefixQuery. If the object contains neither the handled property nor \"prefix\", it throws ArgumentException(\"Prefix query misses prefix value\") because a prefix filter without a prefix string cannot be constructed.","triggerScenarios":"Calling CreateFilteredQuery with {\"prefix\": {\"Title\": {\"boost\": 2.0}}} — an object that sets boost but omits the required \"prefix\" property; also an object containing only unrecognized keys.","commonSituations":"Hand-writing query JSON and confusing the property name (e.g. writing \"value\" or \"term\" instead of \"prefix\"); porting an Elasticsearch prefix clause (which uses \"value\") into Orchard's Lucene syntax; typo in the key in a saved recipe or query.","solutions":["Add the \"prefix\" property to the object: {\"prefix\": {\"Title\": {\"prefix\": \"Orch\", \"boost\": 2.0}}}.","Check the property key spelling — it must be exactly \"prefix\", not \"value\" or \"term\".","If a plain string value is accepted by this provider for simple cases, pass the prefix as a string instead of an object.","Validate prefix filter objects for the \"prefix\" key before executing the query."],"exampleFix":"// before\n{\"prefix\": {\"Title\": {\"boost\": 2.0}}}\n// after\n{\"prefix\": {\"Title\": {\"prefix\": \"Orch\", \"boost\": 2.0}}}","handlingStrategy":"validation","validationCode":"if (filter.TryGetPropertyValue(field, out var v) && v.ValueKind == JsonValueKind.Object &&\n    !v.AsObject().TryGetPropertyValue(\"prefix\", out _))\n{\n    throw new InvalidOperationException($\"prefix filter for '{field}' requires a 'prefix' property.\");\n}","typeGuard":"static bool HasPrefixValue(JsonElement v) =>\n    v.ValueKind != JsonValueKind.Object ||\n    v.AsObject().TryGetPropertyValue(\"prefix\", out _);","tryCatchPattern":"try\n{\n    var query = provider.CreateFilteredQuery(context);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"misses prefix value\"))\n{\n    _logger.LogError(ex, \"prefix filter missing 'prefix' key: {Json}\", filterJson);\n    throw new QueryValidationException(\"prefix filter requires a 'prefix' property.\", ex);\n}","preventionTips":["Use the exact key \"prefix\" — not \"value\" or \"term\" — in prefix filter objects.","Remember Orchard's Lucene prefix syntax differs from Elasticsearch's \"value\" key.","Validate prefix objects before persisting queries or recipes."],"tags":["lucene","query-filter","missing-value","json"],"backgroundTag":"missing-required-argument","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}