From 9c98026d5490ebb2ac9465d565319d77f6d505b4 Mon Sep 17 00:00:00 2001
From: ai_xiaopei <xiaopei@aisim.cn>
Date: Sun, 26 Jul 2026 13:21:50 +0800
Subject: [PATCH] fix: 修复草稿创建时知识库搜索失败问题
---
cmd/search.go | 36 ++++++++++++++++++------------------
1 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/cmd/search.go b/cmd/search.go
index 6552d88..88c0065 100644
--- a/cmd/search.go
+++ b/cmd/search.go
@@ -3,6 +3,7 @@
import (
"fmt"
"os"
+ "strings"
"github.com/aisim/kb-cli/internal/index"
"github.com/aisim/kb-cli/internal/search"
@@ -22,23 +23,10 @@
var searchCmd = &cobra.Command{
Use: "search [keywords...]",
Short: "搜索知识库",
- Long: `# search - 搜索
-kb-cli search <关键词> [flags]
-
-参数:
- <关键词> 搜索关键词(必填,支持多个)
- --top N 返回前 N 条结果(默认 10)
- --expanded <词> 扩展词(提升相关实体权重,支持多个)
- --symptom <词> 症状词(针对具体症状,支持多个)
- --with-content 返回完整文件内容
- --with-links 显示关联文档链接
- --json JSON 格式输出
-
-全局参数:
- --vault <路径> 知识库根目录(默认:~/aisim/note/001/笔记001)
- --db <路径> 索引数据库路径(默认:~/.cache/kb-cli/kb.db)`,
- Args: cobra.MinimumNArgs(1),
- RunE: runSearch,
+ Long: `# search - 搜索
+kb-cli search <关键词> [--top N] [--expanded <词>] [--symptom <词>] [--with-content] [--with-links] [--json] # 搜索知识库,支持关键词、扩展词、症状词`,
+ Args: cobra.MinimumNArgs(1),
+ RunE: runSearch,
}
func init() {
@@ -72,6 +60,18 @@
}
}
+ // 合并所有关键词(支持空格分隔和引号分隔)
+ var allKeywords []string
+ for _, arg := range args {
+ // 如果参数包含空格,按空格分割
+ parts := strings.Fields(arg)
+ allKeywords = append(allKeywords, parts...)
+ }
+
+ if len(allKeywords) == 0 {
+ return fmt.Errorf("请提供至少一个关键词")
+ }
+
// 执行搜索
opts := search.SearchOptions{
Expanded: expanded,
@@ -81,7 +81,7 @@
WithLinks: withLinks,
}
- results, err := search.Search(store, args, opts)
+ results, err := search.Search(store, allKeywords, opts)
if err != nil {
return fmt.Errorf("搜索失败: %w", err)
}
--
Gitblit v1.9.1