Documentation ¶
Index ¶
- type MatchResult
- type Node
- type XTrie
- func (x *XTrie) DictAdd(key string, level int)
- func (x *XTrie) DictRead() (bool, error)
- func (x *XTrie) DictRemove(key string) error
- func (x *XTrie) Fuzzy(key string, limit int) ([]MatchResult, error)
- func (x *XTrie) InitHandle(storeFile string, dictFile string)
- func (x *XTrie) Insert(key string, level int) error
- func (x *XTrie) Load(path string) error
- func (x *XTrie) Match(key string, forceBack bool) (int, int, error)
- func (x *XTrie) Prefix(pre string, limit int) ([]MatchResult, error)
- func (x *XTrie) Remove(key string) error
- func (x *XTrie) Search(key string) []MatchResult
- func (x *XTrie) Store(path string) error
- func (x *XTrie) Suffix(key string, limit int) ([]MatchResult, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MatchResult ¶
查询返回值结构体 使用结构体可以保证检索结果的顺序,使用map结构无法保证顺序
type Node ¶
type Node struct { Code int // 字符对应code值 Depth int // 所处树的层级,正好对应子节点在key中索引 Left int // 当前字符在key list中搜索的左边界索引 (包括) Right int // 当前字符在key list中搜索的右边界索引(不包括) End bool // 是否结束 }
构建trie树使用的节点
type XTrie ¶
type XTrie struct { Fmd5 string // 词典文件md5 Size int // 切片长度 Base []int // 基础切片,存储字符offset,正值和负值分别代表不同的状态 Check []int // 检查字符状态数组,防止查找冲突以及确认多种状态 Keys [][]rune // 所有词典转成rune切片 StoreFile string //dat结构体序列化结果集 DictFile string //词典文件路径 Keymap map[string]int //所有词对应等级 }
x trie结构体 double array trie变种结构体 数据结构更紧凑
func (*XTrie) Fuzzy ¶
func (x *XTrie) Fuzzy(key string, limit int) ([]MatchResult, error)
模糊查找 命中规则,只要有字符是一样的就会返回,最少一个字符
func (*XTrie) InitHandle ¶
初始化 double array 加载store文件,读取词典,编译dat,保存store等
func (*XTrie) Prefix ¶
func (x *XTrie) Prefix(pre string, limit int) ([]MatchResult, error)
前缀查找 匹配搜索词所有相同前缀的词,算法复杂度较高,词不多的时候可以使用
func (*XTrie) Search ¶
func (x *XTrie) Search(key string) []MatchResult
内容匹配模式查找 可传入一段文本,逐字查找是否在词库中存在
Click to show internal directories.
Click to hide internal directories.