grammer

package
v0.0.0-...-334fac4 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EXPORT_JSON = "JSON"
	EXPORT_CSV  = "CSV"
)
View Source
const (
	LogicAND = "AND"
	LogicOR  = "OR"
	LogicNON = "NON" //无复杂逻辑
)
View Source
const (
	FuncEXIST = "EXIST"
	FuncMISS  = "MISS"

	FuncIN  = "IN"
	FuncOUT = "OUT"

	FuncHAS_ANY = "HAS_ANY"
	FuncHAS_ALL = "HAS_ALL"

	FuncRLIKE    = "RLIKE"
	FuncLIKE     = "LIKE"
	FuncNOT_LIKE = "NOT_LIKE"

	FuncSTARTS_WITH = "STARTS_WITH"

	FuncGEO_BBOX = "GEO_BBOX"

	FuncNOT_LOGIC = "MISS|OUT|NOT_LIKE"

	FuncQUERY_STRING = "QUERY_STRING"

	FuncMULTI_MATCH = "MULTI_MATCH"

	FuncMATCH_PHRASE = "MATCH_PHRASE"

	FuncMATCH_PHRASE_PREFIX = "MATCH_PHRASE_PREFIX"
	FuncKNN                 = "KNN"
	FuncIDS                 = "IDS"

	FuncMATCH = "MATCH"

	FuncLOCAL_FILE = "LOCAL_FILE"

	FuncHAS_PARENT = "HAS_PARENT"

	FuncHAS_CHILD = "HAS_CHILD"
)
View Source
const (
	PATH_SEP_CHAR = '$'
	PATH_SEP_STR  = "$"
)

Variables

This section is empty.

Functions

func AdaptSingleComparableExpression

func AdaptSingleComparableExpression(compareExpr IComparableExpression) elastic.Query

func AdaptToQueryBuilder

func AdaptToQueryBuilder(e Expression, ctx *basic.ExeElasticSQLCtx) elastic.Query

AdaptToQueryBuilder where to Query 条件转化总入口

func Exists

func Exists(path string) bool

判断所给路径文件/文件夹是否存在

func GetPathArray

func GetPathArray(field string) ([]string, string)

GetPathArray 工具函数 used for nested path e.g. "a1.b1.c1.d1" to ["a1","a1.b1","a1.b1.c1"] e.g "a1" 返回 空数组

func NestedSingleCondition

func NestedSingleCondition(e *ComparableExpression, query elastic.Query) elastic.Query

Types

type AllExpression

type AllExpression struct {
	ExpressionBase
}

AllExpression match_all

func NewAllExpression

func NewAllExpression() *AllExpression

func (*AllExpression) ToQueryBuilder

func (e *AllExpression) ToQueryBuilder() elastic.Query

type BtwComparableExpression

type BtwComparableExpression struct {
	ComparableExpression
	A   interface{}
	B   interface{}
	Gte bool // 是否左包含
	Lte bool // 是否右包含
}

BtwComparableExpression field between a and b 默认是都包含边界 field range [a,b] or range(a,b)

func NewBtwComparableExpression

func NewBtwComparableExpression() *BtwComparableExpression

func (*BtwComparableExpression) ToQueryBuilder

func (e *BtwComparableExpression) ToQueryBuilder() elastic.Query

type CollapseAdapter

type CollapseAdapter struct {
}

type ComparableExpression

type ComparableExpression struct {
	ExpressionBase
	Field string
	Paths []string // nested field's path, e.g. 字段a.b.c.d的paths是 [a, a.b, a.b.c]
	Not   bool     // 是否是not语义, 按boolean异或生成, not not = false, not != 为 false , not = 为 true

}

func (*ComparableExpression) EnrichBoolQueryBuilder

func (e *ComparableExpression) EnrichBoolQueryBuilder(boolQueryBuilder *elastic.BoolQuery)

EnrichQueryBuilder ComparableExpression类查询通用的对not做处理

func (ComparableExpression) GetField

func (e ComparableExpression) GetField() string

func (*ComparableExpression) GetNot

func (e *ComparableExpression) GetNot() bool

func (ComparableExpression) GetPaths

func (e ComparableExpression) GetPaths() []string

func (ComparableExpression) IsComparableExpression

func (e ComparableExpression) IsComparableExpression() bool

func (*ComparableExpression) NestedSingleCondition

func (e *ComparableExpression) NestedSingleCondition(query elastic.Query) elastic.Query

NestedSingleCondition 单个条件时对嵌套的判断

func (*ComparableExpression) SetField

func (e *ComparableExpression) SetField(field string)

func (*ComparableExpression) SetNot

func (e *ComparableExpression) SetNot(not bool)

func (*ComparableExpression) SetPaths

func (e *ComparableExpression) SetPaths(paths []string)

func (ComparableExpression) XorTrue

func (e ComparableExpression) XorTrue()

XorTrue e.Not^true

type ExportClause

type ExportClause struct {
	Fields     []string
	FileName   string
	FileType   string
	Sep        string
	SaveHeader bool
	Headers    []string
	FetchCode  int
}

ExportClause 导出文件

func NewExportClause

func NewExportClause() *ExportClause

func (*ExportClause) ResetFields

func (c *ExportClause) ResetFields(schema []string)

ResetFields 如果Fields没有设置 就重置

type Expression

type Expression interface {
	// EnrichQueryBuilder use for single condition or '!=' or 'not' logic
	//	将自身放到boolQuery中
	EnrichBoolQueryBuilder(boolQuery *elastic.BoolQuery)
	ToQueryBuilder() elastic.Query
	GetNeedScore() bool
	//AdaptToQueryBuilder(ctx *basic.ExeElasticSQLCtx) elastic.Query
	SetNeedScore(score bool)
	IsComparableExpression() bool
	IsLogicExpression() bool
}

type ExpressionBase

type ExpressionBase struct {
	NeedScore bool    // 是否算分
	Boost     float64 // for boost
}

func (*ExpressionBase) CloneNew

func (e *ExpressionBase) CloneNew(dst interface{}) error

CloneNew 通过序列化深度copy. dst must be a pointer to the correct type

func (*ExpressionBase) EnrichBoolQueryBuilder

func (e *ExpressionBase) EnrichBoolQueryBuilder(boolQuery *elastic.BoolQuery)

func (*ExpressionBase) GetNeedScore

func (e *ExpressionBase) GetNeedScore() bool

func (ExpressionBase) IsComparableExpression

func (e ExpressionBase) IsComparableExpression() bool

func (ExpressionBase) IsLogicExpression

func (e ExpressionBase) IsLogicExpression() bool

func (*ExpressionBase) SetNeedScore

func (e *ExpressionBase) SetNeedScore(need bool)

func (*ExpressionBase) ToQueryBuilder

func (e *ExpressionBase) ToQueryBuilder() elastic.Query

type FullLevelFunctionalComparableExpression

type FullLevelFunctionalComparableExpression struct {
	ComparableExpression
	Func  string
	Props map[string]interface{}
}

func NewFullLevelFunctionalComparableExpression

func NewFullLevelFunctionalComparableExpression() *FullLevelFunctionalComparableExpression

func (*FullLevelFunctionalComparableExpression) ToQueryBuilder

type FunctionalComparableExpression

type FunctionalComparableExpression struct {
	ComparableExpression
	Func   string
	Params []interface{}
	// contains filtered or unexported fields
}

func NewFunctionalComparableExpression

func NewFunctionalComparableExpression() *FunctionalComparableExpression

func (*FunctionalComparableExpression) ToQueryBuilder

func (e *FunctionalComparableExpression) ToQueryBuilder() elastic.Query

type HighlightAdapter

type HighlightAdapter struct {
	FieldAndSchema    map[string]string
	FieldSchema       []string // as
	Tag               string   // 与filed对应
	FragmentSize      int
	NumberOfFragments int
	NoMatchSize       int
}

func NewHighlightAdapter

func NewHighlightAdapter() *HighlightAdapter

func (*HighlightAdapter) ToHighlightBuilder

func (a *HighlightAdapter) ToHighlightBuilder() *elastic.Highlight

type IComparableExpression

type IComparableExpression interface {
	Expression
	GetField() string
	SetField(field string)
	GetPaths() []string
	SetPaths(paths []string)
	SetNot(not bool)
	GetNot() bool
	NestedSingleCondition(query elastic.Query) elastic.Query
}

type LogicExpression

type LogicExpression struct {
	ExpressionBase

	SubExpr []Expression // 所有的子表达式

	PathExpr *PathTree // 用PathTree存储该logic-expr中的nested条件

	FB bool // 是否有括号强制(Force Bracket) 单独Logic 而不是和相同的path合并

	Nested        bool   // 是否有nested类型字段条件
	UniParentPath string // 子表达式的统一parentPath
	Not           bool   // 是否有 not(xxx)  专门用于 nested not
	Logic         string // 默认无LOGIC

	HasSub bool // 是否是含有子表达式 初始化后是空的为false AddSubExpr 之后就不为空 为true
}

LogicExpression and or 逻辑

func NewLogicExpression

func NewLogicExpression() *LogicExpression

func (*LogicExpression) AddNested

func (e *LogicExpression) AddNested() elastic.Query

func (*LogicExpression) AddSubExpr

func (e *LogicExpression) AddSubExpr(expr Expression)

func (*LogicExpression) EnrichBoolQueryBuilder

func (e *LogicExpression) EnrichBoolQueryBuilder(boolQuery *elastic.BoolQuery)

func (LogicExpression) IsLogicExpression

func (e LogicExpression) IsLogicExpression() bool

func (*LogicExpression) ToQueryBuilder

func (e *LogicExpression) ToQueryBuilder() elastic.Query

type MultiTreeNode

type MultiTreeNode struct {
	Path          string
	Layer         int
	Datas         []*TreeNode
	NonRangeExprs []IComparableExpression
	RangeExprs    map[string][]*TermComparableExpression
	// contains filtered or unexported fields
}

MultiTreeNode 多叉树节点

func NewMultiTreeNode

func NewMultiTreeNode(path string, isRoot bool) *MultiTreeNode

func (*MultiTreeNode) AddChild

func (n *MultiTreeNode) AddChild(child *MultiTreeNode)

func (*MultiTreeNode) AddData

func (n *MultiTreeNode) AddData(node *TreeNode)

AddData 在节点上添加条件表达式

func (*MultiTreeNode) GetChild

func (n *MultiTreeNode) GetChild(path string) *MultiTreeNode

type PathTree

type PathTree struct {
	Root        *MultiTreeNode
	NestedPaths map[string]basic.Void // 存放所有的nested path 也就是parentPath
}

无nested类型的logic无PathTreee 为了nested类型字段的查询,同一路径下合并到一个nested查询中

func NewPathTree

func NewPathTree() *PathTree

func (*PathTree) AddNonPathNode

func (t *PathTree) AddNonPathNode(expression IComparableExpression)

func (*PathTree) AddPathNode

func (t *PathTree) AddPathNode(expression IComparableExpression)

func (*PathTree) VisitTree

func (t *PathTree) VisitTree(tree *MultiTreeNode, boolQueryBuilder *elastic.BoolQuery, handler func(tree *MultiTreeNode, boolQuery *elastic.BoolQuery) *elastic.BoolQuery)

type RescoreAdapter

type RescoreAdapter struct {
}

type ScriptAdapter

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

func (*ScriptAdapter) ToScript

func (s *ScriptAdapter) ToScript() (*elastic.Script, error)

type SortAdapter

type SortAdapter struct {
	Field          string
	Ascending      bool
	OrderLogic     int // asc 1 , desc -1, used for mem-sort
	Mode           string
	NestedFilter   Expression
	Script         *ScriptAdapter
	ScriptSortType string
}

func (*SortAdapter) ToFieldSortBuilder

func (a *SortAdapter) ToFieldSortBuilder() elastic.Sorter

type TermComparableExpression

type TermComparableExpression struct {
	ComparableExpression
	Operator string
	Value    interface{}
}

func NewTermComparableExpression

func NewTermComparableExpression() *TermComparableExpression

func (*TermComparableExpression) EnrichQueryBuilderByMustNot

func (e *TermComparableExpression) EnrichQueryBuilderByMustNot(boolQueryBuilder *elastic.BoolQuery)

func (*TermComparableExpression) IsRange

func (e *TermComparableExpression) IsRange() bool

func (*TermComparableExpression) ToQueryBuilder

func (e *TermComparableExpression) ToQueryBuilder() elastic.Query

type TermGroup

type TermGroup []*TermComparableExpression

func (TermGroup) Len

func (g TermGroup) Len() int

func (TermGroup) Less

func (g TermGroup) Less(i, j int) bool

Less 有小到大排序 本体系中只有int64 float64两种类型

func (TermGroup) Swap

func (g TermGroup) Swap(i, j int)

type TreeNode

type TreeNode struct {
	Expr        IComparableExpression // 节点表达式
	ParentPath  string                // paths的最后一个. 如 a.b.c.d = 1 的 parentPath 是 a.b.c
	PathsOnTree []string              // paths, 如 a.b.c.d = 1 的paths is ['a','a.b','a.b.c']
	Layer       int                   // 加在第几层 len(paths)
}

data node 用于nested类型中存放 ComparableExpression

func NewTreeNode

func NewTreeNode(expr IComparableExpression) *TreeNode

Jump to

Keyboard shortcuts

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