get_search_analytics
Analyze search patterns and performance metrics within projects to identify trends and optimize search functionality.
Instructions
Get analytics about search patterns and performance
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| time_range | No | Time range for analytics | week |
| project_id | No | Project to filter analytics (optional) | |
| include_performance | No | Include search performance metrics |
Implementation Reference
- src/tools/intelligent-search.ts:371-383 (handler)Main handler function that validates input with schema, logs the request, calls the analytics calculator, and returns formatted results.export const getSearchAnalytics = requireAuth(async (args: any) => { const { time_range, project_id, include_performance } = GetSearchAnalyticsSchema.parse(args) logger.info('Getting search analytics', { time_range, project_id }) const analytics = await calculateSearchAnalytics(time_range, project_id, include_performance) return { time_range, project_id, ...analytics } })
- Zod validation schema defining the input parameters: time_range (enum), optional project_id, and optional include_performance.const GetSearchAnalyticsSchema = z.object({ time_range: z.enum(['hour', 'day', 'week', 'month']).default('week'), project_id: z.string().optional(), include_performance: z.boolean().default(true) })
- src/tools/intelligent-search.ts:667-672 (registration)Registration of the handler function under the key 'get_search_analytics' in the intelligentSearchHandlers export.export const intelligentSearchHandlers = { universal_search: universalSearch, semantic_search: semanticSearch, get_search_suggestions: getSearchSuggestions, get_search_analytics: getSearchAnalytics }
- src/tools/intelligent-search.ts:340-363 (registration)MCPTool object definition with name, description, and inputSchema for the get_search_analytics tool.export const getSearchAnalyticsTool: MCPTool = { name: 'get_search_analytics', description: 'Get analytics about search patterns and performance', inputSchema: { type: 'object', properties: { time_range: { type: 'string', enum: ['hour', 'day', 'week', 'month'], default: 'week', description: 'Time range for analytics' }, project_id: { type: 'string', description: 'Project to filter analytics (optional)' }, include_performance: { type: 'boolean', default: true, description: 'Include search performance metrics' } } } }
- Helper function that computes the actual search analytics data, returning mock statistics for searches, trends, and performance.async function calculateSearchAnalytics(timeRange: string, projectId?: string, includePerformance?: boolean): Promise<any> { // Placeholder for search analytics return { total_searches: 150, unique_queries: 45, avg_results_per_search: 8.3, top_search_terms: ['api', 'documentation', 'tasks', 'project'], search_trends: { documents: 45, tasks: 35, projects: 20 }, performance: includePerformance ? { avg_search_time: 125, cache_hit_rate: 78.5 } : undefined } }