MCPcopy
hub / github.com/forloopcodes/contextplus / buildIndex

Function buildIndex

src/tools/semantic-search.ts:134–155  ·  view source on GitHub ↗
(rootDir: string)

Source from the content-addressed store, hash-verified

132}
133
134async function buildIndex(rootDir: string): Promise<SearchIndex> {
135 if (cachedIndex && cachedRootDir === rootDir && Date.now() - lastIndexTime < INDEX_TTL_MS) {
136 return cachedIndex;
137 }
138
139 const entries = await walkDirectory({ rootDir, depthLimit: 0 });
140 const files = entries.filter((e) => !e.isDirectory);
141
142 const docs: SearchDocument[] = [];
143 for (const file of files) {
144 const doc = await buildSearchDocumentForFile(rootDir, file.relativePath);
145 if (doc) docs.push(doc);
146 }
147
148 const index = new SearchIndex();
149 await index.index(docs, rootDir);
150 cachedIndex = index;
151 cachedRootDir = rootDir;
152 lastIndexTime = Date.now();
153
154 return index;
155}
156
157export async function semanticCodeSearch(options: SemanticSearchOptions): Promise<string> {
158 const index = await buildIndex(options.rootDir);

Callers 1

semanticCodeSearchFunction · 0.85

Calls 3

indexMethod · 0.95
walkDirectoryFunction · 0.85

Tested by

no test coverage detected