Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

Implement body search for notes

Smaug6739afcbc6aaac3e
diff --git a/backend/controllers/nodes.controller.go b/backend/controllers/nodes.controller.go
index b21ccfad..35c49a8d 100644
--- a/backend/controllers/nodes.controller.go
+++ b/backend/controllers/nodes.controller.go
@@ -6,6 +6,7 @@ import (
"alexandrie/permissions"
"alexandrie/utils"
"net/http"
+ "strconv"
"github.com/gin-gonic/gin"
)
@@ -18,6 +19,7 @@ type NodeController interface {
CreateNode(c *gin.Context) (int, any)
UpdateNode(c *gin.Context) (int, any)
DeleteNode(c *gin.Context) (int, any)
+ SearchNodes(c *gin.Context) (int, any)
}
func NewNodeController(app *app.App) NodeController {
@@ -147,3 +149,36 @@ func (ctr *Controller) DeleteNode(c *gin.Context) (int, any) {
}
return http.StatusOK, "OK"
}
+
+// SearchNodes performs a fulltext search on user's documents
+// Query params:
+// - q: search query (required, min 2 chars)
+// - content: include content body in search (optional, default false)
+// - limit: max results (optional, default 20, max 100)
+func (ctr *Controller) SearchNodes(c *gin.Context) (int, any) {
+ connectedUserId, _, err := utils.GetUserContext(c)
+ if err != nil {
+ return http.StatusUnauthorized, err
+ }
+
+ query := c.Query("q")
+ if len(query) < 2 {
+ return http.StatusBadRequest, "Search query must be at least 2 characters"
+ }
+
+ includeContent := c.Query("content") == "true"
+
+ limit := 20
+ if limitStr := c.Query("limit"); limitStr != "" {
+ if parsedLimit, err := strconv.Atoi(limitStr); err == nil && parsedLimit > 0 {
+ limit = parsedLimit
+ }
+ }
+
+ results, err := ctr.app.Services.Node.SearchNodes(connectedUserId, query, includeContent, limit)
+ if err != nil {
+ return http.StatusInternalServerError, err
+ }
+
+ return http.StatusOK, results
+}
diff --git a/backend/migrations/000013_fulltext_search.down.sql b/backend/migrations/000013_fulltext_search.down.sql
new file mode 100644
index 00000000..0e6bb2f5
--- /dev/null
+++ b/backend/migrations/000013_fulltext_search.down.sql
@@ -0,0 +1,6 @@
+-- ========================================
+-- Remove FULLTEXT indexes
+-- ========================================
+
+ALTER TABLE `nodes` DROP INDEX `ft_nodes_search`;
+ALTER TABLE `nodes` DROP INDEX `ft_nodes_content`;
diff --git a/backend/migrations/000013_fulltext_search.up.sql b/backend/migrations/000013_fulltext_search.up.sql
new file mode 100644
index 00000000..749d9cff
--- /dev/null
+++ b/backend/migrations/000013_fulltext_search.up.sql
@@ -0,0 +1,12 @@
+-- ========================================
+-- Add FULLTEXT index for content search
+-- ========================================
+
+-- Create FULLTEXT index on name, description, tags, and content
+-- This allows efficient full-text search without using LIKE '%...%'
+ALTER TABLE `nodes`
+ADD FULLTEXT INDEX `ft_nodes_search` (`name`, `description`, `tags`, `content`);
+
+-- Also add a separate index for just the content (body) search
+ALTER TABLE `nodes`
+ADD FULLTEXT INDEX `ft_nodes_content` (`content`);
diff --git a/backend/models/node.model.go b/backend/models/node.model.go
index b72a22cd..0054cf51 100644
--- a/backend/models/node.model.go
+++ b/backend/models/node.model.go
@@ -29,3 +29,18 @@ type Node struct {
// Relations
Permissions []*Permission `json:"permissions" form:"permissions" binding:"omitempty"`
}
+
+// NodeSearchResult represents a search result with relevance score and content snippet
+type NodeSearchResult struct {
+ Id types.Snowflake `json:"id"`
+ UserId types.Snowflake `json:"user_id"`
+ ParentId *types.Snowflake `json:"parent_id"`
+ Name string `json:"name"`
+ Description *string `json:"description"`
+ Tags *string `json:"tags"`
+ Role int `json:"role"`
+ Icon *string `json:"icon"`
+ Relevance float64 `json:"relevance"`
+ ContentSnippet *string `json:"content_snippet,omitempty"`
+ UpdatedTimestamp int64 `json:"updated_timestamp"`
+}
diff --git a/backend/repositories/node.repository.go b/backend/repositories/node.repository.go
index e7b7c4f4..8f829d8a 100644
--- a/backend/repositories/node.repository.go
+++ b/backend/repositories/node.repository.go
@@ -25,6 +25,7 @@ type NodeRepository interface {
Create(node *models.Node) error
Update(node *models.Node) error
Delete(nodeId types.Snowflake) error
+ SearchFulltext(userId types.Snowflake, query string, includeContent bool, limit int) ([]*models.NodeSearchResult, error)
}
// Prepared statement keys
@@ -38,6 +39,8 @@ const (
stmtNodeCreate = "node_create"
stmtNodeUpdate = "node_update"
stmtNodeDelete = "node_delete"
+ stmtNodeSearchFulltext = "node_search_fulltext"
+ stmtNodeSearchContent = "node_search_content"
// Note: GetAll and GetShared use complex recursive CTEs, prepared separately
)
@@ -135,6 +138,32 @@ func (r *NodeRepositoryImpl) prepareStatements() error {
stmtNodeDelete: `
DELETE FROM nodes
WHERE id = ?`,
+
+ // FULLTEXT search on name, description, tags only (faster, for quick search)
+ stmtNodeSearchFulltext: `
+ SELECT n.id, n.user_id, n.parent_id, n.name, n.description, n.tags, n.role, n.icon,
+ MATCH(n.name, n.description, n.tags, n.content) AGAINST(? IN NATURAL LANGUAGE MODE) AS relevance,
+ NULL AS content_snippet,
+ n.updated_timestamp
+ FROM nodes n
+ WHERE n.user_id = ? AND n.role = 3
+ AND MATCH(n.name, n.description, n.tags, n.content) AGAINST(? IN NATURAL LANGUAGE MODE)
+ ORDER BY relevance DESC
+ LIMIT ?`,
+
+ // FULLTEXT search including content body (for content search)
+ stmtNodeSearchContent: `
+ SELECT n.id, n.user_id, n.parent_id, n.name, n.description, n.tags, n.role, n.icon,
+ MATCH(n.content) AGAINST(? IN NATURAL LANGUAGE MODE) AS relevance,
+ SUBSTRING(n.content,
+ GREATEST(1, LOCATE(?, LOWER(n.content)) - 50),
+ 200) AS content_snippet,
+ n.updated_timestamp
+ FROM nodes n
+ WHERE n.user_id = ? AND n.role = 3
+ AND MATCH(n.content) AGAINST(? IN NATURAL LANGUAGE MODE)
+ ORDER BY relevance DESC
+ LIMIT ?`,
}
// Prepare all statements
@@ -498,3 +527,75 @@ func (r *NodeRepositoryImpl) Delete(nodeId types.Snowflake) error {
return nil
}
+
+// SearchFulltext performs a FULLTEXT search on nodes
+// If includeContent is true, it searches in the content body as well
+func (r *NodeRepositoryImpl) SearchFulltext(userId types.Snowflake, query string, includeContent bool, limit int) ([]*models.NodeSearchResult, error) {
+ if limit <= 0 {
+ limit = 20
+ }
+ if limit > 100 {
+ limit = 100
+ }
+
+ // Prepare the search query for MySQL FULLTEXT
+ // Clean the query for safety
+ cleanQuery := strings.TrimSpace(query)
+ if len(cleanQuery) < 2 {
+ return []*models.NodeSearchResult{}, nil
+ }
+
+ var stmtKey string
+ if includeContent {
+ stmtKey = stmtNodeSearchContent
+ } else {
+ stmtKey = stmtNodeSearchFulltext
+ }
+
+ stmt, err := r.manager.GetStatement(stmtKey)
+ if err != nil {
+ return nil, err
+ }
+
+ var rows *sql.Rows
+ if includeContent {
+ // For content search, we need the query for MATCH, for LOCATE (snippet), userId, and limit
+ rows, err = stmt.Query(cleanQuery, strings.ToLower(cleanQuery), userId, cleanQuery, limit)
+ } else {
+ // For fulltext search: query for MATCH, userId, query for MATCH again, and limit
+ rows, err = stmt.Query(cleanQuery, userId, cleanQuery, limit)
+ }
+
+ if err != nil {
+ return nil, fmt.Errorf("failed to execute fulltext search: %w", err)
+ }
+ defer rows.Close()
+
+ results := make([]*models.NodeSearchResult, 0)
+ for rows.Next() {
+ var result models.NodeSearchResult
+ err := rows.Scan(
+ &result.Id,
+ &result.UserId,
+ &result.ParentId,
+ &result.Name,
+ &result.Description,
+ &result.Tags,
+ &result.Role,
+ &result.Icon,
+ &result.Relevance,
+ &result.ContentSnippet,
+ &result.UpdatedTimestamp,
+ )
+ if err != nil {
+ return nil, fmt.Errorf("failed to scan search result: %w", err)
+ }
+ results = append(results, &result)
+ }
+
+ if err = rows.Err(); err != nil {
+ return nil, fmt.Errorf("error iterating search results: %w", err)
+ }
+
+ return results, nil
+}
diff --git a/backend/router/routes/nodes.go b/backend/router/routes/nodes.go
index a0aae936..dc62ef6d 100644
--- a/backend/router/routes/nodes.go
+++ b/backend/router/routes/nodes.go
@@ -14,6 +14,7 @@ func Nodes(app *app.App, router *gin.RouterGroup) {
nodeCtrl := controllers.NewNodeController(app)
node.GET("/public/:id", utils.WP(nodeCtrl.GetPublicNode))
+ node.GET("/search", middlewares.Auth(), utils.WP(nodeCtrl.SearchNodes))
node.GET("/shared/:userId", middlewares.Auth(), utils.WP(nodeCtrl.GetSharedNodes))
node.GET("/:userId", middlewares.Auth(), utils.WP(nodeCtrl.GetNodes))
node.GET("/:userId/:id", middlewares.Auth(), utils.WP(nodeCtrl.GetNode))
diff --git a/backend/services/node.service.go b/backend/services/node.service.go
index 65d4e9ae..3e5df6e9 100644
--- a/backend/services/node.service.go
+++ b/backend/services/node.service.go
@@ -20,6 +20,7 @@ type NodeService interface {
CreateNode(node *models.Node, userId types.Snowflake) (*models.Node, error)
UpdateNode(nodeId types.Snowflake, node *models.Node, connectedUserId types.Snowflake, connectedUserRole permissions.UserRole, authorizer permissions.Authorizer) (*models.Node, error)
DeleteNode(nodeId types.Snowflake, connectedUserId types.Snowflake, connectedUserRole permissions.UserRole, authorizer permissions.Authorizer) error
+ SearchNodes(userId types.Snowflake, query string, includeContent bool, limit int) ([]*models.NodeSearchResult, error)
}
type nodeService struct {
@@ -194,3 +195,8 @@ func (s *nodeService) DeleteNode(nodeId types.Snowflake, connectedUserId types.S
return s.nodeRepo.Delete(nodeId)
}
+
+// SearchNodes performs a fulltext search on user's documents
+func (s *nodeService) SearchNodes(userId types.Snowflake, query string, includeContent bool, limit int) ([]*models.NodeSearchResult, error) {
+ return s.nodeRepo.SearchFulltext(userId, query, includeContent, limit)
+}
diff --git a/frontend/app/components/CommandCenter/AdvancedSearchTab.vue b/frontend/app/components/CommandCenter/AdvancedSearchTab.vue
index 8d39bfdb..8832c93c 100644
--- a/frontend/app/components/CommandCenter/AdvancedSearchTab.vue
+++ b/frontend/app/components/CommandCenter/AdvancedSearchTab.vue
@@ -3,38 +3,44 @@
<div class="search-filters">
<div class="filters-header">
<h3 class="filters-title">Advanced Filters</h3>
- <button class="toggle-filters-btn" :class="{ collapsed: !showFilters }" @click="toggleFilters">
- <Icon :name="showFilters ? 'collapse' : 'expand'" />
- </button>
+ <span class="filters-actions">
+ <button class="clear-filters-btn" @click="clearFilters">Clear</button>
+ <button class="toggle-filters-btn" :class="{ collapsed: !showFilters }" @click="toggleFilters">
+ <Icon :name="showFilters ? 'collapse' : 'expand'" />
+ </button>
+ </span>
</div>
<div v-show="showFilters" class="filters-content">
- <div class="filter-group">
+ <div class="filter-group full-width">
<label class="filter-label">Date Range</label>
- <div class="date-filters">
- <div class="date-input">
- <label>From</label>
- <input v-model="dateFrom" type="date" class="date-picker" />
+ <div class="date-row">
+ <div class="date-filters">
+ <div class="date-input">
+ <label>From</label>
+ <input v-model="searchQuery.fromDate" type="date" class="date-picker" />
+ </div>
+ <div class="date-input">
+ <label>To</label>
+ <input v-model="searchQuery.toDate" type="date" class="date-picker" />
+ </div>
</div>
- <div class="date-input">
- <label>To</label>
- <input v-model="dateTo" type="date" class="date-picker" />
+ <div class="radio-group">
+ <label class="radio-option">
+ <input v-model="searchQuery.dateType" type="radio" value="created" />
+ <span>Created</span>
+ </label>
+ <label class="radio-option">
+ <input v-model="searchQuery.dateType" type="radio" value="modified" />
+ <span>Modified</span>
+ </label>
</div>
</div>
</div>
<div class="filter-group">
- <label class="filter-label">Date Type</label>
- <div class="radio-group">
- <label class="radio-option">
- <input v-model="dateType" type="radio" value="created" />
- <span>Created</span>
- </label>
- <label class="radio-option">
- <input v-model="dateType" type="radio" value="modified" />
- <span>Modified</span>
- </label>
- </div>
+ <label class="filter-label">Category</label>
+ <AppSelect v-model="searchQuery.category" :items="categoriesTree" placeholder="All categories" />
</div>
<div class="filter-group">
@@ -45,7 +51,7 @@
<input
v-model="tagInput"
type="text"
- placeholder="Add tag filter..."
+ placeholder="Add tag..."
class="tag-input"
@keydown.enter="handleEnter"
@keydown.arrow-up="tagHandleArrowUp"
@@ -59,7 +65,6 @@
<Icon name="plus" fill="#fff" />
</button>
</div>
-
<div v-if="showSuggestions && filteredTagSuggestions.length > 0" class="tag-suggestions">
<div
v-for="(tag, index) in filteredTagSuggestions"
@@ -73,99 +78,188 @@
</div>
</div>
</div>
- <div class="selected-tags">
- <span v-for="tag in selectedTags" :key="tag" class="tag-chip">
+ <div v-if="searchQuery.tags?.length" class="selected-tags">
+ <span v-for="tag in searchQuery.tags" :key="tag" class="tag-chip">
{{ tag }}
- <button class="remove-tag" @click.stop="removeTag(tag)">
- <Icon name="close" class="no-close" />
- </button>
+ <button class="remove-tag" @click.stop="removeTag(tag)">Γ—</button>
</span>
</div>
</div>
</div>
- <div class="filter-group">
- <label class="filter-label">Category</label>
- <AppSelect v-model="selectedCategory" :items="categoriesTree" placeholder="Select a category" />
+ <div class="filter-group full-width">
+ <label class="filter-label inline">
+ <AppCheck v-model="searchInContent" />
+ Search in document content
+ </label>
+ <p class="filter-hint">Searches inside document body (requires complete words)</p>
</div>
- <div class="filter-actions">
- <button class="clear-filters-btn" @click="clearFilters">Clear Filters</button>
- <button class="apply-filters-btn">Apply Filters</button>
- </div>
+ <div class="filter-actions"></div>
</div>
</div>
<div class="search-results">
- <SearchResultsList
- :items="flattenedItems"
- :selected-index="selectedIndex"
- :query="query"
- empty-text="No documents match your filters"
- empty-icon="search"
- @update-selected-index="$emit('updateSelectedIndex', $event)"
- />
+ <SearchResultsList :items="flattenedItems" :selected-index="selectedIndex" :query="query" @update-selected-index="$emit('updateSelectedIndex', $event)" />
</div>
</div>
</template>
<script setup lang="ts">
import SearchResultsList from './SearchResultsList.vue';
-import type { Node } from '~/stores';
-const props = defineProps<{
- query: string;
- selectedIndex: number;
-}>();
+import type { SearchOptions, Node, NodeSearchResult } from '~/stores';
+
+const props = defineProps<{ query: string; selectedIndex: number }>();
defineEmits<{ updateSelectedIndex: [index: number] }>();
-const dateFrom = ref('');
-const dateTo = ref('');
-const dateType = ref<'created' | 'modified'>('modified');
-const tagInput = ref('');
-const selectedTags = ref<string[]>([]);
-const selectedCategory = ref('');
+const nodesStore = useNodesStore();
+const categoriesTree = new TreeStructure(useSidebarTree().nodes.value.filter(n => n.data.role <= 2)).generateTree();
+
+// UI State
const showFilters = ref(true);
const showSuggestions = ref(false);
const selectedSuggestionIndex = ref(0);
+const tagInput = ref('');
-const nodesStore = useNodesStore();
-const categoriesTree = new TreeStructure(useSidebarTree().nodes.value.filter(n => n.data.role <= 2)).generateTree();
+// Search State
+const searchInContent = ref(true);
+const searchResults = ref<(NodeSearchResult | Node)[]>([]);
+const isLoading = ref(false);
+
+const searchQuery = ref<SearchOptions>({
+ query: props.query,
+});
+
+/**
+ * Global search function
+ * - If searchInContent is ON and query >= 2 chars β†’ API fulltext search
+ * - Otherwise β†’ local store search
+ */
+async function search(query: string) {
+ const shouldUseAPI = searchInContent.value && query.length >= 2;
+
+ if (shouldUseAPI) {
+ // API fulltext search
+ isLoading.value = true;
+ try {
+ const apiResults = await nodesStore.searchFulltext(query, true, 30);
+ searchResults.value = applyFilters(apiResults);
+ } catch (error) {
+ console.error('[CommandCenter] Fulltext search error:', error);
+ searchResults.value = [];
+ } finally {
+ isLoading.value = false;
+ }
+ } else {
+ // Local store search (instant, no API)
+ searchResults.value = nodesStore.search({ ...searchQuery.value, query, role: 3 });
+ }
+}
+
+/**
+ * Apply additional filters to API results (category, tags, dates)
+ */
+function applyFilters(results: (NodeSearchResult | Node)[]): (NodeSearchResult | Node)[] {
+ let filtered = [...results];
+
+ if (searchQuery.value.category) {
+ filtered = filtered.filter(d => d.parent_id === searchQuery.value.category);
+ }
+
+ if (searchQuery.value.tags?.length) {
+ filtered = filtered.filter(d => {
+ if (!d.tags) return false;
+ const nodeTags = d.tags.split(',').map(t => t.trim());
+ return searchQuery.value.tags!.some(tag => nodeTags.includes(tag));
+ });
+ }
+
+ if (searchQuery.value.fromDate || searchQuery.value.toDate) {
+ filtered = filtered.filter(d => {
+ const date = new Date(d.updated_timestamp);
+ if (searchQuery.value.fromDate && date < new Date(searchQuery.value.fromDate)) return false;
+ if (searchQuery.value.toDate && date > new Date(searchQuery.value.toDate)) return false;
+ return true;
+ });
+ }
+
+ return filtered;
+}
+
+// Debounced search (300ms) - single watcher for all search triggers
+const debouncedSearch = useDebounceFn((query: string) => search(query), 300);
+
+// Watch all search-related changes and trigger debounced search
+watch([() => props.query, searchInContent, () => searchQuery.value], ([query]) => debouncedSearch(query), { immediate: true, deep: true });
const filteredTagSuggestions = computed(() => {
if (!tagInput.value) return [];
const input = tagInput.value.toLowerCase();
- return nodesStore.allTags.filter(tag => tag.toLowerCase().includes(input) && !selectedTags.value.includes(tag)).slice(0, 5);
-});
-
-const filteredDocuments = computed(() => {
- return nodesStore.search({
- query: props.query,
- category: selectedCategory.value,
- dateType: dateType.value,
- fromDate: dateFrom.value ? new Date(dateFrom.value) : undefined,
- toDate: dateTo.value ? new Date(dateTo.value) : undefined,
- tags: selectedTags.value,
- role: 3,
- });
+ return nodesStore.allTags.filter(tag => tag.toLowerCase().includes(input) && !tagInput.value.includes(tag)).slice(0, 5);
});
const flattenedItems = computed(() => {
- return filteredDocuments.value.map((doc, idx) => ({
+ return searchResults.value.map((doc, idx) => ({
id: doc.id,
icon: getDocumentIcon(doc),
title: doc.name,
- description: doc.tags ? `#${String(doc.tags.split(', ').join(' #'))}` : 'Document',
+ description: buildDescription(doc),
path: `/dashboard/docs/${doc.id}`,
section: '',
globalIndex: idx,
}));
});
+function buildDescription(doc: NodeSearchResult | Node): string {
+ // If we have a content snippet from fulltext search, show it
+ if ('content_snippet' in doc && doc.content_snippet) {
+ // Clean up HTML tags and show snippet
+ const cleanSnippet = doc.content_snippet.replace(/<[^>]*>/g, '').trim();
+ if (cleanSnippet) {
+ return `...${highlightMatches(cleanSnippet)}...`;
+ }
+ }
+ // Fallback to tags
+ if (doc.tags) {
+ return `#${String(
+ doc.tags
+ .split(',')
+ .map(t => t.trim())
+ .join(' #'),
+ )}`;
+ }
+ return 'Document';
+}
+
+/**
+ * Highlight matching words in text by wrapping them in <b> tags
+ */
+function highlightMatches(text: string): string {
+ if (!props.query || props.query.length < 2) return escapeHtml(text);
+
+ const words = props.query
+ .trim()
+ .split(/\s+/)
+ .filter(w => w.length >= 2);
+ if (words.length === 0) return escapeHtml(text);
+
+ // Escape special regex chars and create pattern
+ const pattern = words.map(w => w.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
+ const regex = new RegExp(`(${pattern})`, 'gi');
+
+ return escapeHtml(text).replace(regex, '<b>$1</b>');
+}
+
+function escapeHtml(text: string): string {
+ return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
+}
+
function addTag() {
const tag = tagInput.value.trim();
- if (tag && !selectedTags.value.includes(tag)) {
- selectedTags.value.push(tag);
+ if (!searchQuery.value.tags) searchQuery.value.tags = [];
+ if (tag && !searchQuery.value.tags.includes(tag)) {
+ searchQuery.value.tags.push(tag);
tagInput.value = '';
showSuggestions.value = false;
}
@@ -173,7 +267,7 @@ function addTag() {
function selectTag(tag?: string) {
if (!tag) return;
- selectedTags.value.push(tag);
+ searchQuery.value.tags?.push(tag);
tagInput.value = '';
showSuggestions.value = false;
}
@@ -217,18 +311,16 @@ function toggleFilters() {
}
function removeTag(tag: string) {
- selectedTags.value = selectedTags.value.filter(t => t !== tag);
+ searchQuery.value.tags = searchQuery.value.tags?.filter(t => t !== tag);
}
function clearFilters() {
- dateFrom.value = '';
- dateTo.value = '';
- selectedTags.value = [];
- selectedCategory.value = '';
+ searchQuery.value = { query: props.query };
+ tagInput.value = '';
}
-function getDocumentIcon(doc: Node) {
- if (doc.order == -1) return 'pin';
+function getDocumentIcon(doc: NodeSearchResult | Node): string {
+ if ('order' in doc && doc.order == -1) return 'pin';
return 'files';
}
@@ -249,7 +341,7 @@ defineExpose({ flattenedItems });
.filters-header {
display: flex;
- padding: 16px 20px;
+ padding: 10px 16px;
align-items: center;
border-bottom: 1px solid var(--border-color);
justify-content: space-between;
@@ -257,11 +349,16 @@ defineExpose({ flattenedItems });
.filters-title {
margin: 0;
- font-size: 14px;
+ font-size: 11px;
font-weight: 600;
letter-spacing: 0.5px;
text-transform: uppercase;
}
+.filters-actions {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+}
.toggle-filters-btn {
display: flex;
@@ -284,29 +381,35 @@ defineExpose({ flattenedItems });
}
.filters-content {
- padding: 20px;
+ display: grid;
+ padding: 12px 16px;
+ grid-template-columns: 1fr 1fr;
+ gap: 12px 16px;
}
.filter-group {
- margin-bottom: 20px;
-
- &:last-child {
- margin-bottom: 0;
+ &.full-width {
+ grid-column: 1 / -1;
}
}
.filter-label {
display: block;
- font-size: 12px;
+ font-size: 11px;
font-weight: 600;
- letter-spacing: 0.5px;
- margin-bottom: 8px;
+ letter-spacing: 0.3px;
+ margin-bottom: 4px;
text-transform: uppercase;
}
+.inline {
+ display: flex;
+ align-items: center;
+}
+
.date-filters {
display: flex;
- gap: 12px;
+ gap: 8px;
}
.date-input {
@@ -314,17 +417,18 @@ defineExpose({ flattenedItems });
label {
display: block;
- font-size: 11px;
- margin-bottom: 4px;
+ font-size: 10px;
+ margin-bottom: 2px;
+ opacity: 0.6;
}
}
.date-picker {
width: 100%;
- padding: 8px 12px;
+ padding: 6px 8px;
border: 1px solid var(--border-color);
- border-radius: 6px;
- font-size: 14px;
+ border-radius: 4px;
+ font-size: 12px;
background: var(--bg-color);
outline: none;
@@ -335,15 +439,15 @@ defineExpose({ flattenedItems });
.radio-group {
display: flex;
- gap: 16px;
+ gap: 12px;
}
.radio-option {
display: flex;
- font-size: 14px;
+ font-size: 12px;
align-items: center;
cursor: pointer;
- gap: 6px;
+ gap: 4px;
input[type='radio'] {
accent-color: var(--primary);
@@ -353,19 +457,18 @@ defineExpose({ flattenedItems });
.tags-filter {
.tags-input-wrapper {
position: relative;
- margin-bottom: 12px;
}
.tags-input {
display: flex;
- gap: 8px;
+ gap: 6px;
}
.tag-input {
- padding: 8px 12px;
+ padding: 6px 8px;
border: 1px solid var(--border-color);
- border-radius: 6px;
- font-size: 14px;
+ border-radius: 4px;
+ font-size: 12px;
background: var(--bg-color);
flex: 1;
outline: none;
@@ -377,12 +480,11 @@ defineExpose({ flattenedItems });
.add-tag-btn {
display: flex;
- padding: 8px 12px;
+ padding: 6px 10px;
border: none;
- border-radius: 6px;
+ border-radius: 4px;
color: white;
background: var(--primary);
- transition: background-color 0.2s ease;
align-items: center;
cursor: pointer;
justify-content: center;
@@ -394,57 +496,51 @@ defineExpose({ flattenedItems });
}
.tag-suggestions {
+ position: absolute;
top: 100%;
- right: 48px;
+ right: 40px;
left: 0;
z-index: 10;
- max-height: 200px;
+ max-height: 150px;
+ margin-top: 2px;
border: 1px solid var(--border-color);
- border-radius: 6px;
+ border-radius: 4px;
background: var(--bg-color);
box-shadow: 0 4px 12px rgb(0 0 0 / 15%);
overflow-y: auto;
}
.tag-suggestion {
- padding: 8px 12px;
- font-size: 14px;
- transition: background 0.2s ease;
+ padding: 6px 10px;
+ font-size: 12px;
cursor: pointer;
&:hover,
&.selected {
background: var(--border-color);
}
-
- &:first-child {
- border-radius: 6px 6px 0 0;
- }
-
- &:last-child {
- border-radius: 0 0 6px 6px;
- }
}
.selected-tags {
display: flex;
flex-wrap: wrap;
- gap: 6px;
+ margin-top: 6px;
+ gap: 4px;
}
.tag-chip {
display: inline-flex;
- padding: 4px 8px;
- border-radius: 12px;
- font-size: 12px;
+ padding: 2px 6px;
+ border-radius: 10px;
+ font-size: 11px;
background: var(--border-color);
align-items: center;
gap: 4px;
.remove-tag {
display: flex;
- width: 16px;
- height: 16px;
+ width: 14px;
+ height: 14px;
padding: 0;
border: none;
border-radius: 50%;
@@ -461,19 +557,17 @@ defineExpose({ flattenedItems });
.filter-actions {
display: flex;
- gap: 12px;
- margin-top: 20px;
+ grid-column: 1 / -1;
+ gap: 8px;
}
-.clear-filters-btn,
-.apply-filters-btn {
- padding: 10px 16px;
+.clear-filters-btn {
+ padding: 6px 12px;
border: none;
- border-radius: 6px;
- font-size: 14px;
+ border-radius: 4px;
+ font-size: 12px;
font-weight: 500;
cursor: pointer;
- flex: 1;
}
.clear-filters-btn {
@@ -484,15 +578,6 @@ defineExpose({ flattenedItems });
}
}
-.apply-filters-btn {
- color: white;
- background: var(--primary);
-
- &:hover {
- background: var(--primary-dark);
- }
-}
-
.search-results {
position: relative;
min-height: 0;
@@ -500,6 +585,12 @@ defineExpose({ flattenedItems });
overscroll-behavior: contain;
}
+.filter-hint {
+ margin: 2px 0 0 0;
+ font-size: 10px;
+ color: var(--text-secondary);
+}
+
.tag {
padding: 2px 6px;
border-radius: 4px;
diff --git a/frontend/app/components/CommandCenter/QuickSearchTab.vue b/frontend/app/components/CommandCenter/QuickSearchTab.vue
index fa3344bf..9c8ce614 100644
--- a/frontend/app/components/CommandCenter/QuickSearchTab.vue
+++ b/frontend/app/components/CommandCenter/QuickSearchTab.vue
@@ -4,7 +4,6 @@
:items="flattenedItems"
:selected-index="selectedIndex"
:query="searchQuery"
- empty-icon="search"
@update-selected-index="$emit('updateSelectedIndex', $event)"
/>
</div>
diff --git a/frontend/app/components/CommandCenter/SearchResultsList.vue b/frontend/app/components/CommandCenter/SearchResultsList.vue
index d26eec54..1834b812 100644
--- a/frontend/app/components/CommandCenter/SearchResultsList.vue
+++ b/frontend/app/components/CommandCenter/SearchResultsList.vue
@@ -1,7 +1,7 @@
<template>
<div>
<div v-if="items.length === 0" class="no-results">
- <Icon :name="emptyIcon" class="no-results-icon" />
+ <Icon name="search" class="no-results-icon" />
<p>No results found for "{{ query }}"</p>
</div>
<div v-else class="search-results-list">
@@ -18,7 +18,8 @@
<Icon :name="item.icon" class="result-icon" />
<div class="result-content">
<span class="result-title">{{ item.title }}</span>
- <span class="result-description">{{ item.description }}</span>
+ <!-- eslint-disable-next-line vue/no-v-html OK because app format -->
+ <span class="result-description" v-html="item.description"></span>
</div>
<div class="result-shortcut">
<kbd v-if="item.shortcut">{{ item.shortcut }}</kbd>
@@ -36,7 +37,6 @@ const props = defineProps<{
items: ItemCommand[];
selectedIndex: number;
query: string;
- emptyIcon: string;
}>();
defineEmits<{
@@ -75,18 +75,6 @@ const groupedItems = computed(() => {
}
}
-kbd {
- display: inline-block;
- padding: 4px 8px;
- border: 1px solid var(--border-color);
- border-radius: 6px;
- font-family: Inter;
- font-size: 14px;
- font-weight: 400;
- color: var(--font-color-dark);
- background-color: var(--bg-color);
-}
-
.result-icon {
width: 20px;
height: 20px;
@@ -109,7 +97,8 @@ kbd {
}
.result-title {
- font-weight: 600;
+ font-weight: 500;
+ font-size: 14px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
diff --git a/frontend/app/composables/utils.ts b/frontend/app/composables/utils.ts
index 910b801a..63a51989 100644
--- a/frontend/app/composables/utils.ts
+++ b/frontend/app/composables/utils.ts
@@ -71,3 +71,25 @@ export function debounceDelayed<T extends (...args: unknown[]) => void>(fn: T, d
}, delay);
};
}
+
+/**
+ * Creates a debounced function similar to VueUse's useDebounceFn.
+ * Useful for search inputs where you want to wait for the user to stop typing.
+ * Works with both sync and async functions.
+ *
+ * @param fn - The function to debounce (can be async)
+ * @param delay - The number of milliseconds to delay (default: 300)
+ * @returns A debounced function
+ */
+export function useDebounceFn<T extends (...args: Parameters<T>) => ReturnType<T>>(fn: T, delay = 300) {
+ let timeout: ReturnType<typeof setTimeout> | null = null;
+
+ return (...args: Parameters<T>) => {
+ if (timeout) clearTimeout(timeout);
+
+ timeout = setTimeout(() => {
+ fn(...args);
+ timeout = null;
+ }, delay);
+ };
+}
diff --git a/frontend/app/pages/dashboard/settings/_views/shortcuts.vue b/frontend/app/pages/dashboard/settings/_views/shortcuts.vue
index 0bd4b827..5c9a2fa3 100644
--- a/frontend/app/pages/dashboard/settings/_views/shortcuts.vue
+++ b/frontend/app/pages/dashboard/settings/_views/shortcuts.vue
@@ -143,16 +143,4 @@ p {
background-color: var(--bg-ui);
}
}
-
-kbd {
- display: inline-block;
- padding: 4px 8px;
- border: 1px solid var(--border-color);
- border-radius: 6px;
- font-family: Inter;
- font-size: 14px;
- font-weight: 400;
- color: var(--font-color-dark);
- background-color: var(--bg-color);
-}
</style>
diff --git a/frontend/app/stores/db_strustures.d.ts b/frontend/app/stores/db_strustures.d.ts
index 7f27221f..6dbb8cdb 100644
--- a/frontend/app/stores/db_strustures.d.ts
+++ b/frontend/app/stores/db_strustures.d.ts
@@ -64,6 +64,20 @@ export interface PublicUser {
updated_timestamp: number;
}
+export interface NodeSearchResult {
+ id: string;
+ user_id: string;
+ parent_id?: string;
+ name: string;
+ description?: string;
+ tags?: string;
+ role: number;
+ icon?: string;
+ relevance: number;
+ content_snippet?: string;
+ updated_timestamp: number;
+}
+
export interface ConnectionLog {
id: string;
user_id: string;
diff --git a/frontend/app/stores/nodes.store.ts b/frontend/app/stores/nodes.store.ts
index a00663c4..f5bf87fd 100644
--- a/frontend/app/stores/nodes.store.ts
+++ b/frontend/app/stores/nodes.store.ts
@@ -1,6 +1,6 @@
import { makeRequest, type FetchOptions } from './_utils';
import { Collection } from './collection';
-import type { DB_Node, Node, Permission } from './db_strustures';
+import type { DB_Node, Node, NodeSearchResult, Permission } from './db_strustures';
export interface SearchOptions {
query?: string;
@@ -329,6 +329,27 @@ export const useNodesStore = defineStore('nodes', {
allChildrens.forEach(childId => this.nodes.delete(childId));
} else throw request.message;
},
+ /**
+ * Performs a fulltext search on the server using MySQL FULLTEXT index
+ * This is optimized for searching in document content (body)
+ * @param query - Search query (min 2 characters)
+ * @param includeContent - Whether to search in document body content
+ * @param limit - Max results to return
+ */
+ async searchFulltext(query: string, includeContent = true, limit = 20): Promise<NodeSearchResult[]> {
+ if (query.length < 2) return [];
+ const params = new URLSearchParams({
+ q: query,
+ content: includeContent.toString(),
+ limit: limit.toString(),
+ });
+ const request = await makeRequest(`nodes/search?${params.toString()}`, 'GET', {});
+ if (request.status === 'success') {
+ return request.result as NodeSearchResult[];
+ }
+ console.error('[store/nodes] Fulltext search failed:', request.message);
+ return [];
+ },
clear() {
this.nodes.clear();
this.public_nodes.clear();
diff --git a/frontend/app/styles/theme.scss b/frontend/app/styles/theme.scss
index 9aa1bce0..a1bc7ec3 100644
--- a/frontend/app/styles/theme.scss
+++ b/frontend/app/styles/theme.scss
@@ -141,11 +141,15 @@ input:-webkit-autofill:focus {
}
kbd {
- padding: 2px 6px;
- border-radius: 4px;
- font-family: monospace;
- font-weight: 600;
- background: var(--border-color);
+ display: inline-block;
+ padding: 4px 8px;
+ border: 1px solid var(--border-color);
+ border-radius: 6px;
+ font-family: Inter;
+ font-size: 14px;
+ font-weight: 400;
+ color: var(--font-color-dark);
+ background-color: var(--bg-color);
}
label {