| | |
| | | |
| | | // SearchOptions 搜索选项 |
| | | type SearchOptions struct { |
| | | Expanded []string // 扩展词 |
| | | Symptom []string // 症状词 |
| | | TopN int // 返回前 N 条 |
| | | Expanded []string // 扩展词 |
| | | Symptom []string // 症状词 |
| | | TopN int // 返回前 N 条 |
| | | WithContent bool // 返回完整文件内容 |
| | | WithLinks bool // 返回关联文档链接 |
| | | } |
| | | |
| | | // SearchResult 搜索结果 |
| | | type SearchResult struct { |
| | | ID int64 |
| | | Path string |
| | | Title string |
| | | Section string |
| | | Score int |
| | | ID int64 `json:"id"` |
| | | Path string `json:"path"` |
| | | Title string `json:"title"` |
| | | Section string `json:"section"` |
| | | Score int `json:"score"` |
| | | Content string `json:"content,omitempty"` // 文件内容(WithContent=true 时填充) |
| | | Links []string `json:"links,omitempty"` // 关联文档路径(WithLinks=true 时填充) |
| | | } |
| | | |
| | | // Search 执行搜索 |
| | |
| | | results = results[:opts.TopN] |
| | | } |
| | | |
| | | // 获取内容(如果请求) |
| | | if opts.WithContent { |
| | | for i := range results { |
| | | content, _, _, err := store.GetNodeContent(results[i].ID) |
| | | if err == nil { |
| | | results[i].Content = content |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 获取关联链接(如果请求) |
| | | if opts.WithLinks { |
| | | for i := range results { |
| | | links, err := store.GetNodeLinks(results[i].ID) |
| | | if err == nil { |
| | | results[i].Links = links |
| | | } |
| | | } |
| | | } |
| | | |
| | | return results, nil |
| | | } |
| | | |