diff --git a/src/components/modals.ts b/src/components/modals.ts index c37eda5..d3aa6b2 100644 --- a/src/components/modals.ts +++ b/src/components/modals.ts @@ -136,7 +136,7 @@ abstract class OmnisearchModal extends Modal { }) // Context - this.scope.register(['Ctrl'], 'H', _e => { + this.scope.register(['Ctrl'], 'G', _e => { eventBus.emit(EventNames.ToggleExcerpts) }) } diff --git a/src/search/omnisearch.ts b/src/search/omnisearch.ts index 8684d5a..4411dc3 100644 --- a/src/search/omnisearch.ts +++ b/src/search/omnisearch.ts @@ -252,6 +252,40 @@ export class Omnisearch { }) } + logDebug( + 'searching with downranked folders', + settings.downrankedFoldersFilters + ) + // downrank files that are in folders listed in the downrankedFoldersFilters + if (settings.downrankedFoldersFilters.length > 0) { + results.forEach(result => { + const path = result.id + let downrankingFolder = false + settings.downrankedFoldersFilters.forEach(filter => { + if (path.startsWith(filter)) { + // we don't want the filter to match the folder sources, e.g. + // it needs to match a whole folder name + if (path === filter || path.startsWith(filter + '/')) { + logDebug('searching with downranked folders in path: ', path) + downrankingFolder = true + } + } + }) + if (downrankingFolder) { + result.score /= 10 + } + const pathParts = path.split('/') + const pathPartsLength = pathParts.length + for (let i = 0; i < pathPartsLength; i++) { + const pathPart = pathParts[i] + if (settings.downrankedFoldersFilters.includes(pathPart)) { + result.score /= 10 + break + } + } + }) + } + // Extract tags from the query const tags = query.getTags() diff --git a/src/settings.ts b/src/settings.ts index 782423d..be63474 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -29,6 +29,8 @@ export interface OmnisearchSettings extends WeightingSettings { useCache: boolean /** Respect the "excluded files" Obsidian setting by downranking results ignored files */ hideExcluded: boolean + /** downrank files in the given folders */ + downrankedFoldersFilters: string[] /** Ignore diacritics when indexing files */ ignoreDiacritics: boolean /** Extensions of plain text files to index, in addition to .md */ @@ -268,6 +270,24 @@ export class SettingsTab extends PluginSettingTab { }) ) + // Downranked files + new Setting(containerEl) + .setName('Folders to downrank in search results') + .setDesc( + `Folders to downrank in search results. Files in these folders will be downranked in results. They will still be indexed for tags, unlike excluded files. Folders should be comma delimited.` + ) + .addText(component => { + component + .setValue(settings.downrankedFoldersFilters.join(',')) + .setPlaceholder('Example: src,p2/dir') + .onChange(async v => { + let folders = v.split(',') + folders = folders.map(f => f.trim()) + settings.downrankedFoldersFilters = folders + await saveSettings(this.plugin) + }) + }) + // Split CamelCaseWords const camelCaseDesc = new DocumentFragment() camelCaseDesc.createSpan({}, span => { @@ -621,6 +641,7 @@ export class SettingsTab extends PluginSettingTab { export const DEFAULT_SETTINGS: OmnisearchSettings = { useCache: true, hideExcluded: false, + downrankedFoldersFilters: [] as string[], ignoreDiacritics: true, indexedFileTypes: [] as string[], PDFIndexing: false,