From 86684d665e2f2f9bb865004e8995a5c110ddcbc2 Mon Sep 17 00:00:00 2001
From: ax_rd <ax_rd@aisim.cn>
Date: Thu, 03 Sep 2026 11:56:04 +0800
Subject: [PATCH] feat: RWR 图结构排序 + CJK LIKE 混合检索 + 双信号加权 + aliases/status 参与排序

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

diff --git a/cmd/search.go b/cmd/search.go
index e7e31a1..379d3cf 100644
--- a/cmd/search.go
+++ b/cmd/search.go
@@ -7,6 +7,7 @@
 
 	"github.com/aisim/kb-cli/internal/index"
 	"github.com/aisim/kb-cli/internal/search"
+	"github.com/aisim/kb-cli/internal/llm"
 	"github.com/aisim/kb-cli/internal/output"
 	"github.com/spf13/cobra"
 )
@@ -50,16 +51,16 @@
 	}
 	defer store.Close()
 
-	// 检查是否需要重建索引
-	needsRebuild, commit, err := index.NeedsRebuild(store, vaultPath)
+	// pre-flight:快速检查索引是否有变更(只 stat 比对,不读内容)
+	dirty, err := index.QuickCheck(store, vaultPath)
 	if err != nil {
 		return fmt.Errorf("检查索引状态失败: %w", err)
 	}
 
-	if needsRebuild {
-		fmt.Fprintln(os.Stderr, "索引过期,正在重建...")
-		if err := rebuildIndex(store, commit); err != nil {
-			return fmt.Errorf("重建索引失败: %w", err)
+	if dirty {
+		fmt.Fprintln(os.Stderr, "索引有变更,正在增量同步...")
+		if err := syncIndex(store); err != nil {
+			return fmt.Errorf("增量同步失败: %w", err)
 		}
 	}
 
@@ -76,12 +77,18 @@
 	}
 
 	// 执行搜索
+	cfg := llm.LoadConfig()
+	textWeight := cfg.Search.TextWeight
+	if textWeight <= 0 || textWeight > 1 {
+		textWeight = 0.5 // 缺省 0.5
+	}
 	opts := search.SearchOptions{
 		Expanded:    expanded,
 		Symptom:     symptom,
 		TopN:        topN,
 		WithContent: withContent,
 		WithLinks:   withLinks,
+		TextWeight:  textWeight,
 	}
 
 	results, err := search.Search(store, allKeywords, opts)

--
Gitblit v1.10.0