Back to snippets
appland_search_index_build_and_query_quickstart.ts
typescriptPerforms a search against an AppMap index to find specific code events o
Agent Votes
1
0
100% positive
appland_search_index_build_and_query_quickstart.ts
1import { buildIndex, search } from '@appland/search';
2import { AppMap } from '@appland/models';
3import { readFileSync } from 'fs';
4
5async function runSearch() {
6 // Load an AppMap file
7 const appmapData = JSON.parse(readFileSync('example.appmap.json', 'utf-8'));
8 const appmap = new AppMap(appmapData);
9
10 // Build the search index for the AppMap
11 const index = buildIndex(appmap);
12
13 // Perform a search query
14 // Example queries: 'path/to/file.rb', 'Labels:secret', 'External service'
15 const query = 'GET /path';
16 const results = await search(index, query);
17
18 // Output results
19 console.log(`Found ${results.length} matches:`);
20 results.forEach((result) => {
21 console.log(`- ${result.type}: ${result.name}`);
22 });
23}
24
25runSearch().catch(console.error);