add maxTrigramCount setting

This commit is contained in:
msukkari 2025-01-28 14:44:47 -08:00
parent d1ef80d39f
commit f83a4db3d6
6 changed files with 18 additions and 2 deletions

View file

@ -5,6 +5,7 @@ import { Settings } from "./types.js";
*/
export const DEFAULT_SETTINGS: Settings = {
maxFileSize: 2 * 1024 * 1024, // 2MB in bytes
maxTrigramCount: 20000,
autoDeleteStaleRepos: true,
reindexInterval: 1000 * 60 * 60, // 1 hour in milliseconds
resyncInterval: 1000 * 60 * 60 * 24, // 1 day in milliseconds

View file

@ -209,6 +209,7 @@ const syncConfig = async (configPath: string, db: Database, signal: AbortSignal,
// Update the settings
const updatedSettings: Settings = {
maxFileSize: config.settings?.maxFileSize ?? DEFAULT_SETTINGS.maxFileSize,
maxTrigramCount: config.settings?.maxTrigramCount ?? DEFAULT_SETTINGS.maxTrigramCount,
autoDeleteStaleRepos: config.settings?.autoDeleteStaleRepos ?? DEFAULT_SETTINGS.autoDeleteStaleRepos,
reindexInterval: config.settings?.reindexInterval ?? DEFAULT_SETTINGS.reindexInterval,
resyncInterval: config.settings?.resyncInterval ?? DEFAULT_SETTINGS.resyncInterval,

View file

@ -21,6 +21,10 @@ export interface Settings {
* The maximum size of a file (in bytes) to be indexed. Files that exceed this maximum will not be inexed. Defaults to 2MB (2097152 bytes).
*/
maxFileSize?: number;
/**
* The maximum amount of trigrams per document. Documents that exceed this maximum will not be indexed. Defaults to 20000
*/
maxTrigramCount?: number;
/**
* Automatically delete stale repositories from the index. Defaults to true.
*/

View file

@ -46,9 +46,13 @@ export type AppContext = {
export type Settings = {
/**
* The maximum size of a file (in bytes) to be indexed. Files that exceed this maximum will not be inexed.
* The maximum size of a file (in bytes) to be indexed. Files that exceed this maximum will not be indexed.
*/
maxFileSize: number;
/**
* The maximum number of trigrams per document. Files that exceed this maximum will not be indexed.
*/
maxTrigramCount: number;
/**
* Automatically delete stale repositories from the index. Defaults to true.
*/

View file

@ -10,7 +10,7 @@ export const indexGitRepository = async (repo: GitRepository, settings: Settings
...repo.tags ?? [],
];
const command = `zoekt-git-index -allow_missing_branches -index ${ctx.indexPath} -file_limit ${settings.maxFileSize} -branches ${revisions.join(',')} ${repo.path}`;
const command = `zoekt-git-index -allow_missing_branches -index ${ctx.indexPath} -max_trigram_count ${settings.maxTrigramCount} -file_limit ${settings.maxFileSize} -branches ${revisions.join(',')} ${repo.path}`;
return new Promise<{ stdout: string, stderr: string }>((resolve, reject) => {
exec(command, (error, stdout, stderr) => {

View file

@ -570,6 +570,12 @@
"default": 2097152,
"minimum": 1
},
"maxTrigramCount": {
"type": "integer",
"description": "The maximum amount of trigrams per document. Documents that exceed this maximum will not be indexed. Defaults to 20000",
"default": 20000,
"minimum": 1
},
"autoDeleteStaleRepos": {
"type": "boolean",
"description": "Automatically delete stale repositories from the index. Defaults to true.",