Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
QueryTypeOrder = map[QueryType]int{
CaseQuery: 1,
LanguageQuery: 2,
RepoQuery: 3,
FileQuery: 4,
TokenQuery: 6,
RegexQuery: 7,
TreeQuery: 8,
}
)
Functions ¶
func GetModifierName ¶
Types ¶
type Query ¶
type Query struct { // 表达式类型 Type QueryType // 在树状结构中的唯一标识 ID,不同的查询树重新构建 ID ID int // 当 QueryType 为简单文本查询时,存储需要匹配的字符串 // 其他类型下,该字段为空 Token string // 表达式基础上取反操作 Negate bool // 当 QueryType 为正则表达式的时候,这里存储正则表达式原始字符串 RegexString string // 当 QueryType 为正则表达式的时候,这里存储所有解析出来的 token RegexTokens []string // 当 QueryType 为查询树时,SubQueries 存储解析出的递归子查询表达式 SubQueries []*Query Or bool // 如果为 true,则 SubQueries 之间取或,否则取和 // 当 token 或者 regex 类型的 symbol IsSymbol bool // FileQuery FileRegexString string // RepoQuery RepoRegexString string // CaseQuery Case bool // LanguageQuery Language string // 子节点的统计和调试信息 NumNodes int // 树中一共多少节点(包含根节点) MaxDepth int // 子节点最大深度,叶子节点深度为 0 RootDistance int // 该节点到 root 的距离 // contains filtered or unexported fields }
查询表达式 保存了从表达式解析出来的树状结构
func Flatten ¶
对子查询和上级 AND/OR 一致的情况,做扁平化 比如
(a AND (b AND c)) -> (a AND b AND c) (a OR (b OR c)) -> (a OR b OR c)
另外,对只有一个子查询的情况,做级别提升
((a)) -> (a)
func (*Query) String ¶
返回 query 的字符串表征 该字符串和 query 本身是一一对应的,也就是说 1、两个表征字符串相同的 query 是完全相同的 2、实际相同的两个 query 的表征字符串完全相等 这里所说的“实际相同”值得是做过归一化的相同,比如
(a AND b) == (b AND a),表征字符串为 "(a AND b)" (a AND (b AND c)) == (a AND b AND c),表征字符串为 "(a AND b AND c)"
注意复杂运算下相同的两个逻辑相等的 query 可能有不同的字符串表征,比如
(a AND (b OR c)) 表征字符串为 "(a AND (b OR c))" ((a AND b) OR (a AND c)) 表征字符串为 "((a AND b) OR (a AND c))"
Click to show internal directories.
Click to hide internal directories.