docs(comments): 注释中文化 · internal/runtime/memory(31 文件,纯替换)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

- 只翻注释/文档字符串:820 增 / 820 删 严格 1:1;剥掉整行注释与行尾注释尾巴后,
  逐文件与 HEAD 比对「代码部分差异 = 0」;裁决/design 编号计数逐项与 HEAD 一致
- 保留可执行 SQL 样例、SQLite 报错原文、pgvector/HNSW/ANN/BLOB 等技术词原文
- 复核:go build 绿 + memory/projectindex/vector 三包测试绿;gofmt 仅剩 2 个既有未格式化文件(改动前即如此,未顺手修)
This commit is contained in:
AskaEth committed 2026-10-04 13:32:54 +08:00
1 parent eb1828ee7a
commit 61cf80d5ee
31 files changed
+820 -820

No files matched your search

+25 -25
View File
@@ -5,42 +5,42 @@ import (
"strings"
)
// contextRadius is the number of lines shown on each side of a matched line in
// LineMatch.Context.
// contextRadius 是 LineMatch.Context 中匹配行每侧的
// 显示行数。
const contextRadius = 2
// LineMatch is a single matched line inside a chapter's content plus its
// surrounding context. LineNumber is 1-based within the chapter's Content.
// LineMatch 是章节内容中的一条匹配行及其
// 周边上下文。LineNumber 在章节的 Content 中以 1 为基。
type LineMatch struct {
LineNumber int
Text string
Context string
}
// ChapterHit is a chapter whose content matched a keyword, with the located
// lines (and their context) that matched.
// ChapterHit 是内容命中关键词的一个章节,附带定位到的
// 匹配行(及其上下文)。
type ChapterHit struct {
Chapter *Chapter
Matches []LineMatch
}
// SearchResult is the hierarchical result of a Search. Project carries the
// matched project index entry + description (layer 1/2), set only when the
// keyword hits the project title or desc; Chapters carries the matched chapters
// (layer 3) with located lines. When nothing matches, Project is nil and
// Chapters is empty, with no error.
// SearchResult 是一次 Search 的分层结果。Project 携带命中的
// 项目索引条目 + 描述(第 1/2 层),仅当关键词命中
// 项目标题或 desc 时设置;Chapters 携带命中的章节
// (第 3 层)及定位到的行。无任何命中时,Project 为 nil,
// Chapters 为空,且不报错。
type SearchResult struct {
Project *Project
Chapters []ChapterHit
}
// Search looks up keyword within a single project, walking the hierarchy
// 项目索引 → 项目描述 → 章节内容. It first loads the project (ErrProjectNotFound
// when it does not exist), sets SearchResult.Project when the keyword hits the
// project title or description, then scans every chapter for content hits,
// producing located lines plus their context. A blank keyword returns
// ErrMissingKeyword; a keyword that hits nothing returns a non-nil SearchResult
// with Project and Chapters unset.
// Search 在单个项目内查找关键词,沿层级
// 项目索引 → 项目描述 → 章节内容 遍历。它先加载项目(不存在时返回
// ErrProjectNotFound),当关键词命中
// 项目标题或描述时设置 SearchResult.Project,然后扫描每个章节找内容命中,
// 产出定位到的行及其上下文。关键词为空返回
// ErrMissingKeyword;未命中任何内容的关键词返回非 nil 的 SearchResult,
// 其中 Project 与 Chapters 不设置。
func (s *Store) Search(ctx context.Context, projectID, keyword string) (*SearchResult, error) {
kw := strings.ToLower(strings.TrimSpace(keyword))
if kw == "" {
@@ -69,15 +69,15 @@ func (s *Store) Search(ctx context.Context, projectID, keyword string) (*SearchR
return result, nil
}
// containsFold reports whether s (case-insensitively) contains sub, which must
// already be lowercased by the caller.
// containsFold 报告 s 是否(不区分大小写地)包含 sub,
// sub 必须已由调用方转为小写。
func containsFold(s, sub string) bool {
return strings.Contains(strings.ToLower(s), sub)
}
// findLineMatches returns one LineMatch per content line that (case-insensitively)
// contains keyword. Context is the surrounding contextRadius lines on each side,
// joined by newlines and including the matched line.
// findLineMatches 为每行(不区分大小写地)包含 keyword 的内容返回一个
// LineMatch。Context 是每侧 contextRadius 行的周边上下文,
// 以换行连接,并包含匹配行本身。
func findLineMatches(content, keyword string) []LineMatch {
lines := strings.Split(content, "\n")
matches := make([]LineMatch, 0)
@@ -93,8 +93,8 @@ func findLineMatches(content, keyword string) []LineMatch {
return matches
}
// buildContext returns lines[start..end] around idx (inclusive) joined by \n,
// clamped to the slice bounds so the context never overflows.
// buildContext 返回 idx 周围(含 idx)的 lines[start..end],以 \n 连接,
// 并夹到切片边界内,因此上下文绝不会越界。
func buildContext(lines []string, idx int) string {
start := idx - contextRadius
if start < 0 {