-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Refactor fulltext and other search code into explain/index
- Loading branch information
Showing
24 changed files
with
422 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import sqlite3 from 'better-sqlite3'; | ||
|
||
import { FileIndex } from '@appland/search'; | ||
|
||
import buildIndexInTempDir, { CloseableIndex } from './build-index-in-temp-dir'; | ||
import { buildAppMapIndex, search } from './appmap-index'; | ||
import { SearchResponse } from './appmap-match'; | ||
|
||
export async function buildAppMapFileIndex( | ||
appmapDirectories: string[] | ||
): Promise<CloseableIndex<FileIndex>> { | ||
return await buildIndexInTempDir<FileIndex>('appmaps', async (indexFile) => { | ||
const db = new sqlite3(indexFile); | ||
const fileIndex = new FileIndex(db); | ||
await buildAppMapIndex(fileIndex, appmapDirectories); | ||
return fileIndex; | ||
}); | ||
} | ||
|
||
export async function searchAppMapFiles( | ||
appmapDirectories: string[], | ||
vectorTerms: string[], | ||
maxDiagrams: number | ||
): Promise<SearchResponse> { | ||
const index = await buildAppMapFileIndex(appmapDirectories); | ||
try { | ||
return await search(index.index, vectorTerms.join(' OR '), maxDiagrams); | ||
} finally { | ||
index.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/cli/src/fulltext/appmap-match.ts → ...cli/src/rpc/explain/index/appmap-match.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import sqlite3 from 'better-sqlite3'; | ||
import makeDebug from 'debug'; | ||
|
||
import { | ||
buildFileIndex, | ||
FileIndex, | ||
FileSearchResult, | ||
fileTokens, | ||
FilterFn, | ||
isBinaryFile, | ||
isDataFile, | ||
isLargeFile, | ||
listProjectFiles, | ||
readFileSafe, | ||
} from '@appland/search'; | ||
import { fileNameMatchesFilterPatterns } from './filter-patterns'; | ||
|
||
import buildIndexInTempDir, { CloseableIndex } from './build-index-in-temp-dir'; | ||
|
||
const debug = makeDebug('appmap:index:project-files'); | ||
|
||
function fileFilter( | ||
includePatterns: RegExp[] | undefined, | ||
excludePatterns: RegExp[] | undefined | ||
): FilterFn { | ||
return async (path: string) => { | ||
debug('Filtering: %s', path); | ||
if (isBinaryFile(path)) { | ||
debug('Skipping binary file: %s', path); | ||
return false; | ||
} | ||
|
||
const includeFile = fileNameMatchesFilterPatterns(path, includePatterns, excludePatterns); | ||
if (!includeFile) return false; | ||
|
||
const isData = isDataFile(path); | ||
if (isData && (await isLargeFile(path))) { | ||
debug('Skipping large data file: %s', path); | ||
return false; | ||
} | ||
|
||
return true; | ||
}; | ||
} | ||
|
||
async function indexFiles( | ||
db: sqlite3.Database, | ||
directories: string[], | ||
includePatterns: RegExp[] | undefined, | ||
excludePatterns: RegExp[] | undefined | ||
): Promise<FileIndex> { | ||
const fileIndex = new FileIndex(db); | ||
|
||
const filter = fileFilter(includePatterns, excludePatterns); | ||
await buildFileIndex(fileIndex, directories, listProjectFiles, filter, readFileSafe, fileTokens); | ||
|
||
return fileIndex; | ||
} | ||
|
||
export async function buildProjectFileIndex( | ||
sourceDirectories: string[], | ||
includePatterns: RegExp[] | undefined, | ||
excludePatterns: RegExp[] | undefined | ||
): Promise<CloseableIndex<FileIndex>> { | ||
return await buildIndexInTempDir('files', async (indexFile) => { | ||
const db = new sqlite3(indexFile); | ||
return await indexFiles(db, sourceDirectories, includePatterns, excludePatterns); | ||
}); | ||
} | ||
|
||
export async function searchProjectFiles( | ||
sourceDirectories: string[], | ||
includePatterns: RegExp[] | undefined, | ||
excludePatterns: RegExp[] | undefined, | ||
vectorTerms: string[] | ||
): Promise<FileSearchResult[]> { | ||
const index = await buildProjectFileIndex(sourceDirectories, includePatterns, excludePatterns); | ||
try { | ||
return index.index.search(vectorTerms.join(' OR ')); | ||
} finally { | ||
index.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/cli/tests/unit/fulltext/appmap-index.readAppMapContent.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.