Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2024-05-27 09:26:36 +08:00
commit 456e53ebfd
5 changed files with 40 additions and 24 deletions

File diff suppressed because one or more lines are too long

View file

@ -8,7 +8,7 @@ require (
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
github.com/88250/gulu v1.2.3-0.20240505150113-bc43bd50f866
github.com/88250/lute v1.7.7-0.20240525091726-a500a25a2c80
github.com/88250/lute v1.7.7-0.20240526122836-7777ff8a1ab1
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4

View file

@ -12,8 +12,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950 h1:Pa5hMiBceT
github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/88250/gulu v1.2.3-0.20240505150113-bc43bd50f866 h1:RFfNFS0hv6TbOuwET6xZAfGlV4hNlXiWTnfbLN1eF6k=
github.com/88250/gulu v1.2.3-0.20240505150113-bc43bd50f866/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8=
github.com/88250/lute v1.7.7-0.20240525091726-a500a25a2c80 h1:BARuyUqtkBoKV+6w6ufiWGNQ1Pmlhxoga1TVK3I/zoM=
github.com/88250/lute v1.7.7-0.20240525091726-a500a25a2c80/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
github.com/88250/lute v1.7.7-0.20240526122836-7777ff8a1ab1 h1:xcNq6ZecLsJQjrZwg1k4X3XLamMBCK2II0ATgu4YIUQ=
github.com/88250/lute v1.7.7-0.20240526122836-7777ff8a1ab1/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=

View file

@ -853,7 +853,7 @@ func FullTextSearchBlock(query string, boxes, paths []string, types map[string]b
beforeLen := 36
var blocks []*Block
orderByClause := buildOrderBy(method, orderBy)
orderByClause := buildOrderBy(query, method, orderBy)
switch method {
case 1: // 查询语法
filter := buildTypeFilter(types)
@ -992,7 +992,7 @@ func buildPathsFilter(paths []string) string {
return builder.String()
}
func buildOrderBy(method, orderBy int) string {
func buildOrderBy(query string, method, orderBy int) string {
switch orderBy {
case 1:
return "ORDER BY created ASC"
@ -1014,7 +1014,14 @@ func buildOrderBy(method, orderBy int) string {
}
return "ORDER BY rank" // 默认是按相关度降序
default:
return "ORDER BY sort ASC, updated DESC" // Improve search default sort https://github.com/siyuan-note/siyuan/issues/8624
clause := "ORDER BY CASE " +
"WHEN name = '${keyword}' THEN 10 " +
"WHEN alias = '${keyword}' THEN 20 " +
"WHEN name LIKE '%${keyword}%' THEN 50 " +
"WHEN alias LIKE '%${keyword}%' THEN 60 " +
"ELSE 65535 END ASC, sort ASC, updated DESC"
clause = strings.ReplaceAll(clause, "${keyword}", strings.ReplaceAll(query, "'", "''"))
return clause
}
}
@ -1146,21 +1153,21 @@ func fullTextSearchRefBlock(keyword string, beforeLen int, onlyDoc bool) (ret []
stmt += notLike.String()
}
orderBy := ` order by case
when name = '${keyword}' then 10
when alias = '${keyword}' then 20
when memo = '${keyword}' then 30
when content = '${keyword}' and type = 'd' then 40
when content LIKE '%${keyword}%' and type = 'd' then 41
when name LIKE '%${keyword}%' then 50
when alias LIKE '%${keyword}%' then 60
when content = '${keyword}' and type = 'h' then 70
when content LIKE '%${keyword}%' and type = 'h' then 71
when fcontent = '${keyword}' and type = 'i' then 80
when fcontent LIKE '%${keyword}%' and type = 'i' then 81
when memo LIKE '%${keyword}%' then 90
when content LIKE '%${keyword}%' and type != 'i' and type != 'l' then 100
else 65535 end ASC, sort ASC, length ASC`
orderBy := ` ORDER BY CASE
WHEN name = '${keyword}' THEN 10
WHEN alias = '${keyword}' THEN 20
WHEN memo = '${keyword}' THEN 30
WHEN content = '${keyword}' and type = 'd' THEN 40
WHEN content LIKE '%${keyword}%' and type = 'd' THEN 41
WHEN name LIKE '%${keyword}%' THEN 50
WHEN alias LIKE '%${keyword}%' THEN 60
WHEN content = '${keyword}' and type = 'h' THEN 70
WHEN content LIKE '%${keyword}%' and type = 'h' THEN 71
WHEN fcontent = '${keyword}' and type = 'i' THEN 80
WHEN fcontent LIKE '%${keyword}%' and type = 'i' THEN 81
WHEN memo LIKE '%${keyword}%' THEN 90
WHEN content LIKE '%${keyword}%' and type != 'i' and type != 'l' THEN 100
ELSE 65535 END ASC, sort ASC, length ASC`
orderBy = strings.ReplaceAll(orderBy, "${keyword}", strings.ReplaceAll(keyword, "'", "''"))
stmt += orderBy + " LIMIT " + strconv.Itoa(Conf.Search.Limit)
blocks := sql.SelectBlocksRawStmtNoParse(stmt, Conf.Search.Limit)

View file

@ -321,17 +321,26 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
// 根据搜索条件过滤
query = strings.TrimSpace(query)
if "" != query {
// 将连续空格转换为一个空格
query = strings.Join(strings.Fields(query), " ")
// 按空格分割关键字
keywords := strings.Split(query, " ")
// 使用 AND 逻辑 https://github.com/siyuan-note/siyuan/issues/11535
var hitRows []*av.TableRow
for _, row := range ret.Rows {
hit := false
for _, cell := range row.Cells {
allKeywordsHit := true
for _, keyword := range keywords {
if strings.Contains(strings.ToLower(cell.Value.String(true)), strings.ToLower(keyword)) {
hit = true
if !strings.Contains(strings.ToLower(cell.Value.String(true)), strings.ToLower(keyword)) {
allKeywordsHit = false
break
}
}
if allKeywordsHit {
hit = true
break
}
}
if hit {
hitRows = append(hitRows, row)