Skip to content

Commit

Permalink
🐛 编辑器中输入 # 后标签搜索提示不全 Fix #7391
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Feb 17, 2023
1 parent 8196052 commit e08d621
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion kernel/model/graph.go
Expand Up @@ -205,7 +205,7 @@ func BuildGraph(query string) (boxID string, nodes []*GraphNode, links []*GraphL
}

func linkTagBlocks(blocks *[]*Block, nodes *[]*GraphNode, links *[]*GraphLink, p string, style map[string]string) {
tagSpans := sql.QueryTagSpans(p, 1024)
tagSpans := sql.QueryTagSpans(p)
if 1 > len(tagSpans) {
return
}
Expand Down
6 changes: 3 additions & 3 deletions kernel/model/tag.go
Expand Up @@ -41,7 +41,7 @@ func RemoveTag(label string) (err error) {
util.PushEndlessProgress(Conf.Language(116))
util.RandomSleep(1000, 2000)

tags := sql.QueryTagSpansByKeyword(label, 102400)
tags := sql.QueryTagSpansByLabel(label)
treeBlocks := map[string][]string{}
for _, tag := range tags {
if blocks, ok := treeBlocks[tag.RootID]; !ok {
Expand Down Expand Up @@ -126,7 +126,7 @@ func RenameTag(oldLabel, newLabel string) (err error) {
util.PushEndlessProgress(Conf.Language(110))
util.RandomSleep(500, 1000)

tags := sql.QueryTagSpansByKeyword(oldLabel, 102400)
tags := sql.QueryTagSpansByLabel(oldLabel)
treeBlocks := map[string][]string{}
for _, tag := range tags {
if blocks, ok := treeBlocks[tag.RootID]; !ok {
Expand Down Expand Up @@ -310,7 +310,7 @@ func labelBlocksByKeyword(keyword string) (ret map[string]TagBlocks) {
func labelTags() (ret map[string]Tags) {
ret = map[string]Tags{}

tagSpans := sql.QueryTagSpans("", 10240)
tagSpans := sql.QueryTagSpans("")
for _, tagSpan := range tagSpans {
label := tagSpan.Content
if _, ok := ret[label]; ok {
Expand Down
20 changes: 17 additions & 3 deletions kernel/sql/span.go
Expand Up @@ -80,8 +80,23 @@ func SelectSpansRawStmt(stmt string, limit int) (ret []*Span) {
return
}

func QueryTagSpansByLabel(label string) (ret []*Span) {
stmt := "SELECT * FROM spans WHERE type LIKE '%tag%' AND content LIKE '%" + label + "%' GROUP BY block_id"
rows, err := query(stmt)
if nil != err {
logging.LogErrorf("sql query failed: %s", err)
return
}
defer rows.Close()
for rows.Next() {
span := scanSpanRows(rows)
ret = append(ret, span)
}
return
}

func QueryTagSpansByKeyword(keyword string, limit int) (ret []*Span) {
stmt := "SELECT * FROM spans WHERE type LIKE '%tag%' AND content LIKE '%" + keyword + "%'"
stmt := "SELECT * FROM spans WHERE type LIKE '%tag%' AND content LIKE '%" + keyword + "%' GROUP BY markdown"
stmt += " LIMIT " + strconv.Itoa(limit)
rows, err := query(stmt)
if nil != err {
Expand All @@ -96,12 +111,11 @@ func QueryTagSpansByKeyword(keyword string, limit int) (ret []*Span) {
return
}

func QueryTagSpans(p string, limit int) (ret []*Span) {
func QueryTagSpans(p string) (ret []*Span) {
stmt := "SELECT * FROM spans WHERE type LIKE '%tag%'"
if "" != p {
stmt += " AND path = '" + p + "'"
}
stmt += " LIMIT " + strconv.Itoa(limit)
rows, err := query(stmt)
if nil != err {
logging.LogErrorf("sql query failed: %s", err)
Expand Down

0 comments on commit e08d621

Please sign in to comment.