mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 Improve search
This commit is contained in:
parent
f2971a273d
commit
4d7bd111e1
1 changed files with 14 additions and 22 deletions
|
|
@ -1016,7 +1016,11 @@ func FullTextSearchBlock(query string, boxes, paths []string, types map[string]b
|
||||||
typeFilter := buildTypeFilter(types)
|
typeFilter := buildTypeFilter(types)
|
||||||
boxFilter := buildBoxesFilter(boxes)
|
boxFilter := buildBoxesFilter(boxes)
|
||||||
pathFilter := buildPathsFilter(paths)
|
pathFilter := buildPathsFilter(paths)
|
||||||
blocks, matchedBlockCount, matchedRootCount = fullTextSearchByQuerySyntax(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderByClause, beforeLen, page, pageSize)
|
if ast.IsNodeIDPattern(query) {
|
||||||
|
blocks, matchedBlockCount, matchedRootCount = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+query+"'", beforeLen, page, pageSize)
|
||||||
|
} else {
|
||||||
|
blocks, matchedBlockCount, matchedRootCount = fullTextSearchByFTS(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderByClause, beforeLen, page, pageSize)
|
||||||
|
}
|
||||||
case 2: // SQL
|
case 2: // SQL
|
||||||
blocks, matchedBlockCount, matchedRootCount = searchBySQL(query, beforeLen, page, pageSize)
|
blocks, matchedBlockCount, matchedRootCount = searchBySQL(query, beforeLen, page, pageSize)
|
||||||
case 3: // 正则表达式
|
case 3: // 正则表达式
|
||||||
|
|
@ -1028,12 +1032,16 @@ func FullTextSearchBlock(query string, boxes, paths []string, types map[string]b
|
||||||
typeFilter := buildTypeFilter(types)
|
typeFilter := buildTypeFilter(types)
|
||||||
boxFilter := buildBoxesFilter(boxes)
|
boxFilter := buildBoxesFilter(boxes)
|
||||||
pathFilter := buildPathsFilter(paths)
|
pathFilter := buildPathsFilter(paths)
|
||||||
if 2 > len(strings.Split(strings.TrimSpace(query), " ")) {
|
if ast.IsNodeIDPattern(query) {
|
||||||
query = stringQuery(query)
|
blocks, matchedBlockCount, matchedRootCount = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+query+"'", beforeLen, page, pageSize)
|
||||||
blocks, matchedBlockCount, matchedRootCount = fullTextSearchByQuerySyntax(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderByClause, beforeLen, page, pageSize)
|
|
||||||
} else {
|
} else {
|
||||||
docMode = true // 文档全文搜索模式 https://github.com/siyuan-note/siyuan/issues/10584
|
if 2 > len(strings.Split(strings.TrimSpace(query), " ")) {
|
||||||
blocks, matchedBlockCount, matchedRootCount = fullTextSearchByKeyword(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderByClause, beforeLen, page, pageSize)
|
query = stringQuery(query)
|
||||||
|
blocks, matchedBlockCount, matchedRootCount = fullTextSearchByFTS(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderByClause, beforeLen, page, pageSize)
|
||||||
|
} else {
|
||||||
|
docMode = true // 文档全文搜索模式 https://github.com/siyuan-note/siyuan/issues/10584
|
||||||
|
blocks, matchedBlockCount, matchedRootCount = fullTextSearchByLikeWithRoot(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderByClause, beforeLen, page, pageSize)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pageCount = (matchedBlockCount + pageSize - 1) / pageSize
|
pageCount = (matchedBlockCount + pageSize - 1) / pageSize
|
||||||
|
|
@ -1367,22 +1375,6 @@ func extractID(content string) (ret string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func fullTextSearchByQuerySyntax(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderBy string, beforeLen, page, pageSize int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
|
||||||
if ast.IsNodeIDPattern(query) {
|
|
||||||
ret, matchedBlockCount, matchedRootCount = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+query+"'", beforeLen, page, pageSize)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return fullTextSearchByFTS(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderBy, beforeLen, page, pageSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
func fullTextSearchByKeyword(query, boxFilter, pathFilter, typeFilter, ignoreFilter string, orderBy string, beforeLen, page, pageSize int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
|
||||||
if ast.IsNodeIDPattern(query) {
|
|
||||||
ret, matchedBlockCount, matchedRootCount = searchBySQL("SELECT * FROM `blocks` WHERE `id` = '"+query+"'", beforeLen, page, pageSize)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return fullTextSearchByLikeWithRoot(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderBy, beforeLen, page, pageSize)
|
|
||||||
}
|
|
||||||
|
|
||||||
func fullTextSearchByRegexp(exp, boxFilter, pathFilter, typeFilter, ignoreFilter, orderBy string, beforeLen, page, pageSize int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
func fullTextSearchByRegexp(exp, boxFilter, pathFilter, typeFilter, ignoreFilter, orderBy string, beforeLen, page, pageSize int) (ret []*Block, matchedBlockCount, matchedRootCount int) {
|
||||||
fieldFilter := fieldRegexp(exp)
|
fieldFilter := fieldRegexp(exp)
|
||||||
stmt := "SELECT * FROM `blocks` WHERE " + fieldFilter + " AND type IN " + typeFilter
|
stmt := "SELECT * FROM `blocks` WHERE " + fieldFilter + " AND type IN " + typeFilter
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue