{"record":{"id":"bf652780fadf3af7","repo":"OrchardCMS/OrchardCore","slug":"prefix-query-misses-prefix-value-prefixqueryprovider","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/PrefixQueryProvider.cs","lineNumber":40,"sourceCode":"        {\n            case JsonValueKind.String:\n                return new PrefixQuery(new Term(first.Key, first.Value.ToString()));\n\n            case JsonValueKind.Object:\n                var obj = first.Value.AsObject();\n                PrefixQuery prefixQuery;\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                return prefixQuery;\n\n            default: throw new ArgumentException(\"Invalid prefix query\");\n        }\n    }\n}\n","sourceCodeStart":22,"sourceCodeEnd":54,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/PrefixQueryProvider.cs#L22-L54","documentation":"PrefixQueryProvider.CreateQuery builds a Lucene PrefixQuery from a JSON query node. When the node's type is 'prefix' but the JSON object contains no 'prefix' property, there is no value to build the Term from, so the provider throws ArgumentException. The 'prefix' property holding the prefix string is mandatory for this query type.","triggerScenarios":"Calling CreateQuery with a JSON node like {\"field\": {\"type\": \"prefix\"}} — the object has type 'prefix' but lacks the required \"prefix\" string property.","commonSituations":"Hand-written Lucene query JSON in Queries/UI missing the prefix value; recipes or saved queries exported from an older schema where the property was named differently; typos like 'preifx' or 'Prefix'.","solutions":["Add the required \"prefix\" string property to the query JSON object, e.g. {\"Title\": {\"type\": \"prefix\", \"prefix\": \"Orch\"}}.","Verify the property is named exactly 'prefix' (case-sensitive) and is a JSON string.","If the query came from a saved query or recipe, fix it in the admin UI Queries editor and re-save."],"exampleFix":"// before\n{\"Content.ContentItem.Text\": {\"type\": \"prefix\"}}\n// after\n{\"Content.ContentItem.Text\": {\"type\": \"prefix\", \"prefix\": \"Orch\"}}","handlingStrategy":"validation","validationCode":"if (node is JsonObject obj && obj.TryGetPropertyValue(\"prefix\", out var p) && p is JsonValue pv && pv.TryGetValue<string>(out var prefix) && !string.IsNullOrEmpty(prefix)) { /* safe to call */ }","typeGuard":"static bool HasPrefixValue(JsonNode node) => node is JsonObject o && o.TryGetPropertyValue(\"prefix\", out var p) && p.GetValueKind() == JsonValueKind.String;","tryCatchPattern":"try { var q = provider.CreateQuery(node); } catch (ArgumentException ex) when (ex.Message == \"Prefix query misses prefix value\") { // surface a 'prefix value required' validation message }","preventionTips":["Always include both \"type\": \"prefix\" and \"prefix\": \"...\" in prefix query JSON.","Validate query JSON against the expected schema before submitting.","Prefer the Queries admin UI editor over hand-editing recipe JSON."],"tags":["lucene","query-validation","missing-property"],"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-16T04:17:20.429Z"}