Bläddra i källkod

:art: 嵌入块支持搜索 https://github.com/siyuan-note/siyuan/issues/7112

Liang Ding 2 år sedan
förälder
incheckning
1e2a707e02
4 ändrade filer med 26 tillägg och 6 borttagningar
  1. 2 1
      kernel/model/block.go
  2. 19 0
      kernel/model/render.go
  3. 3 3
      kernel/model/search.go
  4. 2 2
      kernel/model/transaction.go

+ 2 - 1
kernel/model/block.go

@@ -457,7 +457,8 @@ func getEmbeddedBlock(embedBlockID string, trees map[string]*parse.Tree, sqlBloc
 	luteEngine := NewLute()
 	luteEngine.RenderOptions.ProtyleContenteditable = false // 不可编辑
 	dom := renderBlockDOMByNodes(nodes, luteEngine)
-	block = &Block{Box: def.Box, Path: def.Path, HPath: b.HPath, ID: def.ID, Type: def.Type.String(), Content: dom}
+	content := renderBlockContentByNodes(nodes)
+	block = &Block{Box: def.Box, Path: def.Path, HPath: b.HPath, ID: def.ID, Type: def.Type.String(), Content: dom, Markdown: content /* 这里使用 Markdown 字段来临时存储 content */}
 
 	// 位于超级块中的嵌入块不显示面包屑 https://github.com/siyuan-note/siyuan/issues/6258
 	inSuperBlock := false

+ 19 - 0
kernel/model/render.go

@@ -118,6 +118,25 @@ func renderBlockDOMByNodes(nodes []*ast.Node, luteEngine *lute.Lute) string {
 	return h
 }
 
+func renderBlockContentByNodes(nodes []*ast.Node) string {
+	var subNodes []*ast.Node
+	for _, n := range nodes {
+		if ast.NodeDocument == n.Type {
+			for c := n.FirstChild; nil != c; c = c.Next {
+				subNodes = append(subNodes, c)
+			}
+		} else {
+			subNodes = append(subNodes, n)
+		}
+	}
+
+	buf := bytes.Buffer{}
+	for _, n := range subNodes {
+		buf.WriteString(treenode.NodeStaticContent(n, nil))
+	}
+	return buf.String()
+}
+
 func renderBlockMarkdownR(id string) string {
 	var rendered []string
 	nodes := renderBlockMarkdownR0(id, &rendered)

+ 3 - 3
kernel/model/search.go

@@ -70,9 +70,6 @@ func searchEmbedBlock(embedBlockID, stmt string, excludeIDs []string, headingMod
 	}
 	sqlBlocks = tmp
 
-	// 嵌入块支持搜索 https://github.com/siyuan-note/siyuan/issues/7112
-	task.AppendTask(task.DatabaseIndexEmbedBlock, updateEmbedBlockContent, embedBlockID, sqlBlocks)
-
 	// 缓存最多 128 棵语法树
 	trees := map[string]*parse.Tree{}
 	count := 0
@@ -101,6 +98,9 @@ func searchEmbedBlock(embedBlockID, stmt string, excludeIDs []string, headingMod
 		})
 	}
 
+	// 嵌入块支持搜索 https://github.com/siyuan-note/siyuan/issues/7112
+	task.AppendTask(task.DatabaseIndexEmbedBlock, updateEmbedBlockContent, embedBlockID, ret)
+
 	// 添加笔记本名称
 	var boxIDs []string
 	for _, embedBlock := range ret {

+ 2 - 2
kernel/model/transaction.go

@@ -1244,14 +1244,14 @@ func autoIndexEmbedBlock(embedBlocks []*sql.Block) {
 	}
 }
 
-func updateEmbedBlockContent(embedBlockID string, queryResultBlocks []*sql.Block) {
+func updateEmbedBlockContent(embedBlockID string, queryResultBlocks []*EmbedBlock) {
 	embedBlock := sql.GetBlock(embedBlockID)
 	if nil == embedBlock {
 		return
 	}
 
 	for _, block := range queryResultBlocks {
-		embedBlock.Content += block.Content
+		embedBlock.Content += block.Block.Markdown
 	}
 	if "" == embedBlock.Content {
 		embedBlock.Content = "no query result"