🎨 Tag search supports space-separated keywords https://github.com/siyuan-note/siyuan/issues/14580

This commit is contained in:
Daniel 2025-04-11 22:02:56 +08:00
parent 8a5dafeb07
commit da9caf91cf
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -96,8 +96,16 @@ func QueryTagSpansByLabel(label string) (ret []*Span) {
}
func QueryTagSpansByKeyword(keyword string, limit int) (ret []*Span) {
stmt := "SELECT * FROM spans WHERE type LIKE '%tag%' AND content LIKE '%" + keyword + "%' GROUP BY markdown"
stmt += " LIMIT " + strconv.Itoa(limit)
// 标签搜索支持空格分隔关键字 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 += " OR "
}
contentLikes += "content LIKE '%" + k + "%'"
}
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)