Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Empty tags no longer appear in the tag panel https://github.com/siyuan-note/siyuan/issues/17367 (#17369)

Jeffrey Chena674b1480634
diff --git a/kernel/model/tag.go b/kernel/model/tag.go
index 6a6dd4b2d3..ddf7c0e03e 100644
--- a/kernel/model/tag.go
+++ b/kernel/model/tag.go
@@ -128,7 +128,7 @@ func RenameTag(oldLabel, newLabel string) (err error) {
newLabel = strings.TrimSuffix(newLabel, "/")
newLabel = strings.TrimSpace(newLabel)
- if "" == newLabel {
+ if "" == oldLabel || "" == newLabel {
return errors.New(Conf.Language(114))
}
@@ -367,12 +367,6 @@ func labelTags() (ret map[string]Tags) {
tagSpans := sql.QueryTagSpans("")
for _, tagSpan := range tagSpans {
label := util.UnescapeHTML(tagSpan.Content)
- if "" == label {
- // 老旧的数据中可能存在标签内容为空的情况,跳过这些数据
- // Empty tags no longer appear in the tag panel https://github.com/siyuan-note/siyuan/issues/17367
- continue
- }
-
if _, ok := ret[label]; ok {
ret[label] = append(ret[label], &Tag{})
} else {
diff --git a/kernel/sql/span.go b/kernel/sql/span.go
index 26770cddc6..e8ca7718c9 100644
--- a/kernel/sql/span.go
+++ b/kernel/sql/span.go
@@ -97,15 +97,20 @@ func QueryTagSpansByLabel(label string) (ret []*Span) {
func QueryTagSpansByKeyword(keyword string, limit int) (ret []*Span) {
// 标签搜索支持空格分隔关键字 Tag search supports space-separated keywords https://github.com/siyuan-note/siyuan/issues/14580
- keywords := strings.Split(keyword, " ")
- contentLikes := ""
- for _, k := range keywords {
- if contentLikes != "" {
- contentLikes += " AND "
+ keywords := strings.Fields(keyword)
+ var stmt string
+ if len(keywords) == 0 {
+ stmt = "SELECT * FROM spans WHERE type LIKE '%tag%' AND content != '' GROUP BY markdown LIMIT " + strconv.Itoa(limit)
+ } else {
+ contentLikes := ""
+ for _, k := range keywords {
+ if contentLikes != "" {
+ contentLikes += " AND "
+ }
+ contentLikes += "content LIKE '%" + k + "%'"
}
- contentLikes += "content LIKE '%" + k + "%'"
+ stmt = "SELECT * FROM spans WHERE type LIKE '%tag%' AND (" + contentLikes + ") GROUP BY markdown LIMIT " + strconv.Itoa(limit)
}
- stmt := "SELECT * FROM spans WHERE type LIKE '%tag%' AND (" + contentLikes + ") GROUP BY markdown LIMIT " + strconv.Itoa(limit)
rows, err := query(stmt)
if err != nil {
logging.LogErrorf("sql query failed: %s", err)
@@ -120,7 +125,7 @@ func QueryTagSpansByKeyword(keyword string, limit int) (ret []*Span) {
}
func QueryTagSpans(p string) (ret []*Span) {
- stmt := "SELECT * FROM spans WHERE type LIKE '%tag%'"
+ stmt := "SELECT * FROM spans WHERE type LIKE '%tag%' AND content != ''"
if "" != p {
stmt += " AND path = '" + p + "'"
}