1
0
forked from x/icebergs
icebergs/base/mdb/search.go
2023-07-28 22:49:18 +08:00

32 lines
834 B
Go

package mdb
import (
ice "shylinux.com/x/icebergs"
kit "shylinux.com/x/toolkits"
)
const SEARCH = "search"
func init() {
Index.MergeCommands(ice.Commands{SEARCH: {Help: "搜索", Actions: RenderAction()}})
ice.AddMergeAction(func(c *ice.Context, key string, cmd *ice.Command, sub string, action *ice.Action) ice.Handler {
if sub == SEARCH {
return func(m *ice.Message, arg ...string) { m.Cmd(sub, CREATE, m.CommandKey(), m.PrefixKey()) }
}
return nil
})
}
func IsSearchPreview(m *ice.Message, arg []string, cb ...func() []string) bool {
if arg[0] == FOREACH && arg[1] == "" {
for _, cb := range cb {
if cb != nil {
if args := cb(); len(args) > 0 {
m.PushSearch(TYPE, kit.Select("", args, 0), NAME, kit.Select("", args, 1), TEXT, kit.Select("", args, 2))
}
}
}
return true
}
return false
}