feat: Enhance search functionality in WikiPage repository and WikiBrowser component

- Updated the search logic in the WikiPage repository to use ILIKE for case-insensitive matching on title, content, summary, and slug fields, improving search accuracy.
- Added a watcher in the WikiBrowser component to reload all pages when the search query is cleared, enhancing user experience by ensuring relevant content is displayed immediately.

These changes collectively improve the search capabilities and responsiveness of the wiki interface.
This commit is contained in:
wizardchen
2026-04-07 21:31:58 +08:00
parent 0e28b2448c
commit 9be4152449
2 changed files with 14 additions and 4 deletions

View File

@@ -1046,6 +1046,13 @@ function drawLegend(svg: SVGSVGElement, width: number) {
}
// Load graph when switching to graph view
// Reload all pages when search query is cleared (backspace or clear button)
watch(searchQuery, (val) => {
if (!val || !val.trim()) {
loadPages()
}
})
watch(() => props.view, (v) => {
if (v === 'graph') loadGraph()
})

View File

@@ -244,13 +244,16 @@ func (r *wikiPageRepository) Search(ctx context.Context, kbID string, query stri
limit = 50
}
likePattern := "%" + query + "%"
var pages []*types.WikiPage
if err := r.db.WithContext(ctx).
Where("knowledge_base_id = ?", kbID).
Where("to_tsvector('simple', coalesce(title, '') || ' ' || coalesce(content, '')) @@ plainto_tsquery('simple', ?)", query).
Order("ts_rank(to_tsvector('simple', coalesce(title, '') || ' ' || coalesce(content, '')), plainto_tsquery('simple', ?)) DESC").
Where("knowledge_base_id = ? AND (title ILIKE ? OR content ILIKE ? OR summary ILIKE ? OR slug ILIKE ?)",
kbID, likePattern, likePattern, likePattern, likePattern).
Where("status != ?", "archived").
Order("updated_at DESC").
Limit(limit).
Find(&pages, query).Error; err != nil {
Find(&pages).Error; err != nil {
return nil, err
}
return pages, nil