feat: restore global search in app header

This commit is contained in:
2026-06-06 02:39:29 +08:00
parent cf770262e5
commit 0cd8a79049
15 changed files with 513 additions and 65 deletions
+7 -2
View File
@@ -11,6 +11,7 @@ type Result struct {
NodeID string `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
Path string `json:"path,omitempty"`
Snippet string `json:"snippet,omitempty"`
}
@@ -61,7 +62,7 @@ func (s *Service) Search(query string) ([]Result, error) {
fts := sanitizeFTS(query)
rows, err := s.db.Query(
`SELECT node_id, title, type, snippet(search_index, 0, '', '', '...', 32) as snip
`SELECT node_id, title, type, path, snippet(search_index, 0, '', '', '...', 32) as snip
FROM search_index WHERE search_index MATCH ?
ORDER BY rank LIMIT 20`, fts)
if err != nil {
@@ -74,9 +75,13 @@ func (s *Service) Search(query string) ([]Result, error) {
for rows.Next() {
var r Result
var snip sqlNullString
if err := rows.Scan(&r.NodeID, &r.Title, &r.Type, &snip); err != nil {
var path sqlNullString
if err := rows.Scan(&r.NodeID, &r.Title, &r.Type, &path, &snip); err != nil {
return nil, err
}
if path.Valid {
r.Path = path.String
}
if snip.Valid {
r.Snippet = snip.String
}