From 1196f409d86bc61e7596eb274840244a62ce84ba Mon Sep 17 00:00:00 2001
From: ai_xiaopei <xiaopei@aisim.cn>
Date: Wed, 29 Jul 2026 14:58:19 +0800
Subject: [PATCH] feat: config priority over env vars, export LoadConfig, add review feature

---
 cmd/search.go |   21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/cmd/search.go b/cmd/search.go
index d2787a1..e7e31a1 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,7 +23,8 @@
 var searchCmd = &cobra.Command{
 	Use:   "search [keywords...]",
 	Short: "搜索知识库",
-	Long:  `搜索知识库,支持关键词、扩展词、症状词`,
+	Long:  `# search - 搜索
+kb-cli search <关键词> [--top N] [--expanded <词>] [--symptom <词>] [--with-content] [--with-links] [--json] # 搜索知识库,支持关键词、扩展词、症状词`,
 	Args:  cobra.MinimumNArgs(1),
 	RunE:  runSearch,
 }
@@ -35,6 +37,9 @@
 	searchCmd.Flags().BoolVar(&jsonOut, "json", false, "JSON 格式输出")
 	searchCmd.Flags().BoolVar(&withContent, "with-content", false, "返回完整文件内容")
 	searchCmd.Flags().BoolVar(&withLinks, "with-links", false, "显示关联文档链接")
+	
+	// 参数不足时显示 help
+	searchCmd.SetUsageTemplate(searchCmd.Long)
 }
 
 func runSearch(cmd *cobra.Command, args []string) error {
@@ -58,6 +63,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,
@@ -67,7 +84,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