{"record":{"id":"317e4cba0c1846e8","repo":"OrchardCMS/OrchardCore","slug":"invalid-range-query-rangequeryprovider","errorCode":null,"errorMessage":"Invalid range query","messagePattern":"Invalid range query","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/RangeQueryProvider.cs","lineNumber":98,"sourceCode":"                        }\n\n                        break;\n\n                    case JsonValueKind.String:\n                        var minString = gt?.Value<string>();\n                        var maxString = lt?.Value<string>();\n                        rangeQuery = TermRangeQuery.NewStringRange(field, minString, maxString, includeLower, includeUpper);\n                        break;\n                    default: throw new ArgumentException($\"Unsupported range value type: {type}\");\n                }\n\n                if (boost != null)\n                {\n                    rangeQuery.Boost = boost.Value;\n                }\n\n                return rangeQuery;\n            default: throw new ArgumentException(\"Invalid range query\");\n        }\n    }\n}\n","sourceCodeStart":80,"sourceCodeEnd":102,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/RangeQueryProvider.cs#L80-L102","documentation":"RangeQueryProvider.CreateQuery only recognizes a JSON object node (containing type 'range' with gt/gte/lt/lte). If the node kind for a range query is anything other than Object, the outer switch's default throws ArgumentException. Like the prefix provider, this enforces that range queries are described by objects.","triggerScenarios":"Passing {\"field\": \"someString\"} or an array node to a query intended as a range query, so nodeKind != JsonValueKind.Object.","commonSituations":"Query JSON where the range object was lost during serialization; mixing up term and range syntax; programmatic query builders emitting the wrong structure.","solutions":["Provide a proper object: {\"field\": {\"type\": \"range\", \"gt\": ..., \"lt\": ...}}.","Check the query JSON actually stored/passed — a plain value indicates the range object was flattened or dropped.","Fix the producer code (e.g. the query builder) to emit the object form for range queries."],"exampleFix":"// before\n{\"CreatedUtc\": \"2023-01-01\"}\n// after\n{\"CreatedUtc\": {\"type\": \"range\", \"gte\": \"2023-01-01\", \"lt\": \"2024-01-01\"}}","handlingStrategy":"type-guard","validationCode":"if (node?.GetValueKind() == JsonValueKind.Object) { /* safe to call */ }","typeGuard":"static bool IsRangeQueryObject(JsonNode node) => node is JsonObject o && o.TryGetPropertyValue(\"type\", out var t) && t.GetValueKind() == JsonValueKind.String && t.GetValue<string>() == \"range\";","tryCatchPattern":"try { var q = provider.CreateQuery(node); } catch (ArgumentException ex) when (ex.Message == \"Invalid range query\") { // log raw query JSON and show a schema hint }","preventionTips":["Always express ranges as objects with gt/gte/lt/lte keys.","Validate the query document shape before dispatching to providers.","Keep recipes and saved queries in sync with the current query schema."],"tags":["lucene","range-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-16T04:17:20.429Z"}