* LIKE-based substring search for cases where FTS doesn't match * Useful for camelCase matching (e.g., "signIn" finds "signInWithGoogle")
(query: string, options: SearchOptions)
| 1056 | * Useful for camelCase matching (e.g., "signIn" finds "signInWithGoogle") |
| 1057 | */ |
| 1058 | private searchNodesLike(query: string, options: SearchOptions): SearchResult[] { |
| 1059 | const { kinds, languages, limit = 100, offset = 0 } = options; |
| 1060 | |
| 1061 | let sql = ` |
| 1062 | SELECT nodes.*, |
| 1063 | CASE |
| 1064 | WHEN name = ? THEN 1.0 |
| 1065 | WHEN name LIKE ? THEN 0.9 |
| 1066 | WHEN name LIKE ? THEN 0.8 |
| 1067 | WHEN qualified_name LIKE ? THEN 0.7 |
| 1068 | ELSE 0.5 |
| 1069 | END as score |
| 1070 | FROM nodes |
| 1071 | WHERE ( |
| 1072 | name LIKE ? OR |
| 1073 | qualified_name LIKE ? OR |
| 1074 | name LIKE ? |
| 1075 | ) |
| 1076 | `; |
| 1077 | |
| 1078 | // Pattern variants for better matching |
| 1079 | const exactMatch = query; |
| 1080 | const startsWith = `${query}%`; |
| 1081 | const contains = `%${query}%`; |
| 1082 | |
| 1083 | const params: (string | number)[] = [ |
| 1084 | exactMatch, // Exact match score |
| 1085 | startsWith, // Starts with score |
| 1086 | contains, // Contains score |
| 1087 | contains, // Qualified name score |
| 1088 | contains, // WHERE: name contains |
| 1089 | contains, // WHERE: qualified_name contains |
| 1090 | startsWith, // WHERE: name starts with |
| 1091 | ]; |
| 1092 | |
| 1093 | if (kinds && kinds.length > 0) { |
| 1094 | sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`; |
| 1095 | params.push(...kinds); |
| 1096 | } |
| 1097 | |
| 1098 | if (languages && languages.length > 0) { |
| 1099 | sql += ` AND language IN (${languages.map(() => '?').join(',')})`; |
| 1100 | params.push(...languages); |
| 1101 | } |
| 1102 | |
| 1103 | sql += ' ORDER BY score DESC, length(name) ASC LIMIT ? OFFSET ?'; |
| 1104 | params.push(limit, offset); |
| 1105 | |
| 1106 | const rows = this.db.prepare(sql).all(...params) as (NodeRow & { score: number })[]; |
| 1107 | |
| 1108 | return rows.map((row) => ({ |
| 1109 | node: rowToNode(row), |
| 1110 | score: row.score, |
| 1111 | })); |
| 1112 | } |
| 1113 | |
| 1114 | /** |
| 1115 | * Find nodes by exact name match |
no test coverage detected