(query: string, limit = 30)
| 148 | } |
| 149 | |
| 150 | public search(query: string, limit = 30): GraphNode[] { |
| 151 | const queryLower = query.toLowerCase(); |
| 152 | const matches: { node: GraphNode; score: number }[] = []; |
| 153 | |
| 154 | for (const node of this.nodes.values()) { |
| 155 | const nameLower = node.name.toLowerCase(); |
| 156 | const fileLower = (node.file || "").toLowerCase(); |
| 157 | |
| 158 | let score = 0; |
| 159 | if (nameLower === queryLower) score = 100; |
| 160 | else if (nameLower.startsWith(queryLower)) score = 80; |
| 161 | else if (nameLower.includes(queryLower)) score = 50; |
| 162 | else if (fileLower.includes(queryLower)) score = 20; |
| 163 | |
| 164 | if (score > 0) matches.push({ node, score }); |
| 165 | } |
| 166 | |
| 167 | return matches |
| 168 | .sort((a, b) => b.score - a.score) |
| 169 | .slice(0, limit) |
| 170 | .map(m => m.node); |
| 171 | } |
| 172 | |
| 173 | public getFileStructure(): { files: string[]; structure: Record<string, GraphNode[]> } { |
| 174 | const files: string[] = []; |
no test coverage detected