Documentation
¶
Index ¶
- Variables
- func Group(str string) []string
- func IsNaturalSplit(str string) bool
- func Position(text, str string) []int
- func Split(str string) []string
- type DB
- type Document
- type Engine
- func (e *Engine) Close() error
- func (e *Engine) Delete(key []byte) error
- func (e *Engine) Get(key []byte) (doc *Document, err error)
- func (e *Engine) Has(key []byte) (bool, error)
- func (e *Engine) IndexKeys(f func(key []byte)) int
- func (e *Engine) IndexNum() int
- func (e *Engine) Put(doc *Document)
- func (e *Engine) Search(str string) []*Document
- func (e *Engine) SearchKey(str string) [][]byte
- type Leveldb
- func (l *Leveldb) Close() error
- func (l *Leveldb) Delete(key []byte) error
- func (l *Leveldb) Get(key []byte) ([]byte, error)
- func (l *Leveldb) Has(key []byte) (bool, error)
- func (l *Leveldb) Iterator(prefix []byte, f func(key, value []byte)) error
- func (l *Leveldb) IteratorKey(prefix []byte, f func(key []byte)) error
- func (l *Leveldb) Put(key, value []byte) error
- type Posting
- type Word
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
// WordMaxLength 最大词长度
WordMaxLength = 6
)
Functions ¶
func Group ¶
Group 句子分组
Example ¶
fmt.Println(Group("太阳当空照"))
Output: [太阳 太阳当 太阳当空 太阳当空照 阳当 阳当空 阳当空照 当空 当空照 空照]
Types ¶
type DB ¶
type DB interface {
// Close 数据库关闭
Close() error
// Get 获取
Get(key []byte) ([]byte, error)
// Put 写入
Put(key, value []byte) error
// Has 是否包含
Has(key []byte) (bool, error)
// Delete 删除
Delete(key []byte) error
// Iterator 迭代数据
Iterator(prefix []byte, f func(key, value []byte)) error
// IteratorKey 迭代Key
IteratorKey(prefix []byte, f func(key []byte)) error
}
DB 数据库接口
type Document ¶
type Document struct {
Key []byte `json:"key"` // 主键
Title string `json:"title,omitempty"` // 标题
Summary string `json:"summary,omitempty"` // 摘要
Content string `json:"content"` // 内容
Modified time.Time `json:"modified"` // 修改时间
}
Document 文档
Example ¶
doc := Document{
Key: []byte("123"),
Title: "标题",
Summary: "简介",
Content: "内容",
}
j, _ := json.Marshal(doc)
fmt.Println(string(j))
Output: {"key":"MTIz","title":"标题","summary":"简介","content":"内容","modified":"0001-01-01T00:00:00Z"}
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine 引擎
func NewLevelEngine ¶
NewLevelEngine leveldb 搜索引擎
Example ¶
e, err := NewLevelEngine("/tmp/search_db")
defer e.Close()
fmt.Println(err)
Output: <nil>
func (*Engine) Has ¶
Has 文档是否索引过
Example ¶
e, _ := NewLevelEngine("/tmp/search_db")
defer e.Close()
ok, err := e.Has([]byte("asd"))
fmt.Println(ok, err)
Output: false <nil>
func (*Engine) Put ¶
Put 更新文档
Example ¶
key := []byte("11")
e, _ := NewLevelEngine("/tmp/search_db")
defer e.Close()
doc := &Document{
Key: key,
Title: "不生气",
Summary: "生气引发的疾病",
Content: "关于生气有,我有些话要说",
}
e.Put(doc)
ok, err := e.Has(key)
fmt.Println(ok, err)
nd, err := e.Get(key)
fmt.Println(nd.Title == doc.Title, err)
Output: true <nil> true <nil>
func (*Engine) Search ¶
Search 搜索文档
Example ¶
e, _ := NewLevelEngine("/tmp/search_db")
defer e.Close()
doc := &Document{
Key: []byte("11"),
Title: "不生气",
Summary: "生气引发的疾病",
Content: "关于生气,我有些话要说",
}
e.Put(doc)
fmt.Println(len(e.Search("生气")))
fmt.Println(len(e.Search("高兴")))
Output: 1 0
func (*Engine) SearchKey ¶
SearchKey 搜索文档主键
Example ¶
e, _ := NewLevelEngine(fmt.Sprintf("/tmp/%s", utils.NewID('t')))
defer e.Close()
doc := &Document{
Key: []byte("11"),
Title: "不生气",
Summary: "生气引发的疾病",
Content: "关于生气,我有些话要说",
}
e.Put(doc)
keys := e.SearchKey("疾病")
fmt.Println(keys)
keys = e.SearchKey("发病")
fmt.Println(keys)
Output: [[49 49]] []
type Leveldb ¶
type Leveldb struct {
// contains filtered or unexported fields
}
Leveldb 数据库支持
func (*Leveldb) IteratorKey ¶
IteratorKey 迭代Key
Source Files
¶
Click to show internal directories.
Click to hide internal directories.