mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-06-04 13:30:32 +08:00
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:
@@ -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()
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user