(query, limit = 5)
| 327 | } |
| 328 | |
| 329 | async searchCssTechniques(query, limit = 5) { |
| 330 | debugLog(`[DEBUG] searchCssTechniques called with query: "${query}", limit: ${limit}`); |
| 331 | debugLog(`[DEBUG] Search engine ready: ${this.isReady}`); |
| 332 | |
| 333 | return new Promise((resolve, reject) => { |
| 334 | const startTime = Date.now(); |
| 335 | debugLog(`[DEBUG] Starting search at ${new Date().toISOString()}`); |
| 336 | |
| 337 | try { |
| 338 | // 处理中文搜索词 |
| 339 | const searchTerms = query.split(/\s+/).filter(Boolean); |
| 340 | let results = []; |
| 341 | |
| 342 | // 对每个搜索词分别进行搜索 |
| 343 | searchTerms.forEach(term => { |
| 344 | const termResults = this.searchEngine.search(term); |
| 345 | results = results.concat(termResults); |
| 346 | }); |
| 347 | |
| 348 | // 去重并按相关度排序 |
| 349 | results = Array.from(new Set(results.map(r => r.item.number))) |
| 350 | .map(number => results.find(r => r.item.number === number)) |
| 351 | .sort((a, b) => a.score - b.score) |
| 352 | .slice(0, limit); |
| 353 | |
| 354 | const endTime = Date.now(); |
| 355 | debugLog(`[DEBUG] Search completed in ${endTime - startTime}ms, found ${results.length} results`); |
| 356 | |
| 357 | const formattedResults = results.map(result => { |
| 358 | const item = result.item; |
| 359 | const matches = result.matches?.map(match => ({ |
| 360 | key: match.key, |
| 361 | value: match.value.substring(0, 100) + '...' |
| 362 | })) || []; |
| 363 | |
| 364 | return { |
| 365 | title: item.title, |
| 366 | issue_number: item.number, |
| 367 | url: item.html_url, |
| 368 | labels: item.labels ? JSON.parse(item.labels) : [], |
| 369 | score: Math.round((1 - result.score) * 100), |
| 370 | preview: this.extractPreview(item.body), |
| 371 | matches: matches |
| 372 | }; |
| 373 | }); |
| 374 | |
| 375 | debugLog(`[DEBUG] Formatted ${formattedResults.length} results, returning response`); |
| 376 | |
| 377 | resolve({ |
| 378 | content: [ |
| 379 | { |
| 380 | type: 'text', |
| 381 | text: `Found ${formattedResults.length} CSS techniques for "${query}":\n\n` + |
| 382 | formattedResults.map((result, index) => |
| 383 | `${index + 1}. **${result.title}** (Issue #${result.issue_number})\n` + |
| 384 | ` 💯 Relevance: ${result.score}%\n` + |
| 385 | ` 🏷️ Tags: ${result.labels.join(', ')}\n` + |
| 386 | ` 📝 Preview: ${result.preview}\n` + |
no test coverage detected