An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Return document blocks when search hits different block content https://github.com/siyuan-note/siyuan/issues/10584
Daniel6c36e9e583c8
diff --git a/kernel/model/search.go b/kernel/model/search.goindex 184f88b255..fbd64ffe7b 100644--- a/kernel/model/search.go+++ b/kernel/model/search.go@@ -1382,9 +1382,6 @@ func fullTextSearchCountByFTS(query, boxFilter, pathFilter, typeFilter, ignoreFifunc fullTextSearchByFTSWithRoot(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderBy string, beforeLen, page, pageSize int) (ret []*Block, matchedBlockCount, matchedRootCount int) {start := time.Now()- defer func() {- logging.LogInfof("time cost: %v", time.Since(start))- }()table := "blocks_fts" // 大小写敏感if !Conf.Search.CaseSensitive {@@ -1407,10 +1404,14 @@ func fullTextSearchByFTSWithRoot(query, boxFilter, pathFilter, typeFilter, ignor" FROM " + table + " WHERE type IN " + typeFilter + boxFilter + pathFilter + ignoreFilter +" GROUP BY root_id HAVING " + likeFiltercteStmt := "WITH docBlocks AS (" + dMatchStmt + "), nonDocBlocks AS (" + bMatchStmt + ")"- cteStmt += "\nSELECT * FROM " + table + " WHERE id IN (SELECT id FROM nonDocBlocks) OR id IN (SELECT root_id FROM docBlocks)"- countStmt := cteStmt+ wheheClause := " WHERE id IN (SELECT id FROM nonDocBlocks) OR id IN (SELECT root_id FROM docBlocks)"+ selectStmt := cteStmt + "\nSELECT * FROM " + table + wheheClause+ countStmt := cteStmt + "\nSELECT COUNT(id) AS `matches`, COUNT(DISTINCT(root_id)) AS `docs` FROM " + table + wheheClausecteStmt += orderBy + " LIMIT " + strconv.Itoa(pageSize) + " OFFSET " + strconv.Itoa((page-1)*pageSize)- resultBlocks := sql.SelectBlocksRawStmtNoParse(cteStmt, -1)+ resultBlocks := sql.SelectBlocksRawStmtNoParse(selectStmt, -1)++ logging.LogInfof("time cost [main search]: %v", time.Since(start))+ now := time.Now()// FTS 高亮projections := "id, parent_id, root_id, hash, box, path, " +@@ -1441,12 +1442,15 @@ func fullTextSearchByFTSWithRoot(query, boxFilter, pathFilter, typeFilter, ignorret = []*Block{}}+ logging.LogInfof("time cost [highlight search]: %v", time.Since(now))+ now = time.Now()matchedBlockCount, matchedRootCount = fullTextSearchCountByStmt(countStmt)+ logging.LogInfof("time cost [count search]: %v", time.Since(now))+ logging.LogInfof("time cost [all]: %v", time.Since(start))return}func fullTextSearchCountByStmt(stmt string) (matchedBlockCount, matchedRootCount int) {- stmt = "SELECT COUNT(id) AS `matches`, COUNT(DISTINCT(root_id)) AS `docs` FROM (" + stmt + ")"result, _ := sql.QueryNoLimit(stmt)if 1 > len(result) {return