utils

package
v0.0.0-...-2b62fdb Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoField        = "__ERR_NO_FIELD_SET__"
	GroupInitField = "__GROUP_INIT__"
)

Variables

View Source
var (
	// sentinel value marking the start of the "current" nested AND/OR clause, for stacking
	GroupInit = &Value{nil, GroupInitField, NoOp, false}
	// sentinel value for Value with as-yet-unset elastic.Query field
	NoQuery elastic.Query = nil
)

Functions

This section is empty.

Types

type Oper

type Oper uint8
const (
	Unset Oper = iota
	DefaultAnd
	DefaultOr
	And
	Or
)

func (Oper) String

func (o Oper) String() string

type Query

type Query struct {
	BoolQ  *elastic.BoolQuery
	Oper   Oper
	Negate bool
}

func NewLevel

func NewLevel(op Oper, negate bool) *Query

func (*Query) Must

func (q *Query) Must(eq elastic.Query)

func (*Query) MustNot

func (q *Query) MustNot(eq elastic.Query)

func (*Query) SetOper

func (q *Query) SetOper(op Oper)

func (*Query) Should

func (q *Query) Should(eq elastic.Query)

type QueryStack

type QueryStack struct {
	Output *elastic.BoolQuery
	// contains filtered or unexported fields
}

func (*QueryStack) Compose

func (qs *QueryStack) Compose(values []*Value) *Query

when ')' or end-of-input is encountered, we pop the whole group of individual queries from the stack back to the last '(' or start-of-input, and we inject into the parent bool query at proper bucket/nesting

func (*QueryStack) Current

func (qs *QueryStack) Current() *Query

obtain a pointer to the "current" query

func (*QueryStack) Empty

func (qs *QueryStack) Empty() bool

func (*QueryStack) Finalize

func (qs *QueryStack) Finalize(values []*Value)

func (*QueryStack) Init

func (qs *QueryStack) Init(defaultToOr bool)

func (*QueryStack) Pop

func (qs *QueryStack) Pop() *Query

func (*QueryStack) Push

func (qs *QueryStack) Push(negate bool)

type RangeOp

type RangeOp uint8
const (
	NoOp RangeOp = iota
	LessThan
	LessThanEqual
	GreaterThan
	GreaterThanEqual
)

type Value

type Value struct {
	Q       elastic.Query
	Field   string
	RangeOp RangeOp
	Negate  bool
}

func NewValue

func NewValue(negate bool) *Value

type ValueStack

type ValueStack struct {
	Default string
	// contains filtered or unexported fields
}

func (*ValueStack) Boolean

func (vs *ValueStack) Boolean(value string)

func (*ValueStack) Date

func (vs *ValueStack) Date(filtered bool, value interface{})

takes RFC3339 datetime in UTC as string

func (*ValueStack) DateRangeOrMatchTerm

func (vs *ValueStack) DateRangeOrMatchTerm(filtered bool, value string)

func (*ValueStack) Empty

func (vs *ValueStack) Empty() bool

func (*ValueStack) Exists

func (vs *ValueStack) Exists()

func (*ValueStack) Init

func (vs *ValueStack) Init(defField string)

func (*ValueStack) Match

func (vs *ValueStack) Match(text interface{})

func (*ValueStack) MatchTerm

func (vs *ValueStack) MatchTerm(filtered bool, value string)

values should land in a "match" clause in query context, "term" clause in filter context

func (*ValueStack) Number

func (vs *ValueStack) Number(filtered bool, value interface{})

func (*ValueStack) NumberRangeOrMatchTerm

func (vs *ValueStack) NumberRangeOrMatchTerm(filtered bool, value string)

func (*ValueStack) Phrase

func (vs *ValueStack) Phrase(phrase string)

only used in single-value (quoted phrase) context (i.e. not a KV)

func (*ValueStack) Pop

func (vs *ValueStack) Pop() *Value

func (*ValueStack) PopGroup

func (vs *ValueStack) PopGroup() []*Value

returns the group of values for this nested AND/OR block

func (*ValueStack) Push

func (vs *ValueStack) Push(v *Value)

func (*ValueStack) Range

func (vs *ValueStack) Range(value interface{})

func (*ValueStack) SetField

func (vs *ValueStack) SetField(field string)

pop the tmp value stacked by SetNegation earlier, or produce new one if not - then fill in Field, replace on stack

func (*ValueStack) SetNegation

func (vs *ValueStack) SetNegation()

first thing that happens in Term parsing (if present), so append a dummy value for filling in as we parse

func (*ValueStack) SetRangeOp

func (vs *ValueStack) SetRangeOp(rop RangeOp)

pop the tmp value stacked by SetNegation and SetField, fill in range op, replace on stack

func (*ValueStack) StartGroup

func (vs *ValueStack) StartGroup()

start sentinel for parens-nested groupings of AND/OR separated query elements TODO: move ValueStack into parent QueryStack instances to disambiguate this

func (*ValueStack) Term

func (vs *ValueStack) Term(term interface{})

func (*ValueStack) Window

func (vs *ValueStack) Window(fromTildaTo string)

TODO: this is hacky, separate out the number and date range handling

Jump to

Keyboard shortcuts

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