Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFieldDescription ¶
GetFieldDescription returns the description of a CQL field. Returns empty string if the field is not valid.
func GetValidFields ¶
func GetValidFields() []string
GetValidFields returns a slice of all valid field names.
func IsValidField ¶
IsValidField checks if a field name is valid in EPO CQL.
func IsValidOperator ¶
IsValidOperator checks if an operator is valid in EPO CQL.
Types ¶
type CQLQuery ¶
type CQLQuery struct {
// Raw is the original query string
Raw string
// Tokens is the parsed token stream
Tokens []CQLToken
// Valid indicates whether the query passed validation
Valid bool
// Errors contains any validation errors as plain strings.
// Retained for backward compatibility; new code should consult
// Failures instead which preserves the structured failure kind.
Errors []string
// Failures lists structured validation failures from the parser.
// One entry per Errors entry; same order.
Failures []*CQLValidationFailure
}
CQLQuery represents a parsed CQL query.
func ParseCQL ¶
ParseCQL parses a CQL query string and returns a CQLQuery object.
Example queries:
- "ti=bluetooth"
- "ti=bluetooth AND pa=ericsson"
- "(ti=5g OR ab=5g) AND pd>=20200101"
- "pa=\"Apple Inc\" AND ic=H04W"
Returns:
- *CQLQuery: The parsed query with tokens and validation status
- error: An error if the query is completely invalid or empty
func (*CQLQuery) TokenCount ¶
TokenCount returns the number of tokens in the parsed query.
type CQLValidationError ¶ added in v1.2.0
type CQLValidationError struct {
Failures []*CQLValidationFailure
}
CQLValidationError is the error type returned by CQLQuery.Validate when one or more validation checks failed. Callers can errors.As into this type and inspect Failures to dispatch on the specific Kind(s).
func (*CQLValidationError) Error ¶ added in v1.2.0
func (e *CQLValidationError) Error() string
func (*CQLValidationError) First ¶ added in v1.2.0
func (e *CQLValidationError) First() *CQLValidationFailure
First returns the first validation failure, or nil if there are none. Useful for picking a single dominant failure kind when classifying.
type CQLValidationFailure ¶ added in v1.2.0
type CQLValidationFailure struct {
Kind CQLValidationKind
Field string // offending field name when Kind == CQLValidationUnknownField
Pos int // position in the raw query, when available; 0 otherwise
Message string // human-readable description, used as Error()
}
CQLValidationFailure describes a single CQL validation problem.
func (*CQLValidationFailure) Error ¶ added in v1.2.0
func (f *CQLValidationFailure) Error() string
type CQLValidationKind ¶ added in v1.2.0
type CQLValidationKind string
CQLValidationKind classifies a single CQL validation failure so callers can route on the failure mode without inspecting prose. Stable across minor releases; new constants may be added but existing values do not change meaning.
const ( // CQLValidationUnknownField - the query referenced a field name that // is not in the EPO field list (ti, ab, pa, in, pn, ic, cpc, pd, ad). CQLValidationUnknownField CQLValidationKind = "unknown_field" // CQLValidationUnclosedParens - more '(' than ')' in the query. CQLValidationUnclosedParens CQLValidationKind = "unclosed_parens" // CQLValidationUnmatchedParens - a ')' appeared without a matching '('. CQLValidationUnmatchedParens CQLValidationKind = "unmatched_parens" // CQLValidationEmptyQuery - the query tokenized to nothing. CQLValidationEmptyQuery CQLValidationKind = "empty_query" // CQLValidationNoFieldPattern - tokens present but no field=value // pattern detected. Often a sign the caller used another provider's // grammar (e.g. USPTO field:value syntax) on the EPO endpoint. CQLValidationNoFieldPattern CQLValidationKind = "no_field_pattern" )