MCPcopy Create free account
hub / github.com/SethGammon/Citadel / queryMapIndex

Function queryMapIndex

core/map/index.js:518–567  ·  view source on GitHub ↗
(index, queryStr, maxFiles = 20)

Source from the content-addressed store, hash-verified

516}
517
518function queryMapIndex(index, queryStr, maxFiles = 20) {
519 const terms = String(queryStr || '').toLowerCase().split(/\s+/).filter(Boolean);
520 if (terms.length === 0) return [];
521
522 const scored = [];
523
524 for (const [relPath, info] of Object.entries(index.files || {})) {
525 let score = 0;
526 const lowerPath = relPath.toLowerCase();
527 const exports = info.exports || [];
528 const symbols = info.symbols || [];
529 const routes = info.routes || [];
530
531 for (const term of terms) {
532 if (lowerPath.includes(term)) score += 3;
533 if (exports.some((exp) => exp.toLowerCase().includes(term))) score += 5;
534 if (symbols.some((sym) => sym.toLowerCase().includes(term))) score += 2;
535 if (String(info.role || '').toLowerCase().includes(term)) score += 1;
536 if (routes.some((route) => route.toLowerCase().includes(term))) score += 4;
537 }
538
539 if (score > 0 && info.role === 'test' && !terms.includes('test') && !terms.includes('spec')) {
540 score = Math.max(1, score - 10);
541 }
542
543 if (score > 0) {
544 scored.push({
545 relPath,
546 score,
547 role: info.role,
548 exports,
549 routes,
550 lines: info.lines,
551 });
552 }
553 }
554
555 scored.sort((a, b) => b.score - a.score || a.relPath.localeCompare(b.relPath));
556
557 const results = [];
558 let outputLength = 0;
559 for (const item of scored.slice(0, maxFiles)) {
560 const line = `${item.score} ${item.role} ${item.relPath} ${item.exports.slice(0, 5).join(',')} ${item.lines}`;
561 if (outputLength + line.length > 8000) break;
562 outputLength += line.length;
563 results.push(item);
564 }
565
566 return results;
567}
568
569function createMapSlice(index, queryStr, options = {}) {
570 const maxFiles = options.maxFiles || 15;

Callers 3

createMapSliceFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected