MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / searchNodesLike

Method searchNodesLike

src/db/queries.ts:1446–1500  ·  view source on GitHub ↗

* LIKE-based substring search for cases where FTS doesn't match * Useful for camelCase matching (e.g., "signIn" finds "signInWithGoogle")

(query: string, options: SearchOptions)

Source from the content-addressed store, hash-verified

1444 * Useful for camelCase matching (e.g., "signIn" finds "signInWithGoogle")
1445 */
1446 private searchNodesLike(query: string, options: SearchOptions): SearchResult[] {
1447 const { kinds, languages, limit = 100, offset = 0 } = options;
1448
1449 let sql = `
1450 SELECT nodes.*,
1451 CASE
1452 WHEN name = ? THEN 1.0
1453 WHEN name LIKE ? THEN 0.9
1454 WHEN name LIKE ? THEN 0.8
1455 WHEN qualified_name LIKE ? THEN 0.7
1456 ELSE 0.5
1457 END as score
1458 FROM nodes
1459 WHERE (
1460 name LIKE ? OR
1461 qualified_name LIKE ? OR
1462 name LIKE ?
1463 )
1464 `;
1465
1466 // Pattern variants for better matching
1467 const exactMatch = query;
1468 const startsWith = `${query}%`;
1469 const contains = `%${query}%`;
1470
1471 const params: (string | number)[] = [
1472 exactMatch, // Exact match score
1473 startsWith, // Starts with score
1474 contains, // Contains score
1475 contains, // Qualified name score
1476 contains, // WHERE: name contains
1477 contains, // WHERE: qualified_name contains
1478 startsWith, // WHERE: name starts with
1479 ];
1480
1481 if (kinds && kinds.length > 0) {
1482 sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
1483 params.push(...kinds);
1484 }
1485
1486 if (languages && languages.length > 0) {
1487 sql += ` AND language IN (${languages.map(() => '?').join(',')})`;
1488 params.push(...languages);
1489 }
1490
1491 sql += ' ORDER BY score DESC, length(name) ASC LIMIT ? OFFSET ?';
1492 params.push(limit, offset);
1493
1494 const rows = this.db.prepare(sql).all(...params) as (NodeRow & { score: number })[];
1495
1496 return rows.map((row) => ({
1497 node: rowToNode(row),
1498 score: row.score,
1499 }));
1500 }
1501
1502 /**
1503 * Find nodes by exact name match

Callers 1

searchNodesMethod · 0.95

Calls 4

rowToNodeFunction · 0.85
allMethod · 0.65
prepareMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected