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 = { export const DEFAULT_SETTINGS: Settings = {
maxFileSize: 2 * 1024 * 1024, // 2MB in bytes maxFileSize: 2 * 1024 * 1024, // 2MB in bytes
maxTrigramCount: 20000,
autoDeleteStaleRepos: true, autoDeleteStaleRepos: true,
reindexInterval: 1000 * 60 * 60, // 1 hour in milliseconds reindexInterval: 1000 * 60 * 60, // 1 hour in milliseconds
resyncInterval: 1000 * 60 * 60 * 24, // 1 day 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 // Update the settings
const updatedSettings: Settings = { const updatedSettings: Settings = {
maxFileSize: config.settings?.maxFileSize ?? DEFAULT_SETTINGS.maxFileSize, maxFileSize: config.settings?.maxFileSize ?? DEFAULT_SETTINGS.maxFileSize,
maxTrigramCount: config.settings?.maxTrigramCount ?? DEFAULT_SETTINGS.maxTrigramCount,
autoDeleteStaleRepos: config.settings?.autoDeleteStaleRepos ?? DEFAULT_SETTINGS.autoDeleteStaleRepos, autoDeleteStaleRepos: config.settings?.autoDeleteStaleRepos ?? DEFAULT_SETTINGS.autoDeleteStaleRepos,
reindexInterval: config.settings?.reindexInterval ?? DEFAULT_SETTINGS.reindexInterval, reindexInterval: config.settings?.reindexInterval ?? DEFAULT_SETTINGS.reindexInterval,
resyncInterval: config.settings?.resyncInterval ?? DEFAULT_SETTINGS.resyncInterval, 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). * 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; 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. * Automatically delete stale repositories from the index. Defaults to true.
*/ */

View file

@ -46,9 +46,13 @@ export type AppContext = {
export type Settings = { 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; 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. * 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 ?? [], ...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) => { return new Promise<{ stdout: string, stderr: string }>((resolve, reject) => {
exec(command, (error, stdout, stderr) => { exec(command, (error, stdout, stderr) => {

View file

@ -570,6 +570,12 @@
"default": 2097152, "default": 2097152,
"minimum": 1 "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": { "autoDeleteStaleRepos": {
"type": "boolean", "type": "boolean",
"description": "Automatically delete stale repositories from the index. Defaults to true.", "description": "Automatically delete stale repositories from the index. Defaults to true.",