cql

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2025 License: MIT Imports: 4 Imported by: 2

Documentation

Overview

Contextual Query Language (CQL) syntax tree API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolClause

type BoolClause struct {
	Left      Clause
	Operator  Operator
	Modifiers []Modifier
	Right     Clause
}

Represents a boolean clause (expression). The `Left`, `Right` and `Operator` fields should be initialized. When the operator is not set, `and` will be used during stringification.

func (*BoolClause) String

func (bc *BoolClause) String() string

type Clause

type Clause struct {
	PrefixMap    []Prefix
	SearchClause *SearchClause
	BoolClause   *BoolClause
}

Represents either a search or a boolean clause (expression). Exactly one pointer field should be set when creating this struct. When neither pointer is set, the clause will stringify to `cql.allRecords = 1` (a special expression matching all records).

func (*Clause) String

func (c *Clause) String() string

type CqlIndex

type CqlIndex string

CQL special built-in indexes.

const (
	AllRecords   CqlIndex = "cql.allRecords"
	AllIndexes   CqlIndex = "cql.allIndexes"
	AnyIndexes   CqlIndex = "cql.anyIndexes"
	Anywhere     CqlIndex = "cql.anywhere"
	Keywords     CqlIndex = "cql.keywords"
	ServerChoice CqlIndex = "cql.serverChoice"
	ResultSetId  CqlIndex = "cql.resultSetId"
)

type CqlModifier

type CqlModifier string

CQL built-in modifiers.

const (
	Stem           CqlModifier = "stem"           //relation/sort, apply stemming to terms
	Relevant       CqlModifier = "relevant"       //relation/sort, apply relevancy matching
	Phonetic       CqlModifier = "phonetic"       //relation/sort, match words sounding like term
	Fuzzy          CqlModifier = "fuzzy"          //relation/sort, fuzzy matching
	Partial        CqlModifier = "partial"        //relation/sort, used with `within`/`encloses`
	IgnoreCase     CqlModifier = "ignoreCase"     //relation/sort, match case-insensitive
	RespectCase    CqlModifier = "respectCase"    //relation/sort, match case-sensitive
	IgnoreAccents  CqlModifier = "ignoreAccents"  //relation/sort, match w/o diacritics
	RespectAccents CqlModifier = "respectAccents" //relation/sort, match with diacritics
	Locale         CqlModifier = "locale"         //relation/sort, set locale, e.g `locale=da_DK`
	Word           CqlModifier = "word"           //relation/sort, break term into words
	String         CqlModifier = "string"         //relation/sort, treat term as a string
	IsoDate        CqlModifier = "isoDate"        //relation/sort, term is an ISO date, e.g `2000-10-31T01:30:00.000-05:00`
	Number         CqlModifier = "number"         //relation/sort, term is a number
	Uri            CqlModifier = "uri"            //relation/sort, term is a URI
	Oid            CqlModifier = "oid"            //relation/sort, terms is a ISO Object Identifier (OID), e.g `1.2.840.10003.3.1`
	Masked         CqlModifier = "masked"         //relation, on by default, * - zero/more chars, ? - single char, ^ - word anchor, \ - escape char, e.g `dc.title adj "*fish food*“
	Unmasked       CqlModifier = "unmasked"       //relation, disable masking
	Substring      CqlModifier = "substring"      //relation, match range of chars, e.g `marc.008 =/substring="1:6" 920102`
	Regexp         CqlModifier = "regexp"         //relation, term is a regular expression
	Distance       CqlModifier = "distance"       //proximity, distance expression e.g `cat prox/distance>2 hat`
	Unit           CqlModifier = "unit"           //proximity, unit for distance, one of paragraph, sentence, word (default), element
	Unordered      CqlModifier = "unordered"      //proximity, order of terms is unimportant
	Ordered        CqlModifier = "ordered"        //proximity, order of terms is important
)

type Modifier

type Modifier struct {
	Name     string
	Relation Relation
	Value    string
}

Represents a relation or a boolean operator modifier. At least `Name` should be set otherwise the struct will stringify to an empty quoted string. If `Relation` is not set but `Value` is, the `=` will be used during stringification.

func (*Modifier) String

func (m *Modifier) String() string

type Operator

type Operator string

CQL boolean operators.

const (
	AND  Operator = "and"
	NOT  Operator = "not"
	OR   Operator = "or"
	PROX Operator = "prox"
)

type ParseError

type ParseError struct {
	// contains filtered or unexported fields
}

Indicates query parsing error

func (*ParseError) Error

func (e *ParseError) Error() string

Formats error for display

func (*ParseError) Marked

func (e *ParseError) Marked() string

Query with the error position marked

func (*ParseError) Message

func (e *ParseError) Message() string

Raw parser error message

func (*ParseError) Pos

func (e *ParseError) Pos() int

Error position in the query

func (*ParseError) Query

func (e *ParseError) Query() string

Query that caused the error

type Parser

type Parser struct {
	Strict bool //if true, multi term values, e.g. `a b c` are not allowed
	// contains filtered or unexported fields
}

CQL parser, non-strict by default

func (*Parser) Parse

func (p *Parser) Parse(input string) (Query, error)

Parse input query string into a syntax tree or return an error.

type Prefix

type Prefix struct {
	Prefix string
	Uri    string
}

Represents a prefix declaration. The Prefix field can be omitted. The Uri field should be set or the struct will stringify to an empty quoted string.

func (*Prefix) String

func (p *Prefix) String() string

type Query

type Query struct {
	Clause
	SortSpec []Sort
}

Represents the top-level CQL query. The `Clause“ field should be provided upon initialization. the `SortSpec` field is optional.

func (*Query) String

func (q *Query) String() string

type Relation

type Relation string

CQL built-in symbolic and named relations.

const (
	EQ       Relation = "="
	NE       Relation = "<>"
	LT       Relation = "<"
	GT       Relation = ">"
	LE       Relation = "<="
	GE       Relation = ">="
	ADJ      Relation = "adj"
	ALL      Relation = "all"
	ANY      Relation = "any"
	SCR      Relation = "scr"
	ENCLOSES Relation = "encloses"
	EXACT    Relation = "exact"
	WITHIN   Relation = "within"
)

type SearchClause

type SearchClause struct {
	Index     string
	Relation  Relation
	Modifiers []Modifier
	Term      string
}

Represents a search clause (expression). When no `Index` is given the `cql.serverChoice` is used during stringification. when no `Relation` is given the `=` (aka `scr`) is used during stringification.

func (*SearchClause) String

func (sc *SearchClause) String() string

type Sort

type Sort struct {
	Index     string
	Modifiers []Modifier
}

Represents a sort criterion. If the `Index“ field is not set, the struct will stringify to an empty quoted string.

func (*Sort) String

func (s *Sort) String() string

type Xcql

type Xcql struct {
	// contains filtered or unexported fields
}

func (*Xcql) Marshal

func (xcql *Xcql) Marshal(query Query, tab int) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL